我已经尝试过了,但我正在努力将其应用到C#中。
Private Function TransmitHex(nChar As Byte, nOption As Boolean) As Boolean
Dim sHex As String
Dim nHi As Byte
Dim nLo As Byte
sHex = Right("00" + Hex(nChar), 2)
nHi = AscW(Left$(sHex, 1))
nLo = AscW(Right$(sHex, 1))
Comm.Output = ChrW$(nHi)
Comm.Output = ChrW$(nLo)
End Function我有两个字节,我想是传入这里的。4和176。我也不能运行代码。
谁能告诉我等同于C#的是什么?或者只是解释一下nChar在运行过程中发生了什么。非常感谢!
发布于 2012-11-01 18:05:49
public bool TransmitHex(byte char, bool opt)
{
//convert to chat to a hex string and that to an array of chars
var hex = char.ToString("X2").ToCharArray();
//open a connection to a serialport
var sp = new SerialPort("COM1");
//write the hex vals
sp.Write(hex,0,1);
sp.Write(hex,1,1);
return true;
}https://stackoverflow.com/questions/13174442
复制相似问题