464 // clear comm error returned OK |
464 // clear comm error returned OK |
465 // check error flags |
465 // check error flags |
466 if (lclErrorFlags) |
466 if (lclErrorFlags) |
467 { |
467 { |
468 // there really was an error |
468 // there really was an error |
469 m_lastCommError = lclErrorFlags; |
|
470 err = TCAPI_ERR_COMM_ERROR; |
469 err = TCAPI_ERR_COMM_ERROR; |
471 COMMLOGOPEN(); |
470 COMMLOGOPEN(); |
472 COMMLOGA1("CRealSerialComm::SendDataToPort ClearCommError succeeded lclErrorFlags=%d\n", lclErrorFlags); |
471 COMMLOGA1("CRealSerialComm::SendDataToPort ClearCommError succeeded lclErrorFlags=%d\n", lclErrorFlags); |
473 COMMLOGCLOSE(); |
472 COMMLOGCLOSE(); |
474 } |
473 } |
475 else |
474 else |
476 { |
475 { |
477 // No OS error returned, but WriteFile failed to write out all bytes |
476 // No OS error returned, but WriteFile failed to write out all bytes |
478 // therefore, since we are not doing overlapped I/O, this is an error. |
477 // therefore, since we are not doing overlapped I/O, this is an error. |
479 err = TCAPI_ERR_COMM_ERROR; |
478 // DUMPCOMSTAT(&lclComStat); |
|
479 BOOL flush = FlushFileBuffers(m_hSerial); // flush transmit buffer |
|
480 // ClearCommError(m_hSerial, &lclErrorFlags, &lclComStat); |
|
481 // if (WriteFile(m_hSerial, inData, inSize, &lclNumBytes, NULL)) |
|
482 // { |
|
483 // COMMLOGOPEN(); |
|
484 // COMMLOGA1("CRealSerialComm::SendDataToPort WriteFile#2 succeeded lclNumBytes=%d\n", lclNumBytes); |
|
485 // COMMLOGCLOSE(); |
|
486 // } |
|
487 err = TCAPI_ERR_COMM_ERROR_DEVICE_NOT_READING; |
480 COMMLOGOPEN(); |
488 COMMLOGOPEN(); |
481 COMMLOGA1("CRealSerialComm::SendDataToPort ClearCommError succeeded lclErrorFlags=0 err=%d\n", m_lastCommError); |
489 COMMLOGA2("CRealSerialComm::SendDataToPort ClearCommError succeeded lclErrorFlags=0 err=%d flush=%d\n", m_lastCommError, flush); |
482 COMMLOGCLOSE(); |
490 COMMLOGCLOSE(); |
483 // DUMPCOMSTAT(&lclComStat); |
491 // DUMPCOMSTAT(&lclComStat); |
484 } |
492 } |
485 } |
493 } |
486 } |
494 } |
491 #ifdef _DEBUG |
499 #ifdef _DEBUG |
492 COMMLOGOPEN(); |
500 COMMLOGOPEN(); |
493 COMMLOGS("CRealSerialComm::SendDataToPort WriteFile successful\n"); |
501 COMMLOGS("CRealSerialComm::SendDataToPort WriteFile successful\n"); |
494 BYTE* ptr = (BYTE*)inData; |
502 BYTE* ptr = (BYTE*)inData; |
495 long numBytes = (inSize > 80) ? 80 : inSize; |
503 long numBytes = (inSize > 80) ? 80 : inSize; |
496 char msg[200]; |
504 char msg[300]; |
497 sprintf(msg, "CRealSerialComm::SendDataToPort = "); |
505 sprintf(msg, "CRealSerialComm::SendDataToPort = "); |
498 for (int i = 0; i < numBytes; i++) |
506 for (int i = 0; i < numBytes; i++) |
499 { |
507 { |
500 sprintf(msg, "%s %02.2x", msg, ptr[i]); |
508 sprintf(msg, "%s %02.2x", msg, ptr[i]); |
501 } |
509 } |
523 outSize = 0; |
531 outSize = 0; |
524 |
532 |
525 COMSTAT lclComStat; |
533 COMSTAT lclComStat; |
526 DWORD lclErrorFlags=0; |
534 DWORD lclErrorFlags=0; |
527 |
535 |
528 if (!IsConnected()) |
536 if (!IsConnected() || m_hSerial == INVALID_HANDLE_VALUE) |
529 return TCAPI_ERR_MEDIA_NOT_OPEN; |
537 return TCAPI_ERR_MEDIA_NOT_OPEN; |
|
538 |
530 |
539 |
531 // Sleep(1); |
540 // Sleep(1); |
532 if (!ClearCommError( m_hSerial, &lclErrorFlags, &lclComStat )) |
541 if (!ClearCommError( m_hSerial, &lclErrorFlags, &lclComStat )) |
533 { |
542 { |
534 if (!IsConnected()) |
543 if (!IsConnected() || m_hSerial == INVALID_HANDLE_VALUE) |
535 return TCAPI_ERR_MEDIA_NOT_OPEN; |
544 return TCAPI_ERR_MEDIA_NOT_OPEN; |
536 |
545 |
537 m_lastCommError = GetLastError(); |
546 m_lastCommError = GetLastError(); |
538 err = TCAPI_ERR_COMM_ERROR; |
547 err = TCAPI_ERR_COMM_ERROR; |
539 |
548 |