189 8069 5689

vb.net获取串口列表 vb编程如何获取串口数据

vb.net2010十六进制读取串口的问题

不是很明白你的题意

创新互联建站是一家集网站建设,市北企业网站建设,市北品牌网站建设,网站定制,市北网站建设报价,网络营销,网络优化,市北网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。

strHex = strHex + [String].Format("{0:X2} "

这里的意思是把每个字节数据转换成了十六进制,每个字节占两个字符

如果你串口收到的4个字节数据:43,27,56,200

那么你的结果是:2B1B38C8

即receivebytes.Text="2B1B38C8"

不足两位的补0

如果你串口收到的4个字节数据:3,27,56,200

那么你的结果是:031B38C8

即receivebytes.Text="031B38C8"

vb.net用SerialPort1获取串口信息对比文本框内容

搜一下

有串口通信的例程

借鉴一下,再根据你的情况 编程

怎样在vb中自动检测到可用串口号的具体程序代码

vb.net的话

For

Each

sp

As

String

In

My.Computer.Ports.SerialPortNames

cbxport.Items.Add(sp)

Next

vb6.0的话要调用API查看串口相关信息存在的注册表。

HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM

通过读注册表的方法获得串口数量,当然也可以获得串口号了。

Option

Explicit

Private

Declare

Function

RegOpenKey

Lib

"advapi32.dll

"

Alias

"RegOpenKeyA

"

(ByVal

hKey

As

Long,

ByVal

lpSubKey

As

String,

phkResult

As

Long)

As

Long

Private

Declare

Function

RegQueryInfoKey

Lib

"advapi32.dll

"

Alias

"RegQueryInfoKeyA

"

(ByVal

hKey

As

Long,

ByVal

lpClass

As

String,

lpcbClass

As

Long,

ByVal

lpReserved

As

Long,

lpcSubKeys

As

Long,

lpcbMaxSubKeyLen

As

Long,

lpcbMaxClassLen

As

Long,

lpcValues

As

Long,

lpcbMaxValueNameLen

As

Long,

lpcbMaxValueLen

As

Long,

lpcbSecurityDescriptor

As

Long,

lpftLastWriteTime

As

Long)

As

Long

Private

Const

HKEY_LOCAL_MACHINE

=

H80000002

'

获得当前系统的

COM

口的数量

Function

GetCOMCount()

As

Integer

Dim

ret

As

Long,

cntCOM

As

Long

RegOpenKey

HKEY_LOCAL_MACHINE,

"HARDWARE\DEVICEMAP\SERIALCOMM

",

ret

RegQueryInfoKey

ret,

"

",

0,

0,

0,

0,

0,

cntCOM,

0,

0,

0,

GetCOMCount

=

cntCOM

End

Function

Private

Sub

Command1_Click()

MsgBox

"您的机器有

"

GetCOMCount

"

个串口。

",

vbOKOnly,

"串口数量

"

End

Sub

vb.net 怎么用事件触发的方式读取串口数据

首先:

textbox里没有显示,是因为SerialPort1和TextBox2不是同一线程创建的,需要跨线程操作。需要用到委托,这样才能显示出来。

其次:

我觉得用串口的接收数据事件更好一些。

下面代码供参考:

'----------------------

'串口接收数据事件,其实比用定时器更好,

'触发事件的条件可以自己在form_load中设置ReceivedBytesThreshold属性数值,默认为ReceivedBytesThreshold=1

Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived

Dim strRecvData As String = ""

strRecvData = SerialPort1.ReadExisting

Call disPlayComData(strRecvData)

End Sub

Delegate Sub callback(ByVal strT As String) '定义委托

Sub showString(ByVal comdata As String) '显示结果

Me.TextBox1.Text = "结果:" comdata

End Sub

Sub disPlayComData(ByVal strTmp As String) '判定是否为跨线程

If Me.TextBox1.InvokeRequired Then

Dim d As New callback(AddressOf showString)

Me.Invoke(d, New Object() {strTmp})

Else

Me.TextBox1.Text = strTmp

End If

End Sub


本文题目:vb.net获取串口列表 vb编程如何获取串口数据
本文链接:http://cdxtjz.cn/article/dohoojs.html

其他资讯