[Com0com-cvs] hub4com/plugins/serial comio.cpp, 1.1, 1.2 comio.h, 1.1, 1.2 comparams.cpp, 1.1, 1.2
The virtual serial port driver for Windows.
Brought to you by:
vfrolov
From: Vyacheslav F. <vf...@us...> - 2008-04-07 12:28:10
|
Update of /cvsroot/com0com/hub4com/plugins/serial In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv16030 Modified Files: comio.cpp comio.h comparams.cpp comparams.h comport.cpp comport.h port.cpp Log Message: Replaced --rt-events option by SET_RT_EVENTS message Index: comport.cpp =================================================================== RCS file: /cvsroot/com0com/hub4com/plugins/serial/comport.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** comport.cpp 26 Mar 2008 08:44:34 -0000 1.1 --- comport.cpp 7 Apr 2008 12:28:03 -0000 1.2 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.2 2008/04/07 12:28:03 vfrolov + * Replaced --rt-events option by SET_RT_EVENTS message + * * Revision 1.1 2008/03/26 08:44:34 vfrolov * Redesigned for using plugins *************** *** 54,57 **** --- 57,61 ---- countXoff(0), filterX(FALSE), + events(0), writeQueueLimit(256), writeQueued(0), *************** *** 87,102 **** CheckComEvents(DWORD(-1)); - DWORD events; - - if (!::GetCommMask(handle, &events)) { - DWORD err = ::GetLastError(); - - cerr << "ComPort::Start(): GetCommMask() ERROR " << err << endl; - return FALSE; - } - - if (events && !StartWaitCommEvent()) - return FALSE; - if (!StartRead()) return FALSE; --- 91,94 ---- *************** *** 212,215 **** --- 204,222 ---- return FALSE; } + else + if (pMsg->type == HUB_MSG_TYPE_SET_RT_EVENTS) { + if (events != pMsg->u.val) { + if (handle == INVALID_HANDLE_VALUE) + return FALSE; + + events = pMsg->u.val; + + if (!SetComEvents(handle, &events)) + return FALSE; + + if (events && !StartWaitCommEvent()) + return FALSE; + } + } return TRUE; *************** *** 238,242 **** countWaitCommEventOverlapped++; ! //cout << "Started WaitCommEvent " << name << " " << countReadOverlapped << endl; return TRUE; --- 245,250 ---- countWaitCommEventOverlapped++; ! //cout << "Started WaitCommEvent " << name << " " << countReadOverlapped ! // << " " << hex << events << dec << endl; return TRUE; *************** *** 278,286 **** CheckComEvents(eMask); ! if (!pOverlapped->StartWaitCommEvent()) { delete pOverlapped; countWaitCommEventOverlapped--; ! cout << "Stopped WaitCommEvent " << name << " " << countWaitCommEventOverlapped << endl; } } --- 286,294 ---- CheckComEvents(eMask); ! if (!events || !pOverlapped->StartWaitCommEvent()) { delete pOverlapped; countWaitCommEventOverlapped--; ! //cout << "Stopped WaitCommEvent " << name << " " << countWaitCommEventOverlapped << endl; } } Index: comparams.cpp =================================================================== RCS file: /cvsroot/com0com/hub4com/plugins/serial/comparams.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** comparams.cpp 26 Mar 2008 08:44:13 -0000 1.1 --- comparams.cpp 7 Apr 2008 12:28:03 -0000 1.2 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.2 2008/04/07 12:28:03 vfrolov + * Replaced --rt-events option by SET_RT_EVENTS message + * * Revision 1.1 2008/03/26 08:44:13 vfrolov * Redesigned for using plugins *************** *** 66,71 **** inX(0), inDsr(0), ! intervalTimeout(0), ! events(0) { } --- 69,73 ---- inX(0), inDsr(0), ! intervalTimeout(0) { } *************** *** 141,182 **** } - BOOL ComParams::SetEvents(const char *pEvents) - { - char *pTmp = _strdup(pEvents); - - if (!pTmp) { - cerr << "No enough memory." << endl; - exit(2); - } - - events = 0; - - char *pSave; - - for (char *pName = STRTOK_R(pTmp, ",", &pSave) ; - pName ; - pName = STRTOK_R(NULL, ",", &pSave)) - { - BOOL found = FALSE; - - for (int i = 0 ; i < sizeof(event_names)/sizeof(event_names[0]) ; i++) { - if (_stricmp(pName, event_names[i].pName) == 0) { - events |= event_names[i].val; - found = TRUE; - break; - } - } - - if (!found && _stricmp(pName, "none") != 0) { - free(pTmp); - return FALSE; - } - } - - free(pTmp); - - return TRUE; - } - BOOL ComParams::SetFlag(const char *pFlagStr, int *pFlag) { --- 143,146 ---- *************** *** 255,281 **** } - string ComParams::EventsStr(DWORD events) - { - if (events > 0) { - stringstream buf; - BOOL first = TRUE; - - for (int i = 0 ; i < sizeof(event_names)/sizeof(event_names[0]) ; i++) { - if ((events & event_names[i].val) != 0) { - if (first) - first = FALSE; - else - buf << ","; - - buf << event_names[i].pName; - } - } - - return buf.str(); - } - - return "none"; - } - string ComParams::FlagStr(int flag) { --- 219,222 ---- *************** *** 313,321 **** } - const char *ComParams::EventsLst() - { - return "<E1>[,<E2>...], where <En> is cts, dsr, dcd, ring, break, err or none"; - } - const char *ComParams::FlagLst() { --- 254,257 ---- Index: port.cpp =================================================================== RCS file: /cvsroot/com0com/hub4com/plugins/serial/port.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** port.cpp 28 Mar 2008 15:55:09 -0000 1.2 --- port.cpp 7 Apr 2008 12:28:03 -0000 1.3 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.3 2008/04/07 12:28:03 vfrolov + * Replaced --rt-events option by SET_RT_EVENTS message + * * Revision 1.2 2008/03/28 15:55:09 vfrolov * Fixed help *************** *** 89,108 **** << " --ito=<t> - set read interval timeout to <t> (" << ComParams().IntervalTimeoutStr() << " by default)," << endl << " where <t> is " << ComParams::IntervalTimeoutLst() << "." << endl - << " --rt-events=<LstEv> - set events that should be handled in real-time to" << endl - << " <LstEv> (" << ComParams().EventsStr() << " by default)." << endl << endl << " The value c[urrent] above means to use current COM port settings." << endl - << " The syntax of <LstEv> above is" << endl - << " " << ComParams::EventsLst() << "." << endl << endl << "Output data stream description:" << endl ! << " LINE_DATA(<data>) - write <data> to serial port." << endl << " COM_FUNCTION(<function>) - direct serial port to perform <function>." << endl << endl << "Input data stream description:" << endl ! << " LINE_DATA(<data>) - readed <data> from serial port." << endl ! << " CONNECT(TRUE) - serial port started." << endl ! << " MODEM_STATUS(<value>) - modem control register changed to <value>." << endl ! << " COM_ERRORS(<mask>) - occured communications errors indicated in <mask>." << endl << endl << "Examples:" << endl --- 92,109 ---- << " --ito=<t> - set read interval timeout to <t> (" << ComParams().IntervalTimeoutStr() << " by default)," << endl << " where <t> is " << ComParams::IntervalTimeoutLst() << "." << endl << endl << " The value c[urrent] above means to use current COM port settings." << endl << endl << "Output data stream description:" << endl ! << " LINE_DATA(<data>) - write <data> to serial port." << endl << " COM_FUNCTION(<function>) - direct serial port to perform <function>." << endl + << " SET_RT_EVENTS(<mask>) - direct serial port to monitor <mask> real-time" << endl + << " events." << endl << endl << "Input data stream description:" << endl ! << " LINE_DATA(<data>) - readed <data> from serial port." << endl ! << " CONNECT(TRUE) - serial port started." << endl ! << " MODEM_STATUS(<value>) - modem control register changed to <value>." << endl ! << " COM_ERRORS(<mask>) - occured communications errors indicated in <mask>." << endl << endl << "Examples:" << endl *************** *** 197,206 **** exit(1); } - } else - if ((pParam = GetParam(pArg, "--rt-events=")) != NULL) { - if (!comParams.SetEvents(pParam)) { - cerr << "Unknown events in " << pArg << endl; - exit(1); - } } else { return FALSE; --- 198,201 ---- Index: comio.h =================================================================== RCS file: /cvsroot/com0com/hub4com/plugins/serial/comio.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** comio.h 26 Mar 2008 08:43:50 -0000 1.1 --- comio.h 7 Apr 2008 12:28:03 -0000 1.2 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.2 2008/04/07 12:28:03 vfrolov + * Replaced --rt-events option by SET_RT_EVENTS message + * * Revision 1.1 2008/03/26 08:43:50 vfrolov * Redesigned for using plugins *************** *** 43,46 **** --- 46,50 ---- /////////////////////////////////////////////////////////////// extern HANDLE OpenComPort(const char *pPath, const ComParams &comParams); + extern BOOL SetComEvents(HANDLE handle, DWORD *events); /////////////////////////////////////////////////////////////// class ReadOverlapped : private OVERLAPPED Index: comparams.h =================================================================== RCS file: /cvsroot/com0com/hub4com/plugins/serial/comparams.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** comparams.h 26 Mar 2008 08:44:13 -0000 1.1 --- comparams.h 7 Apr 2008 12:28:03 -0000 1.2 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.2 2008/04/07 12:28:03 vfrolov + * Replaced --rt-events option by SET_RT_EVENTS message + * * Revision 1.1 2008/03/26 08:44:13 vfrolov * Redesigned for using plugins *************** *** 57,61 **** BOOL SetInDsr(const char *pInDsr) { return SetFlag(pInDsr, &inDsr); } BOOL SetIntervalTimeout(const char *pIntervalTimeout); - BOOL SetEvents(const char *pEvents); static string BaudRateStr(long baudRate); --- 60,63 ---- *************** *** 69,73 **** static string InDsrStr(int inDsr) { return FlagStr(inDsr); } static string IntervalTimeoutStr(long intervalTimeout); - static string EventsStr(DWORD events); string BaudRateStr() const { return BaudRateStr(baudRate); } --- 71,74 ---- *************** *** 81,85 **** string InDsrStr() const { return InDsrStr(inDsr); } string IntervalTimeoutStr() const { return IntervalTimeoutStr(intervalTimeout); } - string EventsStr() const { return EventsStr(events); } static const char *BaudRateLst(); --- 82,85 ---- *************** *** 93,97 **** static const char *InDsrLst() { return FlagLst(); } static const char *IntervalTimeoutLst(); - static const char *EventsLst(); long BaudRate() const { return baudRate; } --- 93,96 ---- *************** *** 105,109 **** int InDsr() const { return inDsr; } long IntervalTimeout() const { return intervalTimeout; } - DWORD Events() const { return events; } private: --- 104,107 ---- *************** *** 122,126 **** int inDsr; long intervalTimeout; - DWORD events; }; /////////////////////////////////////////////////////////////// --- 120,123 ---- Index: comport.h =================================================================== RCS file: /cvsroot/com0com/hub4com/plugins/serial/comport.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** comport.h 26 Mar 2008 08:44:34 -0000 1.1 --- comport.h 7 Apr 2008 12:28:03 -0000 1.2 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.2 2008/04/07 12:28:03 vfrolov + * Replaced --rt-events option by SET_RT_EVENTS message + * * Revision 1.1 2008/03/26 08:44:34 vfrolov * Redesigned for using plugins *************** *** 79,82 **** --- 82,86 ---- int countXoff; BOOL filterX; + DWORD events; DWORD writeQueueLimit; Index: comio.cpp =================================================================== RCS file: /cvsroot/com0com/hub4com/plugins/serial/comio.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** comio.cpp 26 Mar 2008 08:43:50 -0000 1.1 --- comio.cpp 7 Apr 2008 12:28:02 -0000 1.2 *************** *** 20,23 **** --- 20,26 ---- * * $Log$ + * Revision 1.2 2008/04/07 12:28:02 vfrolov + * Replaced --rt-events option by SET_RT_EVENTS message + * * Revision 1.1 2008/03/26 08:43:50 vfrolov * Redesigned for using plugins *************** *** 62,66 **** dcb->DCBlength = sizeof(*dcb); ! if (!GetCommState(handle, dcb)) { TraceError(GetLastError(), "GetCommState()"); return FALSE; --- 65,69 ---- dcb->DCBlength = sizeof(*dcb); ! if (!::GetCommState(handle, dcb)) { TraceError(GetLastError(), "GetCommState()"); return FALSE; *************** *** 71,80 **** static BOOL mySetCommState(HANDLE handle, DCB *dcb) { ! if (!SetCommState(handle, dcb)) { TraceError(GetLastError(), "SetCommState()"); return FALSE; } return TRUE; } /////////////////////////////////////////////////////////////// HANDLE OpenComPort(const char *pPath, const ComParams &comParams) --- 74,122 ---- static BOOL mySetCommState(HANDLE handle, DCB *dcb) { ! if (!::SetCommState(handle, dcb)) { TraceError(GetLastError(), "SetCommState()"); + myGetCommState(handle, dcb); + return FALSE; + } + return myGetCommState(handle, dcb); + } + /////////////////////////////////////////////////////////////// + static BOOL myGetCommTimeouts(HANDLE handle, COMMTIMEOUTS *timeouts) + { + if (!::GetCommTimeouts(handle, timeouts)) { + TraceError(GetLastError(), "GetCommTimeouts()"); return FALSE; } return TRUE; } + + static BOOL mySetCommTimeouts(HANDLE handle, COMMTIMEOUTS *timeouts) + { + if (!::SetCommTimeouts(handle, timeouts)) { + TraceError(GetLastError(), "SetCommTimeouts()"); + myGetCommTimeouts(handle, timeouts); + return FALSE; + } + return myGetCommTimeouts(handle, timeouts); + } + /////////////////////////////////////////////////////////////// + static BOOL myGetCommMask(HANDLE handle, DWORD *events) + { + if (!::GetCommMask(handle, events)) { + TraceError(GetLastError(), "GetCommMask()"); + return FALSE; + } + return TRUE; + } + + BOOL SetComEvents(HANDLE handle, DWORD *events) + { + if (!::SetCommMask(handle, *events)) { + TraceError(GetLastError(), "SetCommMask()"); + myGetCommMask(handle, events); + return FALSE; + } + return myGetCommMask(handle, events); + } /////////////////////////////////////////////////////////////// HANDLE OpenComPort(const char *pPath, const ComParams &comParams) *************** *** 142,147 **** COMMTIMEOUTS timeouts; ! if (!GetCommTimeouts(handle, &timeouts)) { ! TraceError(GetLastError(), "OpenComPort(): GetCommTimeouts()"); CloseHandle(handle); return INVALID_HANDLE_VALUE; --- 184,188 ---- COMMTIMEOUTS timeouts; ! if (!myGetCommTimeouts(handle, &timeouts)) { CloseHandle(handle); return INVALID_HANDLE_VALUE; *************** *** 161,172 **** timeouts.WriteTotalTimeoutConstant = 0; ! if (!SetCommTimeouts(handle, &timeouts)) { ! TraceError(GetLastError(), "OpenComPort(): SetCommTimeouts()"); ! CloseHandle(handle); ! return INVALID_HANDLE_VALUE; ! } ! ! if (!::SetCommMask(handle, comParams.Events())) { ! TraceError(GetLastError(), "OpenComPort(): SetCommMask()"); CloseHandle(handle); return INVALID_HANDLE_VALUE; --- 202,206 ---- timeouts.WriteTotalTimeoutConstant = 0; ! if (!mySetCommTimeouts(handle, &timeouts)) { CloseHandle(handle); return INVALID_HANDLE_VALUE; *************** *** 184,189 **** << ", ix=" << ComParams::InXStr(dcb.fInX) << ", idsr=" << ComParams::InDsrStr(dcb.fDsrSensitivity) ! << ", ito=" << comParams.IntervalTimeoutStr() ! << ", rt-events=" << comParams.EventsStr() << ") - OK" << endl; return handle; --- 218,222 ---- << ", ix=" << ComParams::InXStr(dcb.fInX) << ", idsr=" << ComParams::InDsrStr(dcb.fDsrSensitivity) ! << ", ito=" << ComParams::IntervalTimeoutStr(timeouts.ReadIntervalTimeout) << ") - OK" << endl; return handle; |