Wifibot RS232串口通讯[关闭](Wifibot RS232 Serial Communication [closed])

编程入门 行业动态 更新时间:2024-10-26 22:26:03
Wifibot RS232串口通讯[关闭](Wifibot RS232 Serial Communication [closed])

我正在使用Wifibot平台进行机器人项目,这个机器人包含一个Windows Embedded Standard 7操作系统 ,简而言之,我想通过RS232将一些位从WES7发送到DSPIC 3FF ,控制平台电机使机器人移动,我用C#开发了很多程序,但没有结果,你们有什么帮助。

using System; using System.IO.Ports; using System.Threading; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace sendsendRS232 { class Program { static void Main(string[] args) { SerialPort serial = new SerialPort(); serial.PortName = "COM2"; serial.BaudRate = Convert.ToInt32(9200); serial.Handshake = System.IO.Ports.Handshake.None; serial.Parity = Parity.None; serial.DataBits = 8; serial.StopBits = StopBits.One; serial.ReadTimeout = 200; serial.WriteTimeout = 50; serial.Open(); if (serial.IsOpen) { byte[] hexstring = { 255, 0, 120, 0}; foreach (byte hexval in hexstring) { byte[] _hexval = new byte[] { hexval }; serial.Write(_hexval, 0, 1); Thread.Sleep(1); } } } } }

I am working on Robotic project with Wifibot Platform, this robot contains a Windows Embedded Standard 7 OS, to make things short, i want to send some bits from the WES7 to a DSPIC 3FF via RS232 that controls the platform motors to make the robot move, i have developed a lot of programs using C#, but no results, is there any help from you guys.

using System; using System.IO.Ports; using System.Threading; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace sendsendRS232 { class Program { static void Main(string[] args) { SerialPort serial = new SerialPort(); serial.PortName = "COM2"; serial.BaudRate = Convert.ToInt32(9200); serial.Handshake = System.IO.Ports.Handshake.None; serial.Parity = Parity.None; serial.DataBits = 8; serial.StopBits = StopBits.One; serial.ReadTimeout = 200; serial.WriteTimeout = 50; serial.Open(); if (serial.IsOpen) { byte[] hexstring = { 255, 0, 120, 0}; foreach (byte hexval in hexstring) { byte[] _hexval = new byte[] { hexval }; serial.Write(_hexval, 0, 1); Thread.Sleep(1); } } } } }

最满意答案

我们没有太多要继续下去,因为我们没有您正在与之通信的设备的文档,所以我们无法检查串口设置,或者您写入端口的4字节数据是要发送给它的正确消息。

由于您将握手设置为无,因此您可能希望将DtrEnable和RtsEnable设置为要发送的设备的真实典型设置。

检查可能是一个问题的另一件事是数据的“终结性”。 如果您发送的数据包含多字节值且一个设备是big-endian而另一个设备是little-endian,那么发送字节的顺序很重要,请参阅以下更详细的说明 。

不幸的是,它通常归结为尝试设置,甚至使用Hyperterminal或Putty等终端程序连接到设备并发送相同的数据。

同样,在处理像SerialPort一样实现IDisposable的类时,我会在using语句中使用它,例如:

using(SerialPort serial = new SerialPort()) { // do stuff }

这样,当连接超出范围时,连接将始终关闭并处理掉。

We've not got much to go on here, since we don't have the documentation for the device you are communicating with, so we cannot check the serial port settings, or whether the 4 bytes of data you are writing to the port are a correct message to send to it.

Since you have handshaking set to None, you might want to play with setting DtrEnable and RtsEnable to true, typical settings for a device that wants to send.

Another thing to check that might be an issue is the 'endedness' of the data. If the data you are sending includes multi-byte values and one device is big-endian and another is little-endian, then the order the bytes are sent in is important, see the following more detailed explanation.

Unfortunately it often comes down to experimenting with settings, or even using terminal programs like Hyperterminal or Putty to connect to the device and send the same data.

Just as an aside, when dealing with classes that implement IDisposable like the SerialPort does, I would use it within a using statement, e.g.:

using(SerialPort serial = new SerialPort()) { // do stuff }

That way the connection will always be closed and disposed of when it goes out of scope.

更多推荐

本文发布于:2023-08-05 15:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1434749.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:串口   通讯   Wifibot   Communication   Serial

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!