File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -429,6 +429,17 @@ const char *CSerialPortGetLastErrorMsg(i_handle_t handle)
429429 return " " ;
430430}
431431
432+ const char *CSerialPortGetErrorMsg (i_handle_t handle, int code)
433+ {
434+ itas109::CSerialPort *pCSP = reinterpret_cast <itas109::CSerialPort *>(handle);
435+ if (pCSP)
436+ {
437+ return pCSP->getErrorMsg (code);
438+ }
439+
440+ return " " ;
441+ }
442+
432443void CSerialPortClearError (i_handle_t handle)
433444{
434445 itas109::CSerialPort *pCSP = reinterpret_cast <itas109::CSerialPort *>(handle);
Original file line number Diff line number Diff line change @@ -72,6 +72,33 @@ enum FlowControl
7272 FlowSoftware = 2
7373};
7474
75+ enum SerialPortError
76+ {
77+ ErrorOK = 0 ,
78+
79+ ErrorFail = -1 ,
80+ ErrorNotImplemented = -2 ,
81+ ErrorInner = -3 ,
82+ ErrorNullPointer = -4 ,
83+ ErrorInvalidParam = -5 ,
84+ ErrorAccessDenied = -6 ,
85+ ErrorOutOfMemory = -7 ,
86+ ErrorTimeout = -8 ,
87+
88+ ErrorNotInit = -20 ,
89+ ErrorInitFailed = -21 ,
90+ ErrorAlreadyExist = -22 ,
91+ ErrorNotExist = -23 ,
92+ ErrorAlreadyOpen = -24 ,
93+ ErrorNotOpen = -25 ,
94+ ErrorOpenFailed = -26 ,
95+ ErrorCloseFailed = -27 ,
96+ ErrorWriteFailed = -28 ,
97+ ErrorReadFailed = -29 ,
98+
99+ ErrorUnknown = -999 ,
100+ };
101+
75102#ifdef __cplusplus
76103extern "C"
77104{
@@ -149,6 +176,8 @@ extern "C"
149176
150177 C_DLL_EXPORT const char * CSerialPortGetLastErrorMsg (i_handle_t handle );
151178
179+ C_DLL_EXPORT const char * CSerialPortGetErrorMsg (i_handle_t handle , int code );
180+
152181 C_DLL_EXPORT void CSerialPortClearError (i_handle_t handle );
153182
154183 C_DLL_EXPORT void CSerialPortSetPortName (i_handle_t handle , const char * portName );
Original file line number Diff line number Diff line change @@ -281,6 +281,13 @@ class DLL_EXPORT CSerialPort
281281 * @return return last error code message 返回错误码信息
282282 */
283283 const char *getLastErrorMsg () const ;
284+ /* *
285+ * @brief Get the Error Code Message 获取指定错误码信息
286+ *
287+ * @param code errorCode 错误码
288+ * @return return error code message 返回指定错误码信息
289+ */
290+ const char *getErrorMsg (int code) const ;
284291 /* *
285292 * @brief clear error 清除错误信息
286293 *
Original file line number Diff line number Diff line change @@ -207,6 +207,14 @@ class CSerialPortBase
207207 */
208208 const char *getLastErrorMsg () const ;
209209
210+ /* *
211+ * @brief Get the Error Code Message 获取指定错误码信息
212+ *
213+ * @param code errorCode 错误码
214+ * @return return error code message 返回指定错误码信息
215+ */
216+ const char *getErrorMsg (int code) const ;
217+
210218 /* *
211219 * @brief clear error 清除错误信息
212220 *
Original file line number Diff line number Diff line change @@ -340,6 +340,18 @@ const char *itas109::CSerialPort::getLastErrorMsg() const
340340 }
341341}
342342
343+ const char *itas109::CSerialPort::getErrorMsg (int code) const
344+ {
345+ if (p_serialPortBase)
346+ {
347+ return p_serialPortBase->getErrorMsg (code);
348+ }
349+ else
350+ {
351+ return " " ;
352+ }
353+ }
354+
343355void itas109::CSerialPort::clearError ()
344356{
345357 if (p_serialPortBase)
Original file line number Diff line number Diff line change @@ -69,7 +69,12 @@ int CSerialPortBase::getLastError() const
6969
7070const char *CSerialPortBase::getLastErrorMsg () const
7171{
72- switch (m_lastError)
72+ return getErrorMsg (m_lastError);
73+ }
74+
75+ const char *CSerialPortBase::getErrorMsg (int code) const
76+ {
77+ switch (code)
7378 {
7479 case itas109::ErrorOK:
7580 return " success" ;
You can’t perform that action at this time.
0 commit comments