0
Performing an integration of an RS232 device, we found an obstacle that is related to the flow control using the RTS and DTR with the equipment. Using the Escapecommfunction function to manipulate the signals on these pins, it was not possible to establish communication with the apparatus, having no response to the communication boot command. Example:
Initializing the door
HANDLE hSerial;
DCB dcbSerialParams = {0};
COMMTIMEOUTS timeouts = {0};
hSerial = CreateFile("\\\\.\\COM1", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL );
dcbSerialParams.BaudRate = CBR_19200;
dcbSerialParams.ByteSize = 7;
dcbSerialParams.StopBits = ONESTOPBIT;
dcbSerialParams.Parity = EVENPARITY;
dcbSerialParams.fDtrControl = DTR_CONTROL_ENABLE;
dcbSerialParams.fRtsControl = RTS_CONTROL_ENABLE;
SetCommState(hSerial, &dcbSerialParams);
timeouts.ReadIntervalTimeout = 50;
timeouts.ReadTotalTimeoutConstant = 50;
timeouts.ReadTotalTimeoutMultiplier = 10;
timeouts.WriteTotalTimeoutConstant = 50;
timeouts.WriteTotalTimeoutMultiplier = 10;
SetCommTimeouts(hSerial, &timeouts);
EscapeCommFunction(hSerial,CLRDTR);
EscapeCommFunction(hSerial,CLRRTS);
Sending command
EscapeCommFunction(hSerial,SETRTS)
DWORD bytes_written, total_bytes_written = 0;
if(!WriteFile(hSerial, bytes_to_send, sizeof(bytes_to_send), &bytes_written, NULL))
{
fprintf(stderr, "Erro\n");
CloseHandle(hSerial);
return 1;
}
fprintf(stderr, "%d bytes escritos...", bytes_written);
EscapeCommFunction(hSerial,CLRRTS);
Visualizing answers
char buffer[32];
DWORD bytes_read;
//loop infinito de leitura
while(true){
EscapeCommFunction(hSerial,SETDTR)
ReadFile(hSerial, buffer, sizeof(buffer), &bytes_read, NULL);
if (bytes_read){
fprintf(stderr, "Número de bytes lidos %d\n",bytes_read);
}
EscapeCommFunction(hSerial,CLRDTR)
}
There is no response from the equipment, however, we know that the command used has no errors, because the manufacturer provides a software that performs the same communication but not exporting the data, serving only for visualization, and making a Spy on the door during this communication, we verify the integrity of the.
There is something that could be going blank in this control or another way to be realized?