C#中的串口通信
我们有一种场景,多个设备连接到一个 com 端口。每个设备都有一个访问代码,该代码是在设备内手动定义的。
我可以使用 C# 中的访问代码访问所有连接的设备吗?有人知道如何做到这一点吗?
在我的情况下,多个设备通过单个端口连接,但从属地址不同。我如何访问 C# 代码中的所有从属地址以限制另一个设备不得具有相同的从属地址?
We have a scenario where multiple devices are connected to one com port. Each device has an access code, which is manually defined within the device.
Can I access all the connected devices with/by access code in C#?. Does anybody have any idea as to how to do this?
In my case multiple devices are connected with single port but slave addresses are different..how can i access all the slave address in C# code for restricting that another device shudnot have same slave address?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看一下文章 - C# 中的串行帖子 和教程
Take a look at an article - Serial post in C# and Tutorial
Jaswant,
在我工作的地方,我们有一些通过 .net 表单应用程序通过 RS232 访问的设备。我们有多个设备同时通过同一条串行线连接。
只要电缆末端的设备:
a)在通话时响应(即直接寻址) - 并且在其他时间不响应
b)使用无连接串行通信(即不握手)
那么我怀疑您在执行时会遇到问题这与您的设备有关。
我假设您必须像我们一样对您的设备进行“寻址”,即沿线路发送的每个数据块都采用特定格式(有点像 TCP 标头),例如
所有设备都会接收所有通信,但仅根据指令进行操作如果数据中的地址与设备上的地址匹配,则响应。
Jaswant,
Where I work, we have some devices that are accessed over RS232 via a .net forms app. We have multiple devices connected via the same serial line at the same time.
As long as the devices on the end of the cable:
a) respond when spoken to (i.e. directly addressed) - and at no other time
b) use connectionless serial communications (i.e. no handshaking)
then I doubt that you will have a problem doing this with your devices.
I'm assuming you will have to 'address' your device like we do, i.e. every block of data sent down the line is in a specific format (bit like a TCP header) e.g.
All devices receive all comms, but only act upon instructions and respond if the address in the data matches the address on the device.