// // Tapi32Port.cpp // // Source code from: // // Serial Communications: A C++ Developer's Guide, 2nd // Edition by Mark Nelson, IDG Books, 1999 // // Please see the book for information on usage. // // This file contains the complete implementation of // class Tapi32Port,This class is derived from Win32Port, // and it uses nearly every bit of code from the base class, // with one notable exception. The normal constructor for // Win32Port expects to open a port by name. When we are // using TAPI, we don't get to open the port by name. Instead, // TAPI gets the port all set up and ready to use, then hands // us a handle to the port. The constructor defined for this // class takes that handle and inserts it into the Win32 // object, without trying to open a port with a call to // CreateFile() which is inappropriate for TAPI. // #include #include "Tapi32Port.h" Tapi32Port::Tapi32Port( HANDLE handle ) : Win32Port() { // // Win32Port has to share the debug output with the parent class. // To determine where our first line starts, we call the // FormatDebugOutput() function from our parent class. // first_debug_output_line = RS232::FormatDebugOutput(); debug_line_count = FormatDebugOutput(); port_name = (RS232PortName) -1; m_hPort = handle; m_dwErrors = 0; //Clear cumulative line status errors m_iBreakDuration = 0; //No break in progress, initialize to 0 SetLastError( 0 ); //Clear any Win32 error from this thread read_settings(); //Read and save current port settings saved_settings = settings; //Only needed because base class dumps //the saved settings in debug output //Init timeous to ensure our overlapped reads work COMMTIMEOUTS timeouts = { 0x01, 0, 0, 0, 0 }; SetCommTimeouts( m_hPort, &timeouts ); SetupComm( m_hPort, 500, 500 ); //set buffer sizes error_status = RS232_SUCCESS; //clear current class error // // Since the port opened properly, we're ready to start the // input and output threads. Before they start we create the // five Win32 events that will be used to pass requests to // the threads. Note that the only argument passed to the // thread initialization is a pointer to this. The thread // needs that to find all of the data in the Win32Port // object that it will be manipulating. // m_hKillInputThreadEvent = CreateEvent( NULL, FALSE, FALSE, NULL ); m_hKillOutputThreadEvent = CreateEvent( NULL, FALSE, FALSE, NULL ); m_hWriteRequestEvent = CreateEvent( NULL, FALSE, FALSE, NULL ); m_hReadRequestEvent = CreateEvent( NULL, FALSE, FALSE, NULL ); m_hBreakRequestEvent = CreateEvent( NULL, FALSE, FALSE, NULL ); m_hInputThread = _beginthread( InputThread, 0, (void *) this ); m_hOutputThread = _beginthread( OutputThread, 0, (void *) this ); } //EOF Tapi32Port.cpp