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.
flowcontrol: off
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.