yocto_serialport.h
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * $Id: yocto_serialport.h 28748 2017-10-03 08:23:39Z seb $
4  *
5  * Declares yFindSerialPort(), the high-level API for SerialPort functions
6  *
7  * - - - - - - - - - License information: - - - - - - - - -
8  *
9  * Copyright (C) 2011 and beyond by Yoctopuce Sarl, Switzerland.
10  *
11  * Yoctopuce Sarl (hereafter Licensor) grants to you a perpetual
12  * non-exclusive license to use, modify, copy and integrate this
13  * file into your software for the sole purpose of interfacing
14  * with Yoctopuce products.
15  *
16  * You may reproduce and distribute copies of this file in
17  * source or object form, as long as the sole purpose of this
18  * code is to interface with Yoctopuce products. You must retain
19  * this notice in the distributed source file.
20  *
21  * You should refer to Yoctopuce General Terms and Conditions
22  * for additional information regarding your rights and
23  * obligations.
24  *
25  * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED 'AS IS' WITHOUT
26  * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
27  * WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS
28  * FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO
29  * EVENT SHALL LICENSOR BE LIABLE FOR ANY INCIDENTAL, SPECIAL,
30  * INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA,
31  * COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR
32  * SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT
33  * LIMITED TO ANY DEFENSE THEREOF), ANY CLAIMS FOR INDEMNITY OR
34  * CONTRIBUTION, OR OTHER SIMILAR COSTS, WHETHER ASSERTED ON THE
35  * BASIS OF CONTRACT, TORT (INCLUDING NEGLIGENCE), BREACH OF
36  * WARRANTY, OR OTHERWISE.
37  *
38  *********************************************************************/
39 
40 
41 #ifndef YOCTO_SERIALPORT_H
42 #define YOCTO_SERIALPORT_H
43 
44 #include "yocto_api.h"
45 #include <cfloat>
46 #include <cmath>
47 #include <map>
48 
49 //--- (generated code: YSerialPort return codes)
50 //--- (end of generated code: YSerialPort return codes)
51 //--- (generated code: YSerialPort definitions)
52 class YSerialPort; // forward declaration
53 
54 typedef void (*YSerialPortValueCallback)(YSerialPort *func, const string& functionValue);
55 #ifndef _Y_VOLTAGELEVEL_ENUM
56 #define _Y_VOLTAGELEVEL_ENUM
57 typedef enum {
67 #endif
68 #define Y_RXCOUNT_INVALID (YAPI_INVALID_UINT)
69 #define Y_TXCOUNT_INVALID (YAPI_INVALID_UINT)
70 #define Y_ERRCOUNT_INVALID (YAPI_INVALID_UINT)
71 #define Y_RXMSGCOUNT_INVALID (YAPI_INVALID_UINT)
72 #define Y_TXMSGCOUNT_INVALID (YAPI_INVALID_UINT)
73 #define Y_LASTMSG_INVALID (YAPI_INVALID_STRING)
74 #define Y_CURRENTJOB_INVALID (YAPI_INVALID_STRING)
75 #define Y_STARTUPJOB_INVALID (YAPI_INVALID_STRING)
76 #define Y_COMMAND_INVALID (YAPI_INVALID_STRING)
77 #define Y_PROTOCOL_INVALID (YAPI_INVALID_STRING)
78 #define Y_SERIALMODE_INVALID (YAPI_INVALID_STRING)
79 //--- (end of generated code: YSerialPort definitions)
80 
81 
82 //--- (generated code: YSnoopingRecord definitions)
83 //--- (end of generated code: YSnoopingRecord definitions)
84 
85 //--- (generated code: YSnoopingRecord declaration)
92 #ifdef __BORLANDC__
93 #pragma option push -w-8022
94 #endif
95 //--- (end of generated code: YSnoopingRecord declaration)
96  //--- (generated code: YSnoopingRecord attributes)
97  // Attributes (function value cache)
98  int _tim;
99  int _dir;
100  string _msg;
101  //--- (end of generated code: YSnoopingRecord attributes)
102  //--- (generated code: YSnoopingRecord constructor)
103 
104  //--- (end of generated code: YSnoopingRecord constructor)
105  //--- (generated code: YSnoopingRecord initialization)
106  //--- (end of generated code: YSnoopingRecord initialization)
107 
108 public:
109  YSnoopingRecord(const string& json);
110  //--- (generated code: YSnoopingRecord accessors declaration)
111 
112 
113  virtual int get_time(void);
114 
115  virtual int get_direction(void);
116 
117  virtual string get_message(void);
118 
119 #ifdef __BORLANDC__
120 #pragma option pop
121 #endif
122  //--- (end of generated code: YSnoopingRecord accessors declaration)
123 };
124 
125 
126 
127 
128 
129 //--- (generated code: YSerialPort declaration)
140 #ifdef __BORLANDC__
141 #pragma option push -w-8022
142 #endif
143 //--- (end of generated code: YSerialPort declaration)
144 protected:
145  //--- (generated code: YSerialPort attributes)
146  // Attributes (function value cache)
147  int _rxCount;
148  int _txCount;
152  string _lastMsg;
153  string _currentJob;
154  string _startupJob;
155  string _command;
157  string _protocol;
158  string _serialMode;
160  int _rxptr;
161  string _rxbuff;
163 
164  friend YSerialPort *yFindSerialPort(const string& func);
165  friend YSerialPort *yFirstSerialPort(void);
166 
167  // Function-specific method for parsing of JSON output and caching result
168  virtual int _parseAttr(YJSONObject* json_val);
169 
170  // Constructor is protected, use yFindSerialPort factory function to instantiate
171  YSerialPort(const string& func);
172  //--- (end of generated code: YSerialPort attributes)
173 
174 public:
175  ~YSerialPort();
176  //--- (generated code: YSerialPort accessors declaration)
177 
178  static const int RXCOUNT_INVALID = YAPI_INVALID_UINT;
179  static const int TXCOUNT_INVALID = YAPI_INVALID_UINT;
180  static const int ERRCOUNT_INVALID = YAPI_INVALID_UINT;
181  static const int RXMSGCOUNT_INVALID = YAPI_INVALID_UINT;
182  static const int TXMSGCOUNT_INVALID = YAPI_INVALID_UINT;
183  static const string LASTMSG_INVALID;
184  static const string CURRENTJOB_INVALID;
185  static const string STARTUPJOB_INVALID;
186  static const string COMMAND_INVALID;
187  static const Y_VOLTAGELEVEL_enum VOLTAGELEVEL_OFF = Y_VOLTAGELEVEL_OFF;
188  static const Y_VOLTAGELEVEL_enum VOLTAGELEVEL_TTL3V = Y_VOLTAGELEVEL_TTL3V;
189  static const Y_VOLTAGELEVEL_enum VOLTAGELEVEL_TTL3VR = Y_VOLTAGELEVEL_TTL3VR;
190  static const Y_VOLTAGELEVEL_enum VOLTAGELEVEL_TTL5V = Y_VOLTAGELEVEL_TTL5V;
191  static const Y_VOLTAGELEVEL_enum VOLTAGELEVEL_TTL5VR = Y_VOLTAGELEVEL_TTL5VR;
192  static const Y_VOLTAGELEVEL_enum VOLTAGELEVEL_RS232 = Y_VOLTAGELEVEL_RS232;
193  static const Y_VOLTAGELEVEL_enum VOLTAGELEVEL_RS485 = Y_VOLTAGELEVEL_RS485;
194  static const Y_VOLTAGELEVEL_enum VOLTAGELEVEL_INVALID = Y_VOLTAGELEVEL_INVALID;
195  static const string PROTOCOL_INVALID;
196  static const string SERIALMODE_INVALID;
197 
205  int get_rxCount(void);
206 
207  inline int rxCount(void)
208  { return this->get_rxCount(); }
209 
217  int get_txCount(void);
218 
219  inline int txCount(void)
220  { return this->get_txCount(); }
221 
229  int get_errCount(void);
230 
231  inline int errCount(void)
232  { return this->get_errCount(); }
233 
241  int get_rxMsgCount(void);
242 
243  inline int rxMsgCount(void)
244  { return this->get_rxMsgCount(); }
245 
253  int get_txMsgCount(void);
254 
255  inline int txMsgCount(void)
256  { return this->get_txMsgCount(); }
257 
265  string get_lastMsg(void);
266 
267  inline string lastMsg(void)
268  { return this->get_lastMsg(); }
269 
277  string get_currentJob(void);
278 
279  inline string currentJob(void)
280  { return this->get_currentJob(); }
281 
293  int set_currentJob(const string& newval);
294  inline int setCurrentJob(const string& newval)
295  { return this->set_currentJob(newval); }
296 
304  string get_startupJob(void);
305 
306  inline string startupJob(void)
307  { return this->get_startupJob(); }
308 
320  int set_startupJob(const string& newval);
321  inline int setStartupJob(const string& newval)
322  { return this->set_startupJob(newval); }
323 
324  string get_command(void);
325 
326  inline string command(void)
327  { return this->get_command(); }
328 
329  int set_command(const string& newval);
330  inline int setCommand(const string& newval)
331  { return this->set_command(newval); }
332 
342  Y_VOLTAGELEVEL_enum get_voltageLevel(void);
343 
345  { return this->get_voltageLevel(); }
346 
362  int set_voltageLevel(Y_VOLTAGELEVEL_enum newval);
364  { return this->set_voltageLevel(newval); }
365 
381  string get_protocol(void);
382 
383  inline string protocol(void)
384  { return this->get_protocol(); }
385 
405  int set_protocol(const string& newval);
406  inline int setProtocol(const string& newval)
407  { return this->set_protocol(newval); }
408 
422  string get_serialMode(void);
423 
424  inline string serialMode(void)
425  { return this->get_serialMode(); }
426 
442  int set_serialMode(const string& newval);
443  inline int setSerialMode(const string& newval)
444  { return this->set_serialMode(newval); }
445 
473  static YSerialPort* FindSerialPort(string func);
474 
486  virtual int registerValueCallback(YSerialPortValueCallback callback);
488 
489  virtual int _invokeValueCallback(string value);
490 
491  virtual int sendCommand(string text);
492 
500  virtual int reset(void);
501 
511  virtual int writeByte(int code);
512 
522  virtual int writeStr(string text);
523 
533  virtual int writeBin(string buff);
534 
544  virtual int writeArray(vector<int> byteList);
545 
555  virtual int writeHex(string hexString);
556 
566  virtual int writeLine(string text);
567 
577  virtual int readByte(void);
578 
590  virtual string readStr(int nChars);
591 
603  virtual string readBin(int nChars);
604 
616  virtual vector<int> readArray(int nChars);
617 
629  virtual string readHex(int nBytes);
630 
644  virtual string readLine(void);
645 
667  virtual vector<string> readMessages(string pattern,int maxWait);
668 
678  virtual int read_seek(int absPos);
679 
685  virtual int read_tell(void);
686 
693  virtual int read_avail(void);
694 
707  virtual string queryLine(string query,int maxWait);
708 
720  virtual int uploadJob(string jobfile,string jsonDef);
721 
733  virtual int selectJob(string jobfile);
734 
745  virtual int set_RTS(int val);
746 
755  virtual int get_CTS(void);
756 
773  virtual vector<YSnoopingRecord> snoopMessages(int maxWait);
774 
786  virtual int writeMODBUS(string hexString);
787 
800  virtual vector<int> queryMODBUS(int slaveNo,vector<int> pduBytes);
801 
814  virtual vector<int> modbusReadBits(int slaveNo,int pduAddr,int nBits);
815 
828  virtual vector<int> modbusReadInputBits(int slaveNo,int pduAddr,int nBits);
829 
842  virtual vector<int> modbusReadRegisters(int slaveNo,int pduAddr,int nWords);
843 
856  virtual vector<int> modbusReadInputRegisters(int slaveNo,int pduAddr,int nWords);
857 
870  virtual int modbusWriteBit(int slaveNo,int pduAddr,int value);
871 
884  virtual int modbusWriteBits(int slaveNo,int pduAddr,vector<int> bits);
885 
898  virtual int modbusWriteRegister(int slaveNo,int pduAddr,int value);
899 
912  virtual int modbusWriteRegisters(int slaveNo,int pduAddr,vector<int> values);
913 
929  virtual vector<int> modbusWriteAndReadRegisters(int slaveNo,int pduWriteAddr,vector<int> values,int pduReadAddr,int nReadWords);
930 
931 
932  inline static YSerialPort* Find(string func)
933  { return YSerialPort::FindSerialPort(func); }
934 
942  YSerialPort *nextSerialPort(void);
943  inline YSerialPort *next(void)
944  { return this->nextSerialPort();}
945 
955  static YSerialPort* FirstSerialPort(void);
956  inline static YSerialPort* First(void)
957  { return YSerialPort::FirstSerialPort();}
958 #ifdef __BORLANDC__
959 #pragma option pop
960 #endif
961  //--- (end of generated code: YSerialPort accessors declaration)
962 };
963 
964 //--- (generated code: YSerialPort functions declaration)
965 
993 inline YSerialPort* yFindSerialPort(const string& func)
994 { return YSerialPort::FindSerialPort(func);}
1005 { return YSerialPort::FirstSerialPort();}
1006 
1007 //--- (end of generated code: YSerialPort functions declaration)
1008 
1009 #endif
static YSerialPort * FirstSerialPort(void)
void(* YSerialPortValueCallback)(YSerialPort *func, const string &functionValue)
static const string CURRENTJOB_INVALID
string startupJob(void)
YSerialPort * yFirstSerialPort(void)
int rxCount(void)
static const string PROTOCOL_INVALID
string protocol(void)
int rxMsgCount(void)
Y_VOLTAGELEVEL_enum
int setCommand(const string &newval)
static const string LASTMSG_INVALID
int setSerialMode(const string &newval)
#define YAPI_INVALID_UINT
Definition: yocto_api.h:71
int setCurrentJob(const string &newval)
virtual int _parseAttr(YJSONObject *json_val)
Definition: yocto_api.cpp:2367
int setProtocol(const string &newval)
static const string STARTUPJOB_INVALID
int txCount(void)
YSerialPort * yFindSerialPort(const string &func)
int txMsgCount(void)
static const string COMMAND_INVALID
YSerialPort * next(void)
string lastMsg(void)
int errCount(void)
YSerialPortValueCallback _valueCallbackSerialPort
string currentJob(void)
virtual int registerValueCallback(YFunctionValueCallback callback)
Definition: yocto_api.cpp:2544
int setStartupJob(const string &newval)
string command(void)
#define YOCTO_CLASS_EXPORT
Definition: yocto_api.h:61
string serialMode(void)
Y_VOLTAGELEVEL_enum voltageLevel(void)
static const string SERIALMODE_INVALID
Y_VOLTAGELEVEL_enum _voltageLevel
static YSerialPort * FindSerialPort(string func)
static YSerialPort * First(void)
int setVoltageLevel(Y_VOLTAGELEVEL_enum newval)
static YSerialPort * Find(string func)
virtual int _invokeValueCallback(string value)
Definition: yocto_api.cpp:2563


yoctopuce_altimeter
Author(s): Anja Sheppard
autogenerated on Mon Jun 10 2019 15:49:11