检查串口是否收到了哪些数据 [英] Check Serial Port is received which data

查看:111
本文介绍了检查串口是否收到了哪些数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以从串口接收数据,但我想查看收到的数据。



这是代码:



I am able to receive data from serial port, but i want to check which data is received.

Here is the code :

If int = 0 Then
    If SerialPort1.ReadExisting() = "a" Then
    'Do Something i want
    End If





因此,我使用ReadExisting()功能来接收数据。

它允许我接收数据但不要让我检查收到的数据。



我想查看收到的数据,如果收到的数据与字符 - a相同,然后必须完成我想要的任务。



感谢高级。 :)



So, i used "ReadExisting()" funtion for receiving data.
It allows me receive data but, not let me check what data is received.

"I want to check the received data and if data is received is same as as 'Character - a' then have to do the task i want."

Thanks in Advanced. :)

推荐答案

请记住,当您从串行端口读取数据时,您将获得所有可用字符 - 因此,如果另一端的设备发送a后跟一个新行,你将收到两个或三个字符,而不是一个。所以你的测试可能不合适,因为你得到的数据太多了!



看看:使用调试器在方法的开头放置一个断点, 突破你正在做的事情让你更容易看到它:

Remember that when you read data from a serial port, you get all available characters - so if the device at the other end sends "a" followed by a new line, you will receive two or three characters, not one. So your test may not be workign because you are gettign too much data!

Have a look: use the debugger to put a breakpoint on the start of the method, and "break out" what you are doing to make looking at it easier:
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        If int = 0 Then
            Dim read = SerialPort1.ReadExisting()
            if read = "a" Then
                'Do Something i want
            End If



查看阅读,看看你到底得到了什么。


Look at read and see exactly what you are getting.


这篇关于检查串口是否收到了哪些数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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