Note that there are some explanatory texts on larger screens.

plurals
  1. POmodem call in c++
    primarykey
    data
    text
    <p>I'm trying to make a modem call in one end, and in the other end the program answers the call. It doesn't seem to detect the carrier. Am I doing anything wrong? Am I missing something?</p> <pre><code>int main(int argc, char** argv) { ParseArgs(argc,argv); SerialPort* port = SerialPort::New(); if(!port) Error(ErrorNoMemory,"Can't create port"); int error = port-&gt;Open(PortNum, SendFlag); if(error) Error(error,"Can't open port"); error = port-&gt;Initialise(PortBaud); if(error) Error(error,"Can't initialise port"); if(ReceiveFlag) { port-&gt;Listen(); Receive(port); //after the call is stablished I send a file } else { port-&gt;Dial(PhoneNumber); Send(port); } port-&gt;Close(); delete port; return 0; } </code></pre> <p>The part of opening the port:</p> <pre><code>int Open(unsigned port, bool SendFlag) { // make name for port... char name[] = "\\\\.\\com???.???"; char* nameNumber = name+sizeof(name)-8; char* nameEnd = nameNumber; if(port&gt;999){ return ErrorInvalidPort; } if(port&gt;99) { *nameEnd++ = '0'+port/100; port %= 100; } if(port&gt;9) { *nameEnd++ = '0'+port/10; port %= 10; } *nameEnd++ = '0'+port; *nameEnd = 0; // open port... hSerial = CreateFile(name, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if(hSerial==INVALID_HANDLE_VALUE) { switch(GetLastError()) { case ERROR_FILE_NOT_FOUND: return ErrorInvalidPort; case ERROR_ACCESS_DENIED: return ErrorPortInUse; default: return Error(); } } SetupComm( hSerial, 1024, 1024 ); if (!SendFlag) { if (!SetCommMask(hSerial, EV_RING |EV_RLSD)) // Error setting communications mask printf("error mascara"); } else { if (!SetCommMask(hSerial, EV_RLSD)) { // Error setting communications mask printf("error mascara"); } } return 0; } </code></pre> <p>The initialise part:</p> <pre><code>int Initialise(unsigned baud) { // flush port... if(!FlushFileBuffers(hSerial)) return Error(); if(!PurgeComm(hSerial, PURGE_TXABORT|PURGE_RXABORT|PURGE_TXCLEAR|PURGE_RXCLEAR)) return Error(); // configure port... DCB dcb ; if(!GetCommState(hSerial, &amp;dcb)) return Error(); dcb.BaudRate = CBR_115200; dcb.ByteSize = 8; dcb.StopBits = ONESTOPBIT; dcb.Parity = NOPARITY; if(!SetCommState(hSerial, &amp;dcb)) { if(GetLastError()==ERROR_INVALID_PARAMETER) return ErrorInvalidSettings; return Error(); } // set timeouts to zero so read/writes return immediately... COMMTIMEOUTS timeouts = {0}; timeouts.ReadIntervalTimeout = MAXDWORD; timeouts.ReadTotalTimeoutConstant = 0; timeouts.ReadTotalTimeoutMultiplier = 0; timeouts.WriteTotalTimeoutConstant = 0; timeouts.WriteTotalTimeoutMultiplier= 0; if(!SetCommTimeouts(hSerial, &amp;timeouts)) return Error(); // flush port again... if(!PurgeComm(hSerial, PURGE_TXABORT|PURGE_RXABORT|PURGE_TXCLEAR|PURGE_RXCLEAR)) return Error(); return 0; } </code></pre> <p>The dial part:</p> <pre><code>int Dial(char *telefono) { unsigned long int n = 0; DWORD dwCommEvent; DWORD bytes; DWORD dwRead; char cadena[15]; char chRead; sprintf(cadena, "ATDT%s\r", telefono); if (!WriteFile( hSerial, "ATH1\r", strlen("ATH1\r"), (&amp;(n)), 0 )) { printf("error"); } FlushFileBuffers( hSerial ); Sleep(1000); if (!WriteFile( hSerial, cadena, strlen(cadena), (&amp;(n)), 0)) { printf("error"); } FlushFileBuffers( hSerial ); Sleep(10000); printf("Marcamos"); do { printf("Espero eventos"); if(WaitCommEvent(hSerial, &amp;dwCommEvent, NULL)) { if(dwCommEvent &amp; EV_RLSD) { printf("rlsd"); break; } else { printf("otro"); } } printf("fin del bucle"); } while(true); return 0; } </code></pre> <p>The listening part:</p> <pre><code>int Listen() { DWORD dwCommEvent; unsigned long int n = 0; do { printf("ESpero eventos"); if(WaitCommEvent(hSerial, &amp;dwCommEvent, NULL)) { if(dwCommEvent &amp; EV_RING) { printf("RING"); if (!WriteFile( hSerial, "ATA\r", strlen("ATA\r"), (&amp;(n)), 0 )) { printf("error"); } FlushFileBuffers( hSerial ); break; } else if (dwCommEvent &amp; EV_RLSD ) { break; } } printf("fin del bucle"); } while(true); return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload