Mercurial > flash_v2
comparison host/tools/Utils/common/eCosSerial.h @ 82:6736c52df507 ecos-sw-2000-04-14
Merge from eCos master repository on 2000-04-14-13:35:46-BST
| author | jlarmour |
|---|---|
| date | Tue, 18 Apr 2000 21:51:55 +0000 |
| parents | |
| children | 6ed91473a1cd |
comparison
equal
deleted
inserted
replaced
| 81:89fef2181d7d | 82:6736c52df507 |
|---|---|
| 1 //####COPYRIGHTBEGIN#### | |
| 2 // | |
| 3 // ---------------------------------------------------------------------------- | |
| 4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. | |
| 5 // | |
| 6 // This program is part of the eCos host tools. | |
| 7 // | |
| 8 // This program is free software; you can redistribute it and/or modify it | |
| 9 // under the terms of the GNU General Public License as published by the Free | |
| 10 // Software Foundation; either version 2 of the License, or (at your option) | |
| 11 // any later version. | |
| 12 // | |
| 13 // This program is distributed in the hope that it will be useful, but WITHOUT | |
| 14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
| 16 // more details. | |
| 17 // | |
| 18 // You should have received a copy of the GNU General Public License along with | |
| 19 // this program; if not, write to the Free Software Foundation, Inc., | |
| 20 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
| 21 // | |
| 22 // ---------------------------------------------------------------------------- | |
| 23 // | |
| 24 //####COPYRIGHTEND#### | |
| 25 //================================================================= | |
| 26 // | |
| 27 // eCosSerial.h | |
| 28 // | |
| 29 // Serial test class | |
| 30 // | |
| 31 //================================================================= | |
| 32 //================================================================= | |
| 33 //#####DESCRIPTIONBEGIN#### | |
| 34 // | |
| 35 // Author(s): sdf | |
| 36 // Contributors: sdf | |
| 37 // Date: 1999-04-01 | |
| 38 // Description: This class abstracts the serial port | |
| 39 // Usage: | |
| 40 // | |
| 41 // | |
| 42 //####DESCRIPTIONEND#### | |
| 43 | |
| 44 #ifndef _CECOSSERIAL_H | |
| 45 #define _CECOSSERIAL_H | |
| 46 #include "eCosStd.h" | |
| 47 #include "eCosSocket.h" | |
| 48 #include "Collections.h" | |
| 49 //================================================================= | |
| 50 // This class is a host-independent interface to a serial port | |
| 51 //================================================================= | |
| 52 class CeCosSerial { | |
| 53 friend CeCosSocket::SSReadResult CeCosSocket::SSRead (CeCosSerial &serial,CeCosSocket &socket,void *pBuf,unsigned int nSize,unsigned int &nRead,bool *pbStop); | |
| 54 | |
| 55 public: | |
| 56 enum StopBitsType { ONE_STOP_BIT, ONE_POINT_FIVE_STOP_BITS, TWO_STOP_BITS }; | |
| 57 CeCosSerial(LPCTSTR pszPort,int nBaud); // ctor and open all in one go | |
| 58 CeCosSerial(); // Call Open() later | |
| 59 virtual ~CeCosSerial(); | |
| 60 | |
| 61 // Open the port with given baud rate. Result indicates how successful we've been | |
| 62 bool Open(LPCTSTR pszPort,int nBaud); | |
| 63 | |
| 64 // Set various line characteristics. This can be done with the line open or closed. | |
| 65 // In each case the "bApplySettingsNow" argument indicates whether to perform the action now, | |
| 66 // or to hold off until a call of ApplySettings(). | |
| 67 | |
| 68 bool SetBaud(unsigned int nBaud,bool bApplySettingsNow=true); | |
| 69 bool SetParity(bool bParityOn,bool bApplySettingsNow=true); | |
| 70 bool SetDataBits(int n,bool bApplySettingsNow=true); | |
| 71 bool SetStopBits(StopBitsType n,bool bApplySettingsNow=true); | |
| 72 bool SetReadTimeOuts(int nTotal,int nBetweenChars,bool bApplySettingsNow=true); // Times are in mSec | |
| 73 bool SetWriteTimeOuts(int nTotal,int nBetweenChars,bool bApplySettingsNow=true); // Times are in mSec | |
| 74 | |
| 75 bool ApplySettings(); | |
| 76 | |
| 77 // Query the settings: | |
| 78 int GetParity() const { return m_bParity; } | |
| 79 int GetDataBits() const { return m_nDataBits; } | |
| 80 StopBitsType GetStopBits() const { return m_nStopBits; } | |
| 81 unsigned int GetBaud() const { return m_nBaud; } | |
| 82 bool GetReadTimeOuts(int &nTotal,int &nBetweenChars) const {nTotal=m_nTotalReadTimeout; nBetweenChars=m_nInterCharReadTimeout; return true; }// mSec | |
| 83 bool GetWriteTimeOuts(int &nTotal,int &nBetweenChars) const {nTotal=m_nTotalWriteTimeout; nBetweenChars=m_nInterCharWriteTimeout; return true; }// mSec | |
| 84 bool GetBlockingReads() const { return m_bBlockingReads; } | |
| 85 bool Close(); | |
| 86 | |
| 87 // Clear the serial buffer: | |
| 88 bool Flush (void); | |
| 89 | |
| 90 // Use to test success after opening with the ctor: | |
| 91 bool Ok() const { return 0!=m_pHandle; } | |
| 92 | |
| 93 // Will read up to the length provided: | |
| 94 bool Read (void *pBuf,unsigned int nSize,unsigned int &nRead); | |
| 95 bool Write(void *pBuf,unsigned int nSize,unsigned int &nWritten); | |
| 96 | |
| 97 // Use in the event of an error that needs to be cleared before the next operation: | |
| 98 bool ClearError(); | |
| 99 | |
| 100 // Set blocking/non-blocking | |
| 101 bool SetBlockingReads(bool b,bool bApplySettingsNow=true); | |
| 102 | |
| 103 // Return last error | |
| 104 int Error() const { return m_nErr; } | |
| 105 | |
| 106 // Return last error, translated to a string | |
| 107 String ErrString() const; | |
| 108 | |
| 109 protected: | |
| 110 // The last error: | |
| 111 int m_nErr | |
| 112 ; | |
| 113 // Remember the error | |
| 114 void SaveError() { | |
| 115 #ifdef _WIN32 | |
| 116 m_nErr=WSAGetLastError(); | |
| 117 #else // UNIX | |
| 118 m_nErr=errno; | |
| 119 #endif | |
| 120 } | |
| 121 | |
| 122 // Line characteristics: | |
| 123 void *m_pHandle; | |
| 124 int m_nDataBits; | |
| 125 StopBitsType m_nStopBits; | |
| 126 bool m_bParity; | |
| 127 unsigned int m_nBaud; | |
| 128 int m_nTotalReadTimeout,m_nTotalWriteTimeout; | |
| 129 int m_nInterCharReadTimeout,m_nInterCharWriteTimeout; | |
| 130 bool m_bBlockingReads; | |
| 131 String m_strPort; | |
| 132 }; | |
| 133 #endif |
