传递字节值throgh serialport [英] Passing byte value throgh serialport
本文介绍了传递字节值throgh serialport的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过串口发送数字作为字节,而不是字符串。
我的意思是如果我想发送120,那应该是1字节,而不是2
后跟一个2和一个0.如何可能?
I'm trying to send numbers over the serial port as bytes, not strings.
What I mean is if I want to send a 120, that should be 1 byte, not a 2
followed by a 2 and a 0.How it possible?
推荐答案
如果你使用System.IO.Ports的SerialPort类: http://msdn.microsoft.com/de-de/library/ms143551% 28v = vs.100%29.aspx [ ^ ]
If you use SerialPort class from System.IO.Ports: http://msdn.microsoft.com/de-de/library/ms143551%28v=vs.100%29.aspx[^]
public void Write(
byte[] buffer,
int offset,
int count
)
buffer
Type: System.Byte[]
The byte array that contains the data to write to the port.
offset
Type: System.Int32
The zero-based byte offset in the buffer parameter at which to begin copying bytes to the port.
count
Type: System.Int32
The number of bytes to write.
这篇关于传递字节值throgh serialport的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文