串行端口通讯以编程方式设置端口模式 [英] Serial port communication set the port mode programatically

查看:106
本文介绍了串行端口通讯以编程方式设置端口模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我对串行端口通信还很陌生,请帮助我如何通过c Sharp设置端口模式.

谢谢和问候
Pavan Kumar

Hi All

I am pretty new to serial port communication Please help me out how to set port mode through c sharp.

Thanks and regards
Pavan Kumar

推荐答案

使用串行端口编程第1部分-(非常)简要介绍 [ ^ ]
串行端口编程第2部分–开发GUI以设置端口设置和验证数据 [ ^ ]
串行端口编程–第3部分:最终触摸和发送数据 [
Use SerialPort Class[^]. From there you can do anything :-)

And you are lucky. Check this out:

Serial Port Programming Part 1 – A (very) brief introduction[^]
Serial Port Programming Part 2 – Developing a GUI to set the Port Settings and validating the data[^]
Serial Port Programming – Part 3: Final touches and sending data[^]


在.Net中这很简单.您需要添加以下库:

That''s pretty simple in .Net. You need to add these library:

using System.IO.Ports;



打开/关闭端口:



To open/close a port:

serialport.Open();
serialport.Close();



但是您需要小心,不要打开一个打开的窗口.您需要使用以下命令检查其是否打开:



but you need to be carefull not the open an open one. You need to check if it''s open or not with:

serialport.IsOpen();



然后,您可以使用SerialPort类并进行端口调整,端口名称,波特率,奇偶校验,握手...



Then you can use SerialPort class and make necassery adjustments like Port name, baudrate, parity, handshake...

seriPort.PortName = ....;
serialPort.BaudRate = ...;
serialPort.Parity = Parity.None;
serialPort.Handshake = Handshake.RequestToSend;




另外,您可以使用以下小代码获取所有的serialPort(包括虚拟名称)名称:




Also, you can get all the serialPort(including virtual ones) names using this little code:

serialport.GetPortNames();



玩得开心:)



Have Fun :)


这篇关于串行端口通讯以编程方式设置端口模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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