如何将通信块发送到串行/通信端口 [英] How do I send a communication block to serial/comm port

查看:82
本文介绍了如何将通信块发送到串行/通信端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想使用串口通信(RS232)处理设备通信项目。需要以下面的格式发送通信块。不确定获取MACID以及如何发送它的部分命令。



BOF字符 - > 0XC0

MACID - > ????

命令 - > 0x0001

EOF字符 - > 0XC1



我尝试过:



尝试使用SerialPort类和打开了港口。但是不知道如何获取当前PC的MACID并将其与下面的通信块一起发送:

byte [] bytestosend = {0xC0,MACID,0x0001,0xC1};

serialPort.Write(bytestosend,0,bytestosend.Length);

Hi,
I wanted to work on a device communication project using serial port communication(RS232).Need to send the communication block in the format below. Not sure of getting the MACID and how to send it part of command.

BOF Character ->0XC0
MACID -> ????
Command ->0x0001
EOF Character -> 0XC1

What I have tried:

Tried using SerialPort class and opened the port. But do not know how to get MACID of current PC and send it along with the communication block below:
byte[] bytestosend = { 0xC0, MACID, 0x0001, 0xC1 };
serialPort.Write(bytestosend, 0, bytestosend.Length);

推荐答案

我假设你的意思是 MAC 地址

A MAC 地址 6 字节长,您可以将这些字节插入缓冲区。了解如何检索它:获取机器MAC的可靠方法C#中的地址 - Stack Overflow [ ^ ]。
I assume you mean MAC address.
A MAC address is 6 bytes long, you might insert such bytes into your buffer. See how to retrieve it: Reliable method to get machine's MAC address in C# - Stack Overflow[^].


虽然CPallini对MAC地址是正确的,但我不确定它们与您的要求有什么关系 - MAC地址仅与WiFi连接的LAN相关,与串行数据无关。如果没有任何类型的网络适配器(因此没有MAC地址),PC可以愉快地存在,但可以在串行链路上进行通信而不会出现问题。



我建议看看链路另一端的设备(RS232是点到点的,所以只有一个),并从那一端研究通信协议。制造商可能会提供帮助,并且可能提供样本PC代码,这些代码可以为您提供一个起点。
Although CPallini is right about MAC addresses, I'm not sure they have anything to do with your requirement - a MAC address is only relevant for a LAN of WiFi connection, and have nothing to do with serial data. A PC can happily exist without a network adaptor of any sort (and hence no MAC address) but communicate on a serial link without problems.

I'd suggest looking at the device on the other end of the link (RS232 is point to point so there is only one) and researching the comms protocol from that end. The manufacturer may be able to help, and may have sample PC code available which would give you a starting point.


这篇关于如何将通信块发送到串行/通信端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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