大家好 我对串行端口通信还很陌生,请帮助我如何通过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
推荐答案使用 SerialPort类 [ ^ ].从那里您可以做任何事情:-) 而且你很幸运.检查一下: 串行端口编程第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 :)
更多推荐
串行端口通讯以编程方式设置端口模式
发布评论