首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C# SerialPort DSR/DTR和CTS/RTS握手

C# SerialPort DSR/DTR和CTS/RTS握手
EN

Stack Overflow用户
提问于 2014-06-26 02:47:34
回答 2查看 16.7K关注 0票数 4

我正在尝试使用C#/.NET的SerialPort类与设备通信。

这里描述了与设备交互的文档。

我正在使用一个与TX/RX和所有握手引脚交换(验证)的零调制解调器电缆。

我希望下面的C#代码能够工作,但我不会从我试图与之交互的相机中得到任何响应(低到高)。不过,我相信问题在于代码。这台相机与其他“个人电脑”一起工作。为什么我永远不会在我的代码中获得DsrHolding (空调制解调器电缆,所以从相机高DTR )成为真?

代码语言:javascript
复制
static void Main(string[] args)
{
    var serialPort = new SerialPort("COM5");

    // start the DSR/DTR handshake
    // we are using a null modem cable, so DTR/DSR is switched
    serialPort.DtrEnable = true;
    while (!serialPort.DsrHolding)
    {
        // probally should timeout instead of infinite wait
        Thread.Sleep(10);
        Console.WriteLine("Waiting for the DTR line to go high.");
    }


    // start the RTS/CTS handshake
    // we are using a null modem cable, so RTS/CTS is switched
    serialPort.RtsEnable = true;
    while (!serialPort.CtsHolding)
    {
        // probally should timeout instead of infinite wait
        Thread.Sleep(10);
        Console.WriteLine("Waiting for the RTS line to go high.");
    }

    // read/write
    //serialPort.Write("Some command");
    //var response = serialPort.ReadChar();
    //while (response != stopBit)
    //    response = serialPort.ReadChar();

    // close the connection because we have written/read our data

    // start the DSR/DTR handshake
    // we are using a null modem cable, so DTR/DSR is switched
    serialPort.DtrEnable = false;
    while (serialPort.DsrHolding)
    {
        // probally should timeout instead of infinite wait
        Thread.Sleep(10);
        Console.WriteLine("Waiting for the DTR line to go low.");
    }


    // start the RTS/CTS handshake
    // we are using a null modem cable, so RTS/CTS is switched
    serialPort.RtsEnable = false;
    while (serialPort.CtsHolding)
    {
        // probally should timeout instead of infinite wait
        Thread.Sleep(10);
        Console.WriteLine("Waiting for the RTS line to go low.");
    }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-06-26 19:02:33

你试过用直通电缆吗?相机可能已经处理了需要交叉的引脚。

票数 2
EN

Stack Overflow用户

发布于 2016-11-14 13:48:38

代码中缺少serialPort.Open();

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24421631

复制
相关文章

相似问题

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