gclib  2.0.8
Communications API for Galil controllers and PLCs
Galil.h
Go to the documentation of this file.
1 
4 #ifndef GALIL_H
5 #define GALIL_H
6 
7 #include <string>
8 #include <vector>
9 
10 class GalilPrivate;
11 
12 #ifdef _MSC_VER // MSVC Compiler
13  #ifdef MAKEDLL
14  #define DLL_IMPORT_EXPORT __declspec(dllexport)
15  #else
16 // #define DLL_IMPORT_EXPORT __declspec(dllimport)
17  #define DLL_IMPORT_EXPORT
18  #endif
19 #else //not Windows (e.g. Linux). Expand to empty space
20  #define DLL_IMPORT_EXPORT
21 #endif
22 
23 //DLL_IMPORT_EXPORT void SetDynamicLink (void);
24 
25 class DLL_IMPORT_EXPORT Galil //An instance of the Galil class (Galil object) represents a CONNECTION to a controller (not necessarily the controller itself). Multiple Galil objects can connect to a single Ethernet controller.
26 {
27  GalilPrivate * d;
28 public:
29  static std::string libraryVersion(); //returns version string of Galil class library for display (e.g. "0.0.4.3 Jan 2 2008 16:04:50 libGalil.so"). Can be called WITHOUT an instance of Galil. Note that this has nothing to do with the version of the controller (which can be found with connection() below).
30  static std::vector<std::string> addresses(); //returns list of available addresses to connect to (e.g. "1.2.3.4"). Each item in the list may be fed to the constructor Galil()
31 
32  Galil(std::string address = ""); //constructor opens connection with controller e.g. 192.168.1.2, COM1, /dev/ttyS0, GALILPCI1 /dev/galilpci0 (default constructor with no arguments will bring up a dialog)
33  ~Galil(); //destructor closes connection with controller
34  std::string connection(); //returns a string like "DMC4080 Rev 1.0, 123, 10.0.0.70, IHA"
35 
36  int timeout_ms; //default = 500 milliseconds. This is the timeout for everything but BP, BV, RS, ^R^S, and program/array/firmware download
37  std::string command( const std::string& command = "MG TIME", const std::string& terminator = "\r", const std::string& ack = ":", bool trim = true); //send a command (e.g. "MG _RPX") to the controller and get the response
38  double commandValue(const std::string& command = "MG TIME"); //convenience method that converts response from string to numerical value
39  std::string message( int timeout_ms = 500); //ms. get MGs from controller program
40  int interrupt(int timeout_ms = 500); //ms. EI, UI (DMC-18xx only). Returns status byte (e.g. 0xf0 for UI0)
41 
42  std::string programUpload(); //UL upload a controller program to an in-memory buffer
43  void programDownload( const std::string& program = "MG TIME\rEN"); //DL download a controller program from an in-memory buffer
44  void programUploadFile( const std::string& file = "program.dmc"); //UL upload a controller program to a disk file
45  void programDownloadFile(const std::string& file = "program.dmc"); //DL download a controller program from a disk file
46 
47  std::vector<double> arrayUpload( const std::string& name = "array"); //QU upload an array to an in-memory buffer
48  void arrayDownload( const std::vector<double>& array, const std::string& name = "array"); //QD download an array from an in-memory buffer
49  void arrayUploadFile( const std::string& file = "arrays.csv", const std::string& names = ""); //QU upload array(s) to a disk file. "" means upload all arrays, else separate the array names with a space
50  void arrayDownloadFile(const std::string& file = "arrays.csv"); //QD download array(s) from a disk file
51 
52  void firmwareDownloadFile(const std::string& file = "firmware.hex"); //download hex file (RS-232 only for DMC-21x3)
53 
54  int write(const std::string& bytes = "\r"); //returns actual number of bytes written
55  std::string read(); //returns actual bytes read
56 
57  std::vector<std::string> sources(); //returns list of sources (_RPA...) supported by this controller, which are fed to sourceValue(), source(), and setSource()
58  void recordsStart(double period_ms = -1); //milliseconds. Sends DR. -1 means leave be if not 0, else run as fast as possible. > 0 sets the DR sample period in true milliseconds (rounded to nearest power of 2 for DMC-18xx). 0 sets DR0 (turns it off)
59  std::vector<char> record(const std::string& method = "QR"); //reads DR packet OR sends QR and reads response
60  double sourceValue(const std::vector<char>& record, const std::string& source = "TIME"); //get the value for one particular source (e.g. _RPA is 1000)
61  std::string source( const std::string& field = "Description", const std::string& source = "TIME"); //get e.g. the description string for one particular source (e.g. _RPA is "Axis A reference position"). Fields are "Description", "Units", & "Scale"
62  void setSource( const std::string& field = "Description", const std::string& source = "TIME", const std::string& to = "Sample counter"); //set e.g. the description string for one particular source (e.g. _RPA to "Feed axis reference position"). Fields are "Description", "Units", & "Scale"
63 
64 };
65 
66 #endif
Definition: Galil.h:26
GReturn message(GCon g)
Demonstrates how to receive messages from the controller and detect differences in Trace and crashed ...
Definition: message.cpp:14