gclib  2.0.8
Communications API for Galil controllers and PLCs
gcl_galil.h
Go to the documentation of this file.
1 
3 #ifndef I_34E90AC4_EF44_4CB5_AF47_B9D334EE5FB7
4 #define I_34E90AC4_EF44_4CB5_AF47_B9D334EE5FB7
5 
6 #include "gclibo.h" //gclib and gclibo
7 #include <unordered_map> //used for data record features
8 #include <sstream> //format source keys, string stream
9 #include <iomanip> //format source keys
10 #include <algorithm> //sort sources
11 #define MAKEDLL //Galil.h requires this for proper export declarations
12 #include "Galil.h" //gcl header
13 #define TRAFFICBUF 4096 //Memory used for buffering controller traffic. If program/array upload is getting truncated, make this larger.
14 
15 
16 struct Source //each data record source key (e.g. "_RPA") maps to one of these, each of which describes the position and width of the variable within the binary data record
17 {
18  int byte; //byte offset within binary data record
19  std::string type; //"SB", "UB", "SW", "UW", "SL", "UL". Specifies width within binary data record and signed/unsigned.
20  int bit; //-1 if not bit field (e.g. RPA). >= 0 if bit field (e.g. _MOA)
21  std::string units; //e.g. "counts"
22  std::string description; //e.g. "analog input 1"
23  double scale; //e.g. 32768, scale factor: most sources are 1 except TV, TT, @AN, @AO etc.
24  double offset; //needed for analog inputs and outputs
25 
26  Source(int byte = 0, std::string type = "Ux", int bit = -1, std::string units = "", std::string description = "", double scale = 1, double offset = 0) :
27  byte(byte), type(type), bit(bit), units(units), description(description), scale(scale), offset(offset)
28  { /*ctor just initializes values*/ }
29 };
30 
31 // Use the gcl private class name to hold useful data for the wrapper
33 {
34 public:
35  GalilPrivate(Galil* galil_ptr, GCon gclib_handle)
36  : q(galil_ptr), g(gclib_handle)
37  { /*ctor just initializes values*/ }
38 
39  GCon g; //gclib handle for this class
40  char tbuf[TRAFFICBUF]; //traffic buffer shared by member functions of Galil
41  std::unordered_map<std::string, Source> map; //data structure for data record calls
42  void InitializeDataRecord(); //called in Galil() ctor to create the data record map
43 
44 private:
45  Galil* q; //pointer to the Galil class so we can call Command, etc.
46 
47  //functions for initializing the data record for various products
48  void Init1806(int axes);
49  void Init1800(int axes, bool dmc1802);
50  void Init4000(int axes); //41x3 and 50000 too
51  void Init30010(bool dmc31010);
52  void Init2103(int axes);
53  void InitRio(bool rio3); //rio3 indicates if this connection is to an RIO-47300 which has a different length than other RIOs
54 
55  void InitRio3_24Ex(); //extended I/O option for RIO-47300
56  void InitRioSer(bool rio3); //Serial encoder (quad/SSI/BISS) option for RIO
57 
58  //Helper/convenience functions
59  std::string ax(std::string prefix, int axis, std::string suffix); // Creates an axis string from a prefix, axis number (0-7), and suffix.
60  void input_bits(int byte, int num); //Creates 8 digital input sources from an offset and a starting input number.
61  void output_bits(int byte, int num); //Creates 8 digital ouput sources from an offset and a starting output number.
62  void aq_analog(int byte, int input_num); //polls AQ for input_num and creates an analog input source with the proper AQ scalar
63  void dq_analog(int byte, int input_num); //polls DQ for input_num and creates an analog output source with the proper DQ scalar
64 };
65 
66 void ec(GReturn rc); // Error Check. Takes a gclib error code and throws a GCL-like error string if there's a gclib error
67 
68 
69 
70 #endif //I_34E90AC4_EF44_4CB5_AF47_B9D334EE5FB7
Definition: Galil.h:26
int GReturn
Every function returns a value of type GReturn. See gclib_errors.h for possible values.
Definition: gclib.h:93
void * GCon
Connection handle. Unique for each connection in process. Assigned a non-zero value in GOpen().
Definition: gclib.h:94