Project

General

Profile

Support Request #14449 » serialdevice.h

hidden, 2021-06-07 08:19

 
1
/**
2
*
3
* Class for COM port communication.
4
*
5
* @file
6
 * Copyright © Audi Electronics Venture GmbH. All rights reserved
7
*
8
 * $Author: ELAMIHA $
9
 * $Date: 2014-05-07 19:06:16 +0200 (Wed, 07 May 2014) $
10
 * $Revision: 633 $
11
*
12
* @remarks
13
*
14
*/
15
#ifndef _UTILS_SERIALDEVICE_HEADER
16
#define _UTILS_SERIALDEVICE_HEADER
17

    
18
namespace A_UTILS_NS
19
{
20

    
21
/**
22
 * Class for accessing serial devices.
23
 */
24
class cSerialDevice /* : public cCharacterDevice */
25
{
26
    A_UTILS_D(cSerialDevice)
27

    
28
    protected:
29
#ifdef WIN32
30
        tHandle     m_hDevice;  //!< Device handle
31
#else
32
        tInt        m_nDev;     //!< Device handle
33
#endif
34

    
35
    public:
36
        enum
37
        {
38
            SER_EVENPARITY,
39
            SER_MARKPARITY,
40
            SER_NOPARITY,
41
            SER_ODDPARITY,
42
            SER_SPACEPARITY
43
        };
44

    
45
        enum
46
        {
47
            SER_ONESTOPBIT,
48
            SER_ONE5STOPBITS,
49
            SER_TWOSTOPBITS
50
        };
51

    
52
    public:
53
        /**
54
         * Default constructor.
55
         */
56
        cSerialDevice();
57

    
58
        /**
59
         * Destructor.
60
         */
61
        virtual ~cSerialDevice();
62

    
63
        /**
64
         * Opens a serial device
65
         * @param strDeviceName [in] The device name.
66
         * @param nBaudRate     [in] The baud rate.
67
         * @param nParity       [in] The parity.
68
         * @param nDataBits     [in] The amount of data bits.
69
         * @param nStopBits     [in] The amount of stop bits.
70
         * @param nRxQueue      [in] The receive queue size.
71
         * @param nTxQueue      [in] The transmission queue size.
72
         * @param nReadTimeout  [in] The timeout for read operations in microseconds.
73
         * @return Standard result.
74
         * @remarks only win32: the strDeviceName "COM1" through "COM9" can be used. A general way to specify the COM-ports (inclusive the numbering greather than 9) is the "\\\\.\\COMx". Further information can be found at http://support.microsoft.com/kb/115831/en-us
75
         */
76
        tResult Open(const tChar* strDeviceName, tInt nBaudRate=9600, tInt nParity=SER_NOPARITY, tInt nDataBits=8, tInt nStopBits=SER_ONESTOPBIT, tInt nRxQueue=4096, tInt nTxQueue=4096, tTimeStamp nReadTimeout=0);
77

    
78
        /**
79
         * Closes a serial device
80
         * @return Standard result.
81
         */
82
        tResult Close();
83

    
84
        /**
85
         * Read data from the serial device.
86
         * @param pBuffer [in] The buffer to fill.
87
         * @param nBufferSize [in] How many bytes should be read.
88
         * @return The actual amount of bytes read.
89
         */
90
        tInt32 Read(tVoid* pBuffer, tInt32 nBufferSize);
91

    
92
        /**
93
         * Write data to the serial device.
94
         * @param pBuffer [in] The data to write.
95
         * @param nBufferSize [in] How many bytes should be written.
96
         * @return The actual amount of bytes written.
97
         */
98
        tInt32 Write(const tVoid* pBuffer, tInt32 nBufferSize);
99

    
100
        /**
101
         * Writes a string to the device by writing it byte after byte.
102
         * @param strCmd [in] The string to write
103
         * @return Standard result.
104
         */
105
        tResult WriteByteByByte(const cString &strCmd);
106

    
107
        /**
108
         * Checks if the serial device is opened.
109
         * @return tTrue if the serial device is opened, otherwise tFalse.
110
         * @rtsafe
111
         */
112
        tBool IsConnected();
113

    
114
    public:
115
        /**
116
         * Checks if the specified device is avaliable.
117
         * @param strDeviceName [in] The device name.
118
         * @return Standard result.
119
         */
120
        static tResult CheckForDevice(const tChar* strDeviceName);
121
        /**
122
         * Returns a bitmask of all avaliable serial devices.
123
         * @return A bitmask of all avaliable serial devices.
124
         */
125
        static tUInt32 GetDeviceMask();
126

    
127
        /**
128
         * Returns a bitmask of all unavaliable serial devices.
129
         * @return A bitmask of all unavaliable serial devices.
130
         */
131
        static tUInt32 GetUnusedDeviceMask();
132
        /**
133
         * Returns the name of the first unused serial device.
134
         * @param strDeviceName [out] The name of the first unused serial device.
135
         * @return Standard result.
136
         */
137
        static tResult FindUnusedDevice(cString& strDeviceName);
138
};
139

    
140
} //namespace A_UTILS_NS
141

    
142
#endif //_UTILS_SERIALDEVICE_HEADER
(2-2/7)