调制解调器对 win32 api 没有响应
你好 我的调制解调器和 win32 api 有问题。
当我从源代码打开通信端口时,该端口已准备好接收命令,但调制解调器不写入输出。我编写的所有 at 命令均由调制解调器处理,但我没有收到调制解调器的输出。
如果我使用超级终端连接调制解调器,断开连接然后使用我的软件,则调制解调器可以成功工作。
我的代码如下:
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...)时,它工作得很好。
提前致谢。 问候。
Hi
I have a problem with a modem and win32 api.
When I open the comm port from my source code the port is ready to receive commands but the modem does not write output. All at commands I write are processed by the modem but I don´t receive the output from the modem.
If I connect the modem using hyperterminal, disconect and then use my software, then the modem works succesfully.
My code is as follows:
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
What am I doing wrong?
This happens if I use jablocom gdp-04. When I use other modems (huawei, novatel, ...) it works perfectly.
Thanks in advance.
Regards.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
设备在看到 RTS 和 DTR 信号处于活动状态(表明您已“在线”并准备好接收)之前不会发送任何内容。您需要设置 fRtsControl = RTS_CONTROL_ENABLE 和 fDtrEnable = DTR_CONTROL_ENABLE。顺便说一句,启用硬件握手永远不会有坏处,假设设备正确实现它,在调试时尤其方便。还可以使用超级终端或 Putty 进行基本检查,以确保接线正常。
The device won't send anything until it sees the RTS and DTR signals active, indicating that you are "online" and ready to receive. You will need to set fRtsControl = RTS_CONTROL_ENABLE and fDtrEnable = DTR_CONTROL_ENABLE. Enabling hardware handshaking never hurts btw, assuming the device implements it properly, especially handy while debugging. Also do a basic check with HyperTerminal or Putty to ensure that the wiring is okay.