如何使用visual basic发送和接收十六进制命令 [英] How do I send and receive hex commands with visual basic
本文介绍了如何使用visual basic发送和接收十六进制命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
坚持如何接收数据?
为了给你一些背景信息,我有Optris CT红外传感器,你有一个命令列表可以通过谷歌搜索Optris CT命令找到。
我们非常感谢任何帮助。
我尝试了什么:
1.声明COM端口
2.编写一个打开端口的函数
3.编写一个发送数据的函数 - 我不确定它是否正确
>
Imports System.IO.Ports
Public 类 Form1
Dim ComPort 作为 新 SerialPort( COM1 , 9600 ,Parity.None, 8 , 1 )
私有 Sub Form1_Load( BYVAL sender As System。 Object , ByVal e As System.EventArgs)句柄 MyBase .Load
ComPort.Open()
结束 Sub
私有 Sub cmdSend_Click( ByVal sender As System。 Object , ByVal e As System.EventArgs)句柄 cmdSend.Click
Dim sendArray()作为 字节 = 新 字节e (){& H01,& H0,& H0,& H0,& H0,& H0,& H0,& H0}
ComPort。写(sendArray, 0 , 8 )
结束 Sub
解决方案
嗯。
私有 Sub cmdSend_Click( ByVal sender As System。 Object ,< span class =code-keyword> ByVal e As System.EventArgs)句柄 cmdStop .Click
Dim sendArray() As Byte = 新 字节(){& H01,& H0,& H0, &安培; H0 ,& H0,& H0,& H0,& H0}
ComPort.Write(stopArray, 0 , 8 )
结束 Sub
你的意思是发送sendArray
而不是stopArray
?:
ComPort.Write(sendArray, 0 , 8 跨度>)
Stuck on how to receive data?
To give you some context, I have the "Optris CT" IR sensor, there is a list of commands which you can find by googling Optris CT commands.
Any help would be greatly appreciated.
What I have tried:
1. Declared the COM port
2. Written a function for opening port
3. Written a function for sending data - which I'm not sure if its correct
Imports System.IO.Ports
Public Class Form1
Dim ComPort As New SerialPort("COM1", 9600, Parity.None, 8, 1)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ComPort.Open()
End Sub
Private Sub cmdSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSend.Click
Dim sendArray() As Byte = New Byte() {&H01, &H0, &H0, &H0, &H0, &H0, &H0, &H0}
ComPort.Write(sendArray, 0, 8)
End Sub
解决方案
Um.
Private Sub cmdSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStop.Click Dim sendArray() As Byte = New Byte() {&H01, &H0, &H0, &H0, &H0, &H0, &H0, &H0} ComPort.Write(stopArray, 0, 8) End Sub
Did you mean to send thesendArray
instead ofstopArray
?:
ComPort.Write(sendArray, 0, 8)
这篇关于如何使用visual basic发送和接收十六进制命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文