VB程序员博客
如题:
vb 怎么实现串口端口的扫描呢?就是将电脑上现有的串口号扫描罗列出来。
大家都没上班吗 自己先顶
small but effective tool(if u know the rite way to use it..u might do wonders..)
——————–
you need:
2 textboxes
1 listbox
3 commandbuttons
1 timer
1 winsock control
——————–
Code: VB
Private Sub Command1_Click() Timer1.Enabled = TrueEnd SubPrivate Sub Command2_Click() Timer1.Enabled = False Text2.Text = "0"End SubPrivate Sub Command3_Click() List1.ClearEnd SubPrivate Sub Timer1_Timer() On Error Resume Next Winsock1.Close Text2.Text = Int(Text2.Text) + 1 Winsock1.RemoteHost = Text1.Text Winsock1.RemotePort = Text2.Text Winsock1.ConnectEnd SubPrivate Sub Winsock1_Connect() List1.AddItem Winsock1.RemotePort & " is open!"End Sub——————–
explanation:
text1 = IP to scan
text2 = starting port
list1 = list where all open ports are shown
command1 = start
command2 = stop and reset
command3 = clear port list
timer1 = will make the winsock control to try ports
我要扫描的是串口端口
查注册表。可以得到所有固有的硬件串口和虚拟串口。
4楼的方法可行
四楼的方法是行 但有时候 虚拟端口的端口 可能会比较大 顺序查找的话没什么效率啊,而且事先也不知道查到哪为止
of123能告诉我怎么查注册表吗
呼叫OF123 大哥还在不
HKEY_LOCAL_MACHINEHARDWAREDEVICEMAPSERIALCOMM
一般pc支持16个串口,所以想1~17去遍历也不行,如果事先知道没那么多串口,可以1~8遍历就行,我试过了,这样遍历可以将虚拟串口一块罗列出来,注册表的方法也不错,但如果操作系统不同,位置会不会不同呢?还有如果人为在注册表删掉键值,读出来就是错误了。一般在form_load里面判断一次,速度应该不是问题吧?
不想说话
我以前做过一个一转16 的虚拟串口 每次换个USB口都会有不同的 虚拟口,有时候虚拟口都到40多的 所以我觉得遍历方法会不可靠
搞错,虽然pc支持串口数没那么多,但可遍历数很大,1~1000都没问题。