comparison host/tools/ecostest/common/eCosTestSerial.h @ 76:435cced73e2f ecos-v1_3_1-release

eCos v1.3.1 merged from eCos master repository on 2000-03-27-23:22:51-BST
author jlarmour
date Tue, 28 Mar 2000 14:10:45 +0000
parents
children
comparison
equal deleted inserted replaced
75:41bf073c0c32 76:435cced73e2f
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 // eCosTestSerial.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 for use in the testing infrastructure
39 // Usage:
40 //
41 //
42 //####DESCRIPTIONEND####
43
44 #ifndef _CECOSSERIAL_H
45 #define _CECOSSERIAL_H
46 #include "eCosStd.h"
47 #include "eCosTestSocket.h"
48 #include "Collections.h"
49
50 class CeCosTestSerial {
51 friend int CeCosTestSocket::SSRead (CeCosTestSerial &serial,CeCosTestSocket &socket,void *pBuf,unsigned int nSize,unsigned int &nRead,bool *pbStop);
52
53 public:
54 enum StopBitsType { ONE_STOP_BIT, ONE_POINT_FIVE_STOP_BITS, TWO_STOP_BITS };
55 CeCosTestSerial(LPCTSTR pszPort,int nBaud); // ctor and open all in one go
56 CeCosTestSerial(); // Call Open() later
57 virtual ~CeCosTestSerial(); // Call Open() later
58
59 bool Open(LPCTSTR pszPort,int nBaud);
60
61 // Set various line characteristics. This can be done with the line open or closed.
62 bool SetBaud(unsigned int nBaud,bool bApplySettingsNow=true);
63 bool SetParity(bool bParityOn,bool bApplySettingsNow=true);
64 bool SetDataBits(int n,bool bApplySettingsNow=true);
65 bool SetStopBits(StopBitsType n,bool bApplySettingsNow=true);
66 bool SetReadTimeOuts(int nTotal,int nBetweenChars,bool bApplySettingsNow=true); // mSec
67 bool SetWriteTimeOuts(int nTotal,int nBetweenChars,bool bApplySettingsNow=true); // mSec
68
69 bool ApplySettings();
70
71 // Get them:
72 int GetParity() const { return m_bParity; }
73 int GetDataBits() const { return m_nDataBits; }
74 StopBitsType GetStopBits() const { return m_nStopBits; }
75 unsigned int GetBaud() const { return m_nBaud; }
76 bool GetReadTimeOuts(int &nTotal,int &nBetweenChars) const {nTotal=m_nTotalReadTimeout; nBetweenChars=m_nInterCharReadTimeout; return true; }// mSec
77 bool GetWriteTimeOuts(int &nTotal,int &nBetweenChars) const {nTotal=m_nTotalWriteTimeout; nBetweenChars=m_nInterCharWriteTimeout; return true; }// mSec
78 bool GetBlockingReads() const { return m_bBlockingReads; }
79 bool Close();
80
81 bool Flush (void);
82
83 // Use to test success after open ctor
84 bool Ok() { return 0!=m_pHandle; }
85
86 // Will read up to the length provided:
87 bool Read (void *pBuf,unsigned int nSize,unsigned int &nRead);
88 bool Write(void *pBuf,unsigned int nSize,unsigned int &nWritten);
89
90 //Removed, as dangerous when using UNICODE:
91 //bool Read (String &str);
92 //bool Write(const String &str);
93
94 // Use in the event of an error that needs to be cleared before the next operation:
95 bool ClearError();
96
97 bool SetBlockingReads(bool b,bool bApplySettingsNow=true);
98
99 int Error() { return m_nErr; }
100 // Return last socket error, translated to a string
101 String ErrString();
102
103 protected:
104 int m_nErr;
105 void SaveError() {
106 #ifdef _WIN32
107 m_nErr=WSAGetLastError();
108 #else // UNIX
109 m_nErr=errno;
110 #endif
111 }
112
113 void *m_pHandle;
114 int m_nDataBits;
115 StopBitsType m_nStopBits;
116 bool m_bParity;
117 unsigned int m_nBaud;
118 int m_nTotalReadTimeout,m_nTotalWriteTimeout;
119 int m_nInterCharReadTimeout,m_nInterCharWriteTimeout;
120 bool m_bBlockingReads;
121 String m_strPort;
122 };
123 #endif