首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >转换旧代码帮助。VB6 (我想)到C#

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

Stack Overflow用户
提问于 2012-11-01 17:46:44
回答 1查看 238关注 0票数 0

我已经尝试过了,但我正在努力将其应用到C#中。

代码语言:javascript
复制
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在运行过程中发生了什么。非常感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-11-01 18:05:49

代码语言:javascript
复制
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;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13174442

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档