转换旧代码帮助。VB6(我想)到C#
我已经试过了,但我正在努力让它进入C# 我有2个字节,我想它们被传递到这里。4和176。我也不能运行代码转换旧代码帮助。VB6(我想)到C#,c#,vb.net,legacy,C#,Vb.net,Legacy,我已经试过了,但我正在努力让它进入C# 我有2个字节,我想它们被传递到这里。4和176。我也不能运行代码 有谁能告诉我等效的C#是什么?或者只是解释一下nChar在通过的过程中发生了什么。非常感谢 如果您没有VB6,可以将代码粘贴到VBA宏中,并以这种方式执行,以便自己完成。该代码将nChar转换为字节值的2位十六进制表示形式。然后它将两个数字发送到Com对象(串行端口?)。nOption参数被完全忽略。完全不需要使用AscW和ChrW。 public bool TransmitHex(byte
有谁能告诉我等效的C#是什么?或者只是解释一下nChar在通过的过程中发生了什么。非常感谢 如果您没有VB6,可以将代码粘贴到VBA宏中,并以这种方式执行,以便自己完成。该代码将
nChar
转换为字节值的2位十六进制表示形式。然后它将两个数字发送到Com
对象(串行端口?)。nOption
参数被完全忽略。完全不需要使用AscW
和ChrW
。
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;
}
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;
}