如何将字符串写入(广播)到PC上的所有串行端口 [英] How can I write (broadcast) a string to all serial ports on a PC

查看:90
本文介绍了如何将字符串写入(广播)到PC上的所有串行端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有四个虚拟COM端口的USB集线器.我想连接到所有四个COM端口,并同时将相同的字符串发送给所有.任何想法该怎么做?任何Visual Basic或C ++代码将不胜感激.

I have a USB hub with four virtual COM ports on it. I would like to connect to all four COM ports and send the same string to all at the same time. Any ideas how to do this? Any Visual basic or C++ code would be appreciated.

推荐答案

您可以使用以下示例获取串行端口名称列表:
http://msdn.microsoft.com/en-us/library/9wahf8t8.aspx

You can get a list of serial port names using the example here:
http://msdn.microsoft.com/en-us/library/9wahf8t8.aspx

然后,使用循环,为列表中命名的每个串行端口打开端口,发送数据,然后关闭它.
http://msdn.microsoft.com/en-au/library/system.io.ports.serialport.open.aspx
http://msdn.microsoft.com/en-au/library/y2sxhat8.aspx
http://msdn.microsoft.com/en-au/library/system.io.ports.serialport.close.aspx

Then, using a loop, for each serial port named in that list, open the port, send the data, and close it.
http://msdn.microsoft.com/en-au/library/system.io.ports.serialport.open.aspx
http://msdn.microsoft.com/en-au/library/y2sxhat8.aspx
http://msdn.microsoft.com/en-au/library/system.io.ports.serialport.close.aspx

请注意,串行端口的字符串写入默认为适用于串行端口的字符串编码,但可能不适用于您要发送的文本.

Note that serial port writing of strings defaults to a string encoding that is appropriate for a serial port but which might not be appropriate for the text you are sending.

根据您的设备和框架版本,此处报告的问题
http://stackoverflow.com/questions/2522953/从bluetoothdevice-c/2523404#2523404获取错误的串行端口名称
可能是相关的.

Depending on your device and framework version the problem reported here
http://stackoverflow.com/questions/2522953/getting-wrong-serial-port-names-from-bluetoothdevice-c/2523404#2523404
might be relevant.


这篇关于如何将字符串写入(广播)到PC上的所有串行端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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