通过RS232连接打开插座 [英] Opening a socket over a RS232 connection

查看:46
本文介绍了通过RS232连接打开插座的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个"C#服务器"程序使用.NET套接字侦听端口5500的"127.0.0.1",并且有一个相应的C#客户端程序从同一台PC向该套接字发送消息.他们俩都工作正常.

I have a 'C# server' program listening to '127.0.0.1', port 5500, using .NET socket, and i have a corresponding C# client program sending messages to this socket from the same PC. They both work fine.

现在,如果我在单独的PC上运行客户端"和服务器"程序,并通过连接其串行端口(RS232)的电缆将它们连接起来,我是否应该更改代码以使其正常工作?我要问的是,因为我没有2台PC可以检查,但部署时需要它能正常工作.

Now if i run the 'client' and 'server' programs on seperate PC's and connect them via a cable connecting their serial ports (RS232), should i make changes to code to make them work ? I am asking since i dont have 2 PC's to check , but need it to work when deployed.

谢谢.

推荐答案

如果两台计算机都具有适当的驱动程序来将串行端口视为网络连接,则它应该可以正常工作.

Well, if both computers have appropriate drivers to treat the serial port as a network connection, it should work without any changes.

否则,您将必须使用 SerialPort 类.明确地通过串行端口进行通话.

Otherwise, you'll have to use the SerialPort class. to explicitly talk over the serial port.

您可能会发现最好是对代码进行抽象处理,使其可以在 streams 上工作-然后您可以从网络连接中获取流,而大多数情况下您的代码不需要更改.

You may find it best to abstract your code so that it works over streams - then you can get the stream from a network connection or a serial connection, and most of your code won't need to change.

这篇关于通过RS232连接打开插座的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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