积极答复者
如何通过SerialPort 组件发送和接收数据?

问题
答案
-
Hi 绿绿山水,>>好,言归正传,失恋已去,SerialPort 已来
未来会更好。
>> 1)如何通过SerialPort组件发送30H 45H这2组16进制数据呢?
你可以尝试下面的方法来发送16进制的数据
//30H 45H Byte[] sentHEX= new Byte[2]; sentHEX[0]= 0x30; sentHEX[1]= 0x45; //SerialPort.Write (Byte[], Int32, Int32) 将指定数量的字节写入输出缓冲区中的指定偏移量处。 serialPort1.Write(sentHEX, 0, 2);
下面的博客文章介绍了SerialPort串口类的一些用法,希望对你有所帮助。C# SerialPort 串口读写:
http://blog.csdn.net/kolvin2008/article/details/52833480注意:此回复包含对第三方万维网站点的引用。 微软正在为您提供这方面的信息。 Microsoft不控制这些网站,并没有测试这些网站上发现的任何软件或信息; 因此,Microsoft不能对在那里发现的任何软件或信息的质量,安全性或适用性做任何陈述。 使用互联网上发现的任何软件都存在固有的危险,微软警告您确保在从因特网检索任何软件之前,您完全了解风险。
Best Regards,
Yohann Lu
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.- 已标记为答案 绿绿山水 2017年10月27日 8:23
全部回复
-
Hi 绿绿山水,>>好,言归正传,失恋已去,SerialPort 已来
未来会更好。
>> 1)如何通过SerialPort组件发送30H 45H这2组16进制数据呢?
你可以尝试下面的方法来发送16进制的数据
//30H 45H Byte[] sentHEX= new Byte[2]; sentHEX[0]= 0x30; sentHEX[1]= 0x45; //SerialPort.Write (Byte[], Int32, Int32) 将指定数量的字节写入输出缓冲区中的指定偏移量处。 serialPort1.Write(sentHEX, 0, 2);
下面的博客文章介绍了SerialPort串口类的一些用法,希望对你有所帮助。C# SerialPort 串口读写:
http://blog.csdn.net/kolvin2008/article/details/52833480注意:此回复包含对第三方万维网站点的引用。 微软正在为您提供这方面的信息。 Microsoft不控制这些网站,并没有测试这些网站上发现的任何软件或信息; 因此,Microsoft不能对在那里发现的任何软件或信息的质量,安全性或适用性做任何陈述。 使用互联网上发现的任何软件都存在固有的危险,微软警告您确保在从因特网检索任何软件之前,您完全了解风险。
Best Regards,
Yohann Lu
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.- 已标记为答案 绿绿山水 2017年10月27日 8:23
-
Hi 绿绿山水,
0 代表 sentHEX这个数组的第一个值。一般数组是从索引0 开始算第一个数据。比如sentHEX[0] 就是30H.
serialPort1.Write(sentHEX, 0, 2); 这句话就是发送sentHEX数据到串口,从这个数组的第一个数据开始发送,一共发送2个字节的数据。
HI,如果你有新的问题,可以开启一个新的线程,不要在一个线程中问多个问题。
Best Regards,
Yohann Lu
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.