0

私はこれを実行しようとしましたが、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

ここに渡されると思う2バイトがあります。4と176。コードも実行できません。

誰かが同等のC#が何であるかを教えてもらえますか?または、途中でnCharに何が起こるかを説明してください。どうもありがとう!

4

1 に答える 1

1
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;
}
于 2012-11-01T10:05:48.840 に答える