equal
deleted
inserted
replaced
364 } |
364 } |
365 |
365 |
366 long CRealSerialComm::ClosePort() |
366 long CRealSerialComm::ClosePort() |
367 { |
367 { |
368 COMMLOGOPEN(); |
368 COMMLOGOPEN(); |
369 COMMLOGS("CRealSerialComm::ClosePort\n"); |
369 COMMLOGA1("CRealSerialComm::ClosePort connected=%d\n", IsConnected()); |
370 |
370 |
371 long err = TCAPI_ERR_NONE; |
371 long err = TCAPI_ERR_NONE; |
372 |
372 |
373 if (!IsConnected()) |
373 if (!IsConnected()) |
374 { |
374 { |
441 // we were successful, but did we send all data? (i.e., a timeout occurred) |
441 // we were successful, but did we send all data? (i.e., a timeout occurred) |
442 // we are not doing overlapped I/O so if not all data went, then we timed out |
442 // we are not doing overlapped I/O so if not all data went, then we timed out |
443 // and there was some kind of error |
443 // and there was some kind of error |
444 if (lclNumBytes != inSize) |
444 if (lclNumBytes != inSize) |
445 { |
445 { |
|
446 m_lastCommError = 0; |
446 COMMLOGOPEN(); |
447 COMMLOGOPEN(); |
447 COMMLOGA3("CRealSerialComm::SendDataToPort WriteFile not all bytes sent: lclNumBytes=%d inSize=%d err=%d\n", lclNumBytes, inSize, GetLastError()); |
448 COMMLOGA3("CRealSerialComm::SendDataToPort WriteFile not all bytes sent: lclNumBytes=%d inSize=%d err=%d\n", lclNumBytes, inSize, m_lastCommError); |
448 COMMLOGCLOSE(); |
449 COMMLOGCLOSE(); |
449 |
450 |
450 COMSTAT lclComStat; |
451 COMSTAT lclComStat; |
451 DWORD lclErrorFlags = 0; |
452 DWORD lclErrorFlags = 0; |
452 if (!ClearCommError(m_hSerial, &lclErrorFlags, &lclComStat)) |
453 if (!ClearCommError(m_hSerial, &lclErrorFlags, &lclComStat)) |
466 { |
467 { |
467 // there really was an error |
468 // there really was an error |
468 m_lastCommError = lclErrorFlags; |
469 m_lastCommError = lclErrorFlags; |
469 err = TCAPI_ERR_COMM_ERROR; |
470 err = TCAPI_ERR_COMM_ERROR; |
470 COMMLOGOPEN(); |
471 COMMLOGOPEN(); |
471 COMMLOGA1("CRealSerialComm::SendDataToPort ClearCommError succeeded lclErrorFlags=%d\n", m_lastCommError); |
472 COMMLOGA1("CRealSerialComm::SendDataToPort ClearCommError succeeded lclErrorFlags=%d\n", lclErrorFlags); |
472 COMMLOGCLOSE(); |
473 COMMLOGCLOSE(); |
473 } |
474 } |
474 else |
475 else |
475 { |
476 { |
476 // No OS error returned, but WriteFile failed to write out all bytes |
477 // No OS error returned, but WriteFile failed to write out all bytes |
477 // therefore, since we are not doing overlapped I/O, this is an error. |
478 // therefore, since we are not doing overlapped I/O, this is an error. |
478 err = TCAPI_ERR_COMM_ERROR; |
479 err = TCAPI_ERR_COMM_ERROR; |
479 COMMLOGOPEN(); |
480 COMMLOGOPEN(); |
480 COMMLOGS("CRealSerialComm::SendDataToPort ClearCommError succeeded lclErrorFlags=0\n"); |
481 COMMLOGA1("CRealSerialComm::SendDataToPort ClearCommError succeeded lclErrorFlags=0 err=%d\n", m_lastCommError); |
481 COMMLOGCLOSE(); |
482 COMMLOGCLOSE(); |
482 // DUMPCOMSTAT(&lclComStat); |
483 // DUMPCOMSTAT(&lclComStat); |
483 } |
484 } |
484 } |
485 } |
485 } |
486 } |
528 return TCAPI_ERR_MEDIA_NOT_OPEN; |
529 return TCAPI_ERR_MEDIA_NOT_OPEN; |
529 |
530 |
530 // Sleep(1); |
531 // Sleep(1); |
531 if (!ClearCommError( m_hSerial, &lclErrorFlags, &lclComStat )) |
532 if (!ClearCommError( m_hSerial, &lclErrorFlags, &lclComStat )) |
532 { |
533 { |
|
534 if (!IsConnected()) |
|
535 return TCAPI_ERR_MEDIA_NOT_OPEN; |
|
536 |
533 m_lastCommError = GetLastError(); |
537 m_lastCommError = GetLastError(); |
534 err = TCAPI_ERR_COMM_ERROR; |
538 err = TCAPI_ERR_COMM_ERROR; |
535 |
539 |
536 PROCLOGOPEN(); |
540 PROCLOGOPEN(); |
537 PROCLOGA1("CRealSerialComm::PollPort ClearCommError failed=%d\n", m_lastCommError); |
541 PROCLOGA1("CRealSerialComm::PollPort ClearCommError failed=%d\n", m_lastCommError); |