【问题标题】:Modem not responsive from win32 api调制解调器不响应 win32 api
【发布时间】:2013-08-12 03:56:49
【问题描述】:

嗨 我的调制解调器和 win32 api 有问题。

当我从源代码打开通信端口时,端口已准备好接收命令,但调制解调器不写入输出。我写的所有命令都由调制解调器处理,但我没有收到调制解调器的输出。

如果我使用超级终端连接调制解调器,断开连接然后使用我的软件,则调制解调器可以成功运行。

我的代码如下:

bool open() {
    unsigned long confSize = sizeof(COMMCONFIG);
    winCommConfig.dwSize = confSize;
    DWORD dwFlagsAndAttributes = 0;

    if (!isOpen()) {
        winHandle = CreateFileA(port.toAscii(), GENERIC_READ | GENERIC_WRITE,
                FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
                dwFlagsAndAttributes, NULL);
        if (winHandle != INVALID_HANDLE_VALUE) {
            /*
             * Configure the port settings.
             */
            GetCommConfig(winHandle, &winCommConfig, &confSize);
            GetCommState(winHandle, &(winCommConfig.dcb));

            /*
             * Configure port parameters.
             */
            winCommConfig.dcb.fBinary = TRUE;
            winCommConfig.dcb.fInX = FALSE;
            winCommConfig.dcb.fOutX = FALSE;
            winCommConfig.dcb.fAbortOnError = FALSE;
            winCommConfig.dcb.fNull = FALSE;

            setBaudRate(settings.BaudRate);
            setDataBits(settings.DataBits);
            setStopBits(settings.StopBits);
            setParity(settings.Parity);
            setFlowControl(settings.FlowControl);
            setTimeout(settings.TimeoutMillisec);

            /*
             * Set the final parameters.
             */
            SetCommConfig(winHandle, &winCommConfig, sizeof(COMMCONFIG));
            SetCommState(winHandle, &(winCommConfig.dcb));
        }
    }
    return isOpen();
}

Where:
port represents the comm port
baudrate: 115200
databits: 8
stopbits: 1
parity: none
flowcontrol: off

我做错了什么?

如果我使用 jablocom gdp-04,就会发生这种情况。当我使用其他调制解调器(华为、novatel 等)时,它可以完美运行。

提前致谢。 问候。

【问题讨论】:

    标签: winapi serial-port modem


    【解决方案1】:

    流控制:关闭

    设备在看到 RTS 和 DTR 信号处于活动状态之前不会发送任何内容,这表明您“在线”并准备好接收。您需要设置 fRtsControl = RTS_CONTROL_ENABLE 和 fDtrEnable = DTR_CONTROL_ENABLE。顺便说一句,启用硬件握手永远不会伤害,假设设备正确实现它,在调试时特别方便。还要使用 HyperTerminal 或 Putty 进行基本检查,以确保接线正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-17
      相关资源
      最近更新 更多