C#.net中的串行端口 [英] Serial Ports in C#.net

查看:128
本文介绍了C#.net中的串行端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

人们.
我正在开发一些设备自动化应用程序,需要通过串行pport和RS232接口连接到该设备,并将ASCII数据发送和接收到端口.我已经使用了一些像这样的代码:

Hi people.
I''m working on some device automation application and need to connect to it via a serial pport and a RS232 interface and send and recieve ASCII data to the port. I''ve used some codes like this:

SerialPort srp = new SerialPort("COM2", 19200, Parity.None, 8, StopBits.One);

srp.Open();
srp.WriteLine("some commands");
srp.Close();



我的设备对此代码不采取任何措施,但是我对命令语法有把握.我的二手代码中有问题吗?有人可以帮我吗?



My device takes no action with this code but I''m sure about the command syntax. Is the problem in my used code? Could anyone help me please?

推荐答案



当您使用writeLine方法将指定的字符串和NewLine值写入输出缓冲区时.新行可能是问题所在.您可以验证一下.

杰瑞姆(Jerem)
Hi,

When you use writeLine Method that writes the specified string and the NewLine value to the output buffer. The New line is maybe the problem. You can verify this.

Jerem



您的代码似乎正确吗?
您可以下载任何虚拟串行端口仿真器.配对任何两个虚拟端口,并让您的应用程序与任何已配对的端口连接.将消息发送到同一端口,您将可以使用Microsoft超级终端侦听其他端口(或者您可以创建自己的应用程序以侦听并将消息发送到端口).如果正确获取消息,则代码中没有问题.可能是分隔符是问题所在.

希望这会帮助你.
我正在使用 http://www.eterlogic.com/ [
Hi
Your code seems right?
You can download any virtual Serial port emulator . Pair any two virtual port and let your application connect with any port ,just paired. Send the message to the same port , you will can listen to other port using the Microsoft hyper terminal ( or you can create your own app to listen and send message to a port). If you are getting the message properly ,then there is no issues in your code . May be the delimiter is the issue.

hope this will help you.
I am usingvirtual serial port emulator from http://www.eterlogic.com/[^]


我不是专家,但是您尝试过吗?

I am not an expert but have you tried this?

SerialPort srp = new SerialPort("COM2", 19200, Parity.None, 8, StopBits.One);
srp.Open();
srp.WriteLine("some commands"+Environment.NewLine);
srp.Close();


这篇关于C#.net中的串行端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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