从vb.net中的com端口获取数据 [英] get data from com port in vb.net

查看:307
本文介绍了从vb.net中的com端口获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

i有规模,我想将它连接到计算机的com端口

i希望得到它的5字节信息并在vb.net中将其转换为long

请帮帮我

解决方案

请参考规模的SDK和/或文档。由于我们对秤本身一无所知,因此几乎不可能告诉你如何做到这一点。



现在,如果你有一个更具体的问题要问关于,也许我们可以帮忙。


你好Mtorabi,



看看>



 私有  Sub  SerialPort1_DataReceived( ByVal 发​​件人作为 对象 ByVal  e  As  System.IO.Ports.SerialDataReceivedEventArgs)句柄 SerialPort1.DataReceived 
ReceivedText(SerialPort1.ReadExisting())' 自动调用每个在serialPort收到数据的时间
结束 Sub
私有 Sub ReceivedText( ByVal [text] 作为 字符串
' 将创建线程的ID与调用线程的ID进行比较
如果 .rtbReceived.InvokeRequired 然后
昏暗 x 作为 SetTextCallback( AddressOf ReceivedText)
.Invoke(x, 对象(){(text)})
Else
Me .rtbReceived.Text& = [text]
结束 如果
结束


hello
i have scale that i want to connect it to com port in computer
i want to get 5 byte information of it and convert it to long in vb.net
please help me

解决方案

Consult with the SDK and/or documentation for the scale. Since we know nothing about the scale itself it''s pretty much impossible to tell you how to do that.

Now, if you had a more specific problem to ask about, maybe we could help with that.


Hi Mtorabi,

Take a look here.

Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
ReceivedText(SerialPort1.ReadExisting()) 'Automatically called every time a data is received at the serialPort
End Sub
Private Sub ReceivedText(ByVal [text] As String)
'compares the ID of the creating Thread to the ID of the calling Thread
If Me.rtbReceived.InvokeRequired Then
Dim x As New SetTextCallback(AddressOf ReceivedText)
Me.Invoke(x, New Object() {(text)})
Else
Me.rtbReceived.Text &= [text]
End If
End Sub


这篇关于从vb.net中的com端口获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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