Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
转换旧代码帮助。VB6(我想)到C#_C#_Vb.net_Legacy - Fatal编程技术网

转换旧代码帮助。VB6(我想)到C#

转换旧代码帮助。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#

我有2个字节,我想它们被传递到这里。4和176。我也不能运行代码


有谁能告诉我等效的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;
}