在继续其他进程之前,我的代码如何首先从串行读取所有字节? [英] How does my code read all the bytes from serial first before continuing other process?

查看:85
本文介绍了在继续其他进程之前,我的代码如何首先从串行读取所有字节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在使用arduino处理我的小wsn项目。我使用我的节点将传感器数据发送到我的PC,然后使用C#编程的串行端口捕获它。来自我的节点的所有数据都使用aes128加密。所以我必须在C#程序中读取serial as byte。下面的代码是如何我读我串行

<预LANG = C#> <跨度类= 代码关键字> INT 数据字节= ComPort.BytesToRead。
byte [] byte_buffer = new byte < /跨度> [数据字节];
ComPort.Read(byte_buffer,<跨度类= 代码位> 0 ,数据字节);当程序



的问题是还没有从缓冲区读取所有字节,它运行下一个进程。在运行下一个进程之前,我需要帮助让我的程序首先读取所有字节。任何建议?



由于

解决方案
只是 '运行下道工序'在您成功收到所有需要的数据后(这意味着您可能需要等待几个 DataReceived 事件)。


Hi all,

I'm currently working on my small wsn project using arduino. I use my node for sending sensor data to my PC and I catch it using Serial Port programmed with C#. All the data from my node is encrypted using aes128. So I have to read the serial as byte in my C# program. The code below is how I read my serial.

int databytes = ComPort.BytesToRead;
byte[] byte_buffer = new byte[databytes];
ComPort.Read(byte_buffer, 0, databytes);


The problem is when the program hasn't done read all the byte from buffer, it runs next process. I need help to make my program read all the byte first before running next process. Any suggestion?

Thanks

解决方案

Just 'run next process' after you have succesfully received all the needed data (this implies you probably have to wait for several DataReceived events).


这篇关于在继续其他进程之前,我的代码如何首先从串行读取所有字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆