[Com0com-cvs] hub4com/plugins/serial comio.cpp, 1.2, 1.3 comio.h, 1.2, 1.3 comport.cpp, 1.3, 1.4 co
The virtual serial port driver for Windows.
Brought to you by:
vfrolov
From: Vyacheslav F. <vf...@us...> - 2008-08-11 07:15:39
|
Update of /cvsroot/com0com/hub4com/plugins/serial In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv8775/plugins/serial Modified Files: comio.cpp comio.h comport.cpp comport.h Log Message: Replaced HUB_MSG_TYPE_COM_FUNCTION HUB_MSG_TYPE_INIT_LSR_MASK HUB_MSG_TYPE_INIT_MST_MASK by HUB_MSG_TYPE_SET_PIN_STATE HUB_MSG_TYPE_GET_OPTIONS HUB_MSG_TYPE_SET_OPTIONS Index: comport.cpp =================================================================== RCS file: /cvsroot/com0com/hub4com/plugins/serial/comport.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** comport.cpp 11 Apr 2008 14:48:42 -0000 1.3 --- comport.cpp 11 Aug 2008 07:15:34 -0000 1.4 *************** *** 20,23 **** --- 20,33 ---- * * $Log$ + * Revision 1.4 2008/08/11 07:15:34 vfrolov + * Replaced + * HUB_MSG_TYPE_COM_FUNCTION + * HUB_MSG_TYPE_INIT_LSR_MASK + * HUB_MSG_TYPE_INIT_MST_MASK + * by + * HUB_MSG_TYPE_SET_PIN_STATE + * HUB_MSG_TYPE_GET_OPTIONS + * HUB_MSG_TYPE_SET_OPTIONS + * * Revision 1.3 2008/04/11 14:48:42 vfrolov * Replaced SET_RT_EVENTS by INIT_LSR_MASK and INIT_MST_MASK *************** *** 62,65 **** --- 72,76 ---- filterX(FALSE), events(0), + maskOutPins(0), writeQueueLimit(256), writeQueued(0), *************** *** 94,135 **** HUB_MSG msg; - DWORD mask; - - mask = 0; - msg.type = HUB_MSG_TYPE_INIT_LSR_MASK; - msg.u.pVal = &mask; - pOnRead(hHub, hMasterPort, &msg); - maskLsr = (BYTE)mask; ! mask = 0; ! msg.type = HUB_MSG_TYPE_INIT_MST_MASK; ! msg.u.pVal = &mask; pOnRead(hHub, hMasterPort, &msg); ! maskMst = (BYTE)mask; ! ! CheckComEvents(DWORD(-1)); ! if (maskLsr || maskMst) { ! if ((maskMst & MODEM_STATUS_CTS) != 0) events |= EV_CTS; ! if ((maskMst & MODEM_STATUS_DSR) != 0) events |= EV_DSR; ! if ((maskMst & MODEM_STATUS_DCD) != 0) events |= EV_RLSD; ! if ((maskMst & MODEM_STATUS_RI) != 0) events |= EV_RING; ! if (maskMst & ~(MODEM_STATUS_CTS|MODEM_STATUS_DSR|MODEM_STATUS_DCD|MODEM_STATUS_RI)) { ! cout << "WARNING: Changing of MODEM STATUS bits 0x" << hex ! << (unsigned)(maskMst & ~(MODEM_STATUS_CTS|MODEM_STATUS_DSR|MODEM_STATUS_DCD|MODEM_STATUS_RI)) << dec << " will be ignored" << endl; } ! if (maskLsr) { ! cout << "WARNING: Changing of LINE STATUS bits 0x" << hex ! << (unsigned)maskLsr << dec << " will be ignored" << endl; } --- 105,139 ---- HUB_MSG msg; ! DWORD options = 0; ! msg.type = HUB_MSG_TYPE_GET_OPTIONS; ! msg.u.pv.pVal = &options; ! msg.u.pv.val = 0xFFFFFFFF; pOnRead(hHub, hMasterPort, &msg); ! optsLsr = GO_O2V_LINE_STATUS(options); ! optsMst = GO_O2V_MODEM_STATUS(options); ! if (optsLsr || optsMst) { ! if ((optsMst & MODEM_STATUS_CTS) != 0) events |= EV_CTS; ! if ((optsMst & MODEM_STATUS_DSR) != 0) events |= EV_DSR; ! if ((optsMst & MODEM_STATUS_DCD) != 0) events |= EV_RLSD; ! if ((optsMst & MODEM_STATUS_RI) != 0) events |= EV_RING; ! if (optsMst & ~(MODEM_STATUS_CTS|MODEM_STATUS_DSR|MODEM_STATUS_DCD|MODEM_STATUS_RI)) { ! cout << name << " WARNING: Changing of MODEM STATUS bit(s) 0x" << hex ! << (unsigned)(optsMst & ~(MODEM_STATUS_CTS|MODEM_STATUS_DSR|MODEM_STATUS_DCD|MODEM_STATUS_RI)) << dec << " will be ignored" << endl; } ! if (optsLsr) { ! cout << name << " WARNING: Changing of LINE STATUS bit(s) 0x" << hex ! << (unsigned)optsLsr << dec << " will be ignored" << endl; } *************** *** 142,147 **** --- 146,155 ---- if (!StartWaitCommEvent()) return FALSE; + + cout << name << " Event(s) 0x" << hex << events << dec << " will be monitired" << endl; } + CheckComEvents(DWORD(-1)); + if (!StartRead()) return FALSE; *************** *** 176,180 **** countReadOverlapped++; ! //cout << "Started Read " << name << " " << countReadOverlapped << endl; return TRUE; --- 184,188 ---- countReadOverlapped++; ! //cout << name << " Started Read " << countReadOverlapped << endl; return TRUE; *************** *** 244,256 **** writeQueued += len; ! //cout << "Started Write " << name << " " << len << " " << writeQueued << endl; } else ! if (pMsg->type == HUB_MSG_TYPE_COM_FUNCTION) { if (handle == INVALID_HANDLE_VALUE) return FALSE; ! if (!::EscapeCommFunction(handle, pMsg->u.val)) return FALSE; } --- 252,314 ---- writeQueued += len; ! //cout << name << " Started Write " << len << " " << writeQueued << endl; } else ! if (pMsg->type == HUB_MSG_TYPE_SET_PIN_STATE) { if (handle == INVALID_HANDLE_VALUE) return FALSE; ! cout << name << " SET_PIN_STATE 0x" << hex << pMsg->u.val << dec << endl; ! ! WORD mask = (SPS_MASK2PIN(pMsg->u.val) & maskOutPins); ! ! if (mask & PIN_STATE_RTS) { ! if (!CommFunction(handle, (pMsg->u.val & PIN_STATE_RTS) ? SETRTS : CLRRTS)) ! cerr << name << " WARNING! can't change RTS state" << endl; ! } ! if (mask & PIN_STATE_DTR) { ! if (!CommFunction(handle, (pMsg->u.val & PIN_STATE_DTR) ? SETDTR : CLRDTR)) ! cerr << name << " WARNING! can't change DTR state" << endl; ! } ! if (mask & PIN_STATE_OUT1) { ! cerr << name << " WARNING! can't change OUT1 state" << endl; ! } ! if (mask & PIN_STATE_OUT2) { ! cerr << name << " WARNING! can't change OUT2 state" << endl; ! } ! if (mask & PIN_STATE_BREAK) { ! if (!CommFunction(handle, (pMsg->u.val & PIN_STATE_BREAK) ? SETBREAK : CLRBREAK)) ! cerr << name << " WARNING! can't change BREAK state" << endl; ! } ! } ! else ! if (pMsg->type == HUB_MSG_TYPE_SET_OPTIONS) { ! if (handle == INVALID_HANDLE_VALUE) return FALSE; + + BYTE addedPins = (~maskOutPins & SO_O2V_PIN_STATE(pMsg->u.val)); + + if (addedPins & PIN_STATE_RTS) { + if (!SetManualRtsControl(handle)) { + addedPins &= ~PIN_STATE_RTS; + cerr << name << " WARNING! can't set manual RTS state mode" << endl; + } + } + if (addedPins & PIN_STATE_DTR) { + if (!SetManualDtrControl(handle)) { + addedPins &= ~PIN_STATE_DTR; + cerr << name << " WARNING! can't set manual DTR state mode" << endl; + } + } + if (addedPins & PIN_STATE_OUT1) { + addedPins &= ~PIN_STATE_OUT1; + cerr << name << " WARNING! can't set manual OUT1 state mode" << endl; + } + if (addedPins & PIN_STATE_OUT2) { + addedPins &= ~PIN_STATE_OUT2; + cerr << name << " WARNING! can't set manual OUT2 state mode" << endl; + } + + maskOutPins |= addedPins; } *************** *** 280,284 **** countWaitCommEventOverlapped++; ! //cout << "Started WaitCommEvent " << name << " " << countReadOverlapped // << " " << hex << events << dec << endl; --- 338,342 ---- countWaitCommEventOverlapped++; ! //cout << name << " Started WaitCommEvent " << countReadOverlapped // << " " << hex << events << dec << endl; *************** *** 313,317 **** countReadOverlapped--; ! //cout << "Stopped Read " << name << " " << countReadOverlapped << endl; } } --- 371,375 ---- countReadOverlapped--; ! //cout << name << " Stopped Read " << countReadOverlapped << endl; } } *************** *** 325,329 **** countWaitCommEventOverlapped--; ! //cout << "Stopped WaitCommEvent " << name << " " << countWaitCommEventOverlapped << endl; } } --- 383,387 ---- countWaitCommEventOverlapped--; ! //cout << name << " Stopped WaitCommEvent " << countWaitCommEventOverlapped << endl; } } Index: comport.h =================================================================== RCS file: /cvsroot/com0com/hub4com/plugins/serial/comport.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** comport.h 11 Apr 2008 14:48:42 -0000 1.3 --- comport.h 11 Aug 2008 07:15:34 -0000 1.4 *************** *** 20,23 **** --- 20,33 ---- * * $Log$ + * Revision 1.4 2008/08/11 07:15:34 vfrolov + * Replaced + * HUB_MSG_TYPE_COM_FUNCTION + * HUB_MSG_TYPE_INIT_LSR_MASK + * HUB_MSG_TYPE_INIT_MST_MASK + * by + * HUB_MSG_TYPE_SET_PIN_STATE + * HUB_MSG_TYPE_GET_OPTIONS + * HUB_MSG_TYPE_SET_OPTIONS + * * Revision 1.3 2008/04/11 14:48:42 vfrolov * Replaced SET_RT_EVENTS by INIT_LSR_MASK and INIT_MST_MASK *************** *** 87,92 **** BOOL filterX; DWORD events; ! BYTE maskLsr; ! BYTE maskMst; DWORD writeQueueLimit; --- 97,103 ---- BOOL filterX; DWORD events; ! BYTE maskOutPins; ! BYTE optsLsr; ! BYTE optsMst; DWORD writeQueueLimit; Index: comio.h =================================================================== RCS file: /cvsroot/com0com/hub4com/plugins/serial/comio.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** comio.h 7 Apr 2008 12:28:03 -0000 1.2 --- comio.h 11 Aug 2008 07:15:34 -0000 1.3 *************** *** 20,23 **** --- 20,33 ---- * * $Log$ + * Revision 1.3 2008/08/11 07:15:34 vfrolov + * Replaced + * HUB_MSG_TYPE_COM_FUNCTION + * HUB_MSG_TYPE_INIT_LSR_MASK + * HUB_MSG_TYPE_INIT_MST_MASK + * by + * HUB_MSG_TYPE_SET_PIN_STATE + * HUB_MSG_TYPE_GET_OPTIONS + * HUB_MSG_TYPE_SET_OPTIONS + * * Revision 1.2 2008/04/07 12:28:03 vfrolov * Replaced --rt-events option by SET_RT_EVENTS message *************** *** 46,50 **** --- 56,63 ---- /////////////////////////////////////////////////////////////// extern HANDLE OpenComPort(const char *pPath, const ComParams &comParams); + extern BOOL SetManualRtsControl(HANDLE handle); + extern BOOL SetManualDtrControl(HANDLE handle); extern BOOL SetComEvents(HANDLE handle, DWORD *events); + extern BOOL CommFunction(HANDLE handle, DWORD func); /////////////////////////////////////////////////////////////// class ReadOverlapped : private OVERLAPPED Index: comio.cpp =================================================================== RCS file: /cvsroot/com0com/hub4com/plugins/serial/comio.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** comio.cpp 7 Apr 2008 12:28:02 -0000 1.2 --- comio.cpp 11 Aug 2008 07:15:33 -0000 1.3 *************** *** 20,23 **** --- 20,33 ---- * * $Log$ + * Revision 1.3 2008/08/11 07:15:33 vfrolov + * Replaced + * HUB_MSG_TYPE_COM_FUNCTION + * HUB_MSG_TYPE_INIT_LSR_MASK + * HUB_MSG_TYPE_INIT_MST_MASK + * by + * HUB_MSG_TYPE_SET_PIN_STATE + * HUB_MSG_TYPE_GET_OPTIONS + * HUB_MSG_TYPE_SET_OPTIONS + * * Revision 1.2 2008/04/07 12:28:02 vfrolov * Replaced --rt-events option by SET_RT_EVENTS message *************** *** 120,123 **** --- 130,142 ---- } /////////////////////////////////////////////////////////////// + BOOL CommFunction(HANDLE handle, DWORD func) + { + if (!::EscapeCommFunction(handle, func)) { + TraceError(GetLastError(), "EscapeCommFunction(%lu)", (long)func); + return FALSE; + } + return TRUE; + } + /////////////////////////////////////////////////////////////// HANDLE OpenComPort(const char *pPath, const ComParams &comParams) { *************** *** 223,226 **** --- 242,269 ---- } /////////////////////////////////////////////////////////////// + BOOL SetManualRtsControl(HANDLE handle) + { + DCB dcb; + + if (!myGetCommState(handle, &dcb)) + return FALSE; + + dcb.fRtsControl = RTS_CONTROL_DISABLE; + + return mySetCommState(handle, &dcb); + } + + BOOL SetManualDtrControl(HANDLE handle) + { + DCB dcb; + + if (!myGetCommState(handle, &dcb)) + return FALSE; + + dcb.fDtrControl = DTR_CONTROL_DISABLE; + + return mySetCommState(handle, &dcb); + } + /////////////////////////////////////////////////////////////// WriteOverlapped::WriteOverlapped(ComPort &_port, BYTE *_pBuf, DWORD _len) : port(_port), |