gclib 2.5.0
Galil Communications Library
Loading...
Searching...
No Matches
gclib.hpp
Go to the documentation of this file.
1#pragma once
2#include <gclib.h>
3#include <string>
4#include <vector>
5#include <functional>
6#include <system_error>
7#include <bitset>
8
9namespace gclib {
11 enum result {
12 InvalidArgument = GCLIB_INVALID_ARGUMENT,
13 InternalError = GCLIB_INTERNAL_ERROR,
14 Timeout = GCLIB_TIMEOUT,
15 CommandError = GCLIB_COMMAND_ERROR,
16 BufferTooSmall = GCLIB_BUFFER_TOO_SMALL,
17 NotConnected = GCLIB_NOT_CONNECTED,
18 NotSubscribed = GCLIB_NOT_SUBSCRIBED
19 };
21 const class error_category : public std::error_category {
22 public:
23 using std::error_category::error_category;
24 virtual const char* name() const noexcept override {
25 return "gclib::error::category";
26 }
27 virtual std::string message(int result) const override {
28 switch (result) {
29 case InvalidArgument:
30 return "An invalid argument was passed";
31 case InternalError:
32 return "An internal error occurred";
33 case Timeout:
34 return "The operation timed out";
35 case CommandError:
36 return "The controller returned a question mark";
37 case BufferTooSmall:
38 return "The data could not fit in the provided buffer";
39 case NotConnected:
40 return "The controller or gcaps is not connected";
41 case NotSubscribed:
42 return "Not subscribed to unsolicited data";
43 default:
44 return "Unrecognized gclib result";
45 }
46 }
47 } error_category;
49 class error : public std::system_error {
50 public:
51 using std::system_error::system_error;
52 };
53
60
62 namespace internal {
64 const size_t HUGE_BUFFER = 524288;
66 inline void check(gclib_result result, gclib_handle h = NULL) {
67 if (result) {
68 std::string err = gclib_error(h);
69 if (err.empty()) {
70 throw error(std::error_code(static_cast<enum result>(result), error_category));
71 }
72 throw error(std::error_code(static_cast<enum result>(result), error_category), err);
73 }
74 }
76 template <typename ...Args>
77 inline std::string wrap(std::function<gclib_result(char*, size_t, Args...)> func, Args... args) {
78 char* huge_buffer = static_cast<char*>(std::malloc(sizeof(char) * HUGE_BUFFER));
79 check(func(huge_buffer, sizeof(char) * HUGE_BUFFER, args...));
80 std::string result(huge_buffer);
81 std::free(huge_buffer);
82 return result;
83 }
84 };
85
114
115 struct DataRecord {
126
129 struct Amp {
130 Amp(gclib_data_record_handle h, size_t amp) : h_{h}, amp_{amp} {}
131 bool over_current() { return gclib_data_record_over_current(h_, amp_); }
132 bool over_voltage() { return gclib_data_record_over_voltage(h_, amp_); }
133 bool over_temp() { return gclib_data_record_over_temp(h_, amp_); }
136 private:
138 size_t amp_;
139 };
140
141 struct Axis {
142 Axis(gclib_data_record_handle h, char axis) : h_{h}, axis_{axis} {}
154 bool motor_off() { return gclib_data_record_motor_off(h_, axis_); }
155 bool latch_armed() { return gclib_data_record_latch_armed(h_, axis_); }
157 bool stopping() { return gclib_data_record_stopping(h_, axis_); }
158 bool slewing() { return gclib_data_record_slewing(h_, axis_); }
161 bool moving() { return gclib_data_record_moving(h_, axis_); }
162 int home_phase() { return gclib_data_record_home_phase(h_, axis_); }
163 bool stepper_mode() { return gclib_data_record_stepper_mode(h_, axis_); }
164 bool home_input() { return gclib_data_record_home_input(h_, axis_); }
165 bool reverse_limit() { return gclib_data_record_reverse_limit(h_, axis_); }
166 bool forward_limit() { return gclib_data_record_forward_limit(h_, axis_); }
167 bool latch_input() { return gclib_data_record_latch_input(h_, axis_); }
169 uint8_t stop_code() { return gclib_data_record_stop_code(h_, axis_); }
171 int32_t position() { return gclib_data_record_position(h_, axis_); }
172 int32_t position_error() { return gclib_data_record_position_error(h_, axis_); }
173 int32_t aux_position() { return gclib_data_record_aux_position(h_, axis_); }
174 int32_t velocity() { return gclib_data_record_velocity(h_, axis_); }
175 double torque() { return gclib_data_record_torque(h_, axis_); }
176 double analog_input() { return gclib_data_record_analog_input(h_, axis_); }
177 int8_t halls() { return gclib_data_record_halls(h_, axis_); }
178 int32_t variable() { return gclib_data_record_variable(h_, axis_); }
179 bool hall_error() { return gclib_data_record_hall_error(h_, axis_); }
180 bool peak_current() { return gclib_data_record_peak_current(h_, axis_); }
181 private:
183 char axis_;
184 };
185
187 CoordinatedMove(gclib_data_record_handle h, char plane) : h_{h}, plane_{plane} {}
189 uint16_t status() { return gclib_data_record_coordinated_move_status(h_, plane_); }
196 private:
198 char plane_;
199 };
200 uint16_t sample() { return gclib_data_record_sample(h_); }
201
208 bool input(size_t index) { return gclib_data_record_input(h_, index); }
209
213 bool output(size_t index) { return gclib_data_record_output(h_, index); }
214 std::bitset<8> input_bank(size_t index) { return gclib_data_record_input_bank(h_, index); }
215 std::bitset<8> output_bank(size_t index) { return gclib_data_record_output_bank(h_, index); }
216 uint8_t error_code() { return gclib_data_record_error_code(h_); }
219 bool thread_running(size_t thread) { return gclib_data_record_thread_running(h_, thread); }
220
223 EthernetStatus ethernet_status(char handle) { return static_cast<EthernetStatus>(gclib_data_record_ethernet_status(h_, handle)); }
224
229 std::vector<uint8_t> bytes() {
230 std::string result(1024, '\0');
231 internal::check(gclib_data_record_bytes(h_, result.data(), result.size()));
232 return std::vector<uint8_t>(result.begin(), result.end());
233 }
234 Amp amp(size_t amp) { return Amp(h_, amp); }
235 Axis axis(char axis) { return Axis(h_, axis); }
236 CoordinatedMove coordinated_move(char plane) { return CoordinatedMove(h_, plane); }
237 private:
239 };
240
242 inline std::string version() { return internal::wrap({&gclib_version}); }
243
261 inline std::string addresses() { return internal::wrap({&gclib_addresses}); }
262
273 inline std::string ip_requests() { return internal::wrap({&gclib_ip_requests}); }
274 inline void assign_ip(std::string mac, std::string ip) { internal::check(gclib_assign_ip(mac.data(), ip.data())); }
275
276
287 inline void force_gcaps(bool on) { gclib_force_gcaps(on); }
289 inline std::string gcaps_version() { return internal::wrap({&gclib_gcaps_version}); }
291 inline std::string list_servers() { return internal::wrap({gclib_list_servers}); }
293 inline std::string server() { return internal::wrap({gclib_server}); }
296 inline void set_server(std::string name = {}) { internal::check(gclib_set_server(name.empty() ? nullptr : name.c_str())); }
298 inline std::string published() { return internal::wrap({&gclib_published}); }
300 inline void set_published(std::string name = {}) { internal::check(gclib_set_published(name.empty() ? nullptr : name.c_str())); }
301
304 public:
306 Controller(std::string address) : address_{address} {
307 open();
308 connection_type_ = connection_type();
309 }
310
311 Controller(std::string address, size_t baud_rate) : address_{address}, baud_rate_{baud_rate} {
312 open();
313 connection_type_ = connection_type();
314 }
316
318 void open() {
319 check(gclib_open(&h_, address_.data()));
320 if (connection_type_ == Serial) {
321 gclib_set_baud_rate(h_, baud_rate_);
322 }
323 }
324 void close() { gclib_close(&h_); }
325
327 std::string address() { return wrap({&gclib_address}); }
329 ConnectionType connection_type() { return static_cast<ConnectionType>(wrap<gclib_connection_t>({&gclib_connection_type})); }
330
332 std::string revision_information() { return wrap({&gclib_revision_information}); }
333 uint32_t serial_number() { return wrap<uint32_t>({&gclib_serial_number}); }
334
344 template <typename T = std::string>
345 T command(std::string command) {
346 std::string str = wrap({[command](gclib_handle h, char* buf, size_t len){ return gclib_command(h, command.c_str(), buf, len); }});
347 if constexpr (std::is_integral<T>() || std::is_floating_point<T>()) {
348 return std::stod(str);
349 } else {
350 return str;
351 }
352 };
353
354 std::string program() { return wrap({&gclib_program}); }
355 void set_program(std::string program, std::string insert = "") { check(gclib_set_program(h_, program.c_str(), insert.c_str())); }
356 std::string array(std::string name, size_t start = 0, size_t end = 0) { return wrap({[name](gclib_handle h, char* buf, size_t len, size_t start, size_t end){ return gclib_array(h, name.c_str(), buf, len, start, end); }}, start, end); }
357 void set_array(std::string name, std::string array, size_t start = 0, size_t end = 0) { check(gclib_set_array(h_, name.c_str(), array.c_str(), start, end)); }
358 void set_firmware(std::string file_path) { check(gclib_set_firmware(h_, file_path.c_str())); }
359
360
390 void set_interrupts(Interrupt::Type mask, std::bitset<8> motion_complete_axes = 0, std::bitset<8> digital_inputs = 0) {
391 check(gclib_set_interrupts(h_, static_cast<gclib_interrupt_type>(mask), gclib_axis_flags(motion_complete_axes.to_ulong()), gclib_digital_input_flags(digital_inputs.to_ulong())));
392 }
393
403 void set_data_records(size_t period_ms) { check(gclib_set_data_records(h_, period_ms)); }
404
420 void subscribe_messages(std::function<void(std::string message)> callback) {
421 message_callback_ = std::function([callback](const char* message){ callback(message); });
422 check(gclib_subscribe_messages(h_, wrap_message_callback, &message_callback_));
423 }
424
434 check(gclib_subscribe_messages(h_, nullptr, nullptr));
435 }
436
453 void subscribe_interrupts(std::function<void(Interrupt interrupt)> callback) {
454 interrupt_callback_ = std::function([callback](gclib_interrupt_t interrupt){ callback(interrupt); });
455 check(gclib_subscribe_interrupts(h_, wrap_interrupt_callback, &interrupt_callback_));
456 }
457
470 check(gclib_subscribe_interrupts(h_, nullptr, nullptr));
471 }
472
489 void subscribe_data_records(std::function<void(DataRecord data_record)> callback) {
490 data_record_callback_ = std::function([callback](gclib_data_record_handle h){ callback(DataRecord(h)); });
491 check(gclib_subscribe_data_records(h_, wrap_data_record_callback, &data_record_callback_));
492 }
493
503 check(gclib_subscribe_data_records(h_, nullptr, nullptr));
504 };
505
518 void subscribe_progress(std::function<void(size_t current, size_t max)> callback) {
519 progress_callback_ = callback;
520 check(gclib_subscribe_progress(h_, wrap_progress_callback, &progress_callback_));
521 };
522
523 void unsubscribe_messages() { check(gclib_unsubscribe(h_, (void*)&wrap_message_callback)); }
524 void unsubscribe_interrupts() { check(gclib_unsubscribe(h_, (void*)&wrap_interrupt_callback)); }
525 void unsubscribe_data_records() { check(gclib_unsubscribe(h_, (void*)&wrap_data_record_callback)); }
526 void unsubscribe_progress() { check(gclib_unsubscribe(h_, (void*)&wrap_progress_callback)); }
527
530 std::string message(int timeout = -1) { return wrap({&gclib_message}, timeout); }
533 Interrupt interrupt(int timeout = -1) { return wrap<gclib_interrupt_t>({&gclib_interrupt}, timeout); }
536 DataRecord data_record(int timeout = -1) { return wrap<gclib_data_record_handle>({&gclib_data_record}, timeout); }
537
538 private:
539 std::string address_;
540 size_t baud_rate_{115200};
541 ConnectionType connection_type_;
542 void check(gclib_result result) {
543 internal::check(result, h_);
544 }
545 template <typename ...Args>
546 std::string wrap(std::function<gclib_result(gclib_handle, char*, size_t, Args...)> func, Args... args) {
547 char* huge_buffer = static_cast<char*>(std::malloc(sizeof(char) * internal::HUGE_BUFFER));
548 check(func(h_, huge_buffer, sizeof(char) * internal::HUGE_BUFFER, args...));
549 std::string result(huge_buffer);
550 std::free(huge_buffer);
551 return result;
552 }
553 template <typename T, typename ...Args>
554 T wrap(std::function<gclib_result(gclib_handle, T*, Args...)> func, Args... args) {
555 T result;
556 check(func(h_, &result, args...));
557 return result;
558 }
559 gclib_handle h_{nullptr};
560
561 static inline void wrap_message_callback(void* context, const char* message){ (*(std::function<void(const char*)>*)(context))(message); }
562 static inline void wrap_interrupt_callback(void* context, gclib_interrupt_t interrupt){ (*(std::function<void(gclib_interrupt_t)>*)(context))(interrupt); }
563 static inline void wrap_data_record_callback(void* context, gclib_data_record_handle data_record){ (*(std::function<void(gclib_data_record_handle)>*)(context))(data_record); }
564 static inline void wrap_progress_callback(void* context, size_t current, size_t max){ (*(std::function<void(size_t, size_t)>*)(context))(current, max); }
565 std::function<void(const char*)> message_callback_;
566 std::function<void(gclib_interrupt_t)> interrupt_callback_;
567 std::function<void(gclib_data_record_handle)> data_record_callback_;
568 std::function<void(size_t, size_t)> progress_callback_;
569 };
570}
void subscribe_messages(std::function< void(std::string message)> callback)
Subscribe to unsolicited messages.
Definition gclib.hpp:420
void subscribe_interrupts()
Subscribe to interrupts.
Definition gclib.hpp:469
void set_firmware(std::string file_path)
Definition gclib.hpp:358
std::string address()
Returns the address that was used to connect to the controller.
Definition gclib.hpp:327
Interrupt interrupt(int timeout=-1)
Definition gclib.hpp:533
void unsubscribe_progress()
Definition gclib.hpp:526
uint32_t serial_number()
Definition gclib.hpp:333
std::string array(std::string name, size_t start=0, size_t end=0)
Definition gclib.hpp:356
void subscribe_data_records(std::function< void(DataRecord data_record)> callback)
Subscribe to data records.
Definition gclib.hpp:489
void set_interrupts(Interrupt::Type mask, std::bitset< 8 > motion_complete_axes=0, std::bitset< 8 > digital_inputs=0)
Configure which interrupts will be generated by the controller.
Definition gclib.hpp:390
void unsubscribe_data_records()
Definition gclib.hpp:525
ConnectionType connection_type()
Returns the type of address that was used to connect to the controller.
Definition gclib.hpp:329
Controller(std::string address, size_t baud_rate)
Open a serial connection to a controller reported by addresses().
Definition gclib.hpp:311
std::string program()
Definition gclib.hpp:354
void subscribe_messages()
Subscribe to unsolicited messages.
Definition gclib.hpp:433
std::string revision_information()
Returns controller ^R^V output.
Definition gclib.hpp:332
void subscribe_progress(std::function< void(size_t current, size_t max)> callback)
Register a progress callback.
Definition gclib.hpp:518
std::string message(int timeout=-1)
Definition gclib.hpp:530
DataRecord data_record(int timeout=-1)
Definition gclib.hpp:536
Controller(std::string address)
Open a connection to a controller reported by addresses().
Definition gclib.hpp:306
void open()
Open the connection. If connection is already open, it will be closed and reopened.
Definition gclib.hpp:318
void unsubscribe_messages()
Definition gclib.hpp:523
void subscribe_interrupts(std::function< void(Interrupt interrupt)> callback)
Subscribe to interrupts.
Definition gclib.hpp:453
void subscribe_data_records()
Subscribe to data records.
Definition gclib.hpp:502
void set_program(std::string program, std::string insert="")
Definition gclib.hpp:355
void set_data_records(size_t period_ms)
Configure controller data records.
Definition gclib.hpp:403
void set_array(std::string name, std::string array, size_t start=0, size_t end=0)
Definition gclib.hpp:357
T command(std::string command)
Issues a command to the controller and provides the response.
Definition gclib.hpp:345
void unsubscribe_interrupts()
Definition gclib.hpp:524
Thrown when the underlying C library returns a nonzero gclib_result.
Definition gclib.hpp:49
bool gclib_data_record_electronic_lock_out(gclib_data_record_handle h, size_t amp)
Returns electronic lockout (ELO) status for a bank.
bool gclib_data_record_over_voltage(gclib_data_record_handle h, size_t amp)
Returns over voltage status.
bool gclib_data_record_over_temp(gclib_data_record_handle h, size_t amp)
Returns over temperature status.
bool gclib_data_record_under_voltage(gclib_data_record_handle h, size_t amp)
Returns under voltage status.
bool gclib_data_record_over_current(gclib_data_record_handle h, size_t amp)
Returns over current status.
int32_t gclib_data_record_variable(gclib_data_record_handle h, char axis)
Returns the value of a user variable for an axis.
int32_t gclib_data_record_reference_position(gclib_data_record_handle h, char axis)
Returns the reference position.
bool gclib_data_record_reverse_limit(gclib_data_record_handle h, char axis)
Returns the state of the reverse limit.
int32_t gclib_data_record_velocity(gclib_data_record_handle h, char axis)
Returns the velocity.
int gclib_data_record_home_phase(gclib_data_record_handle h, char axis)
Returns home phase when in GCLIB_HOME mode.
bool gclib_data_record_moving(gclib_data_record_handle h, char axis)
Returns true if motion is being profiled.
bool gclib_data_record_stopping(gclib_data_record_handle h, char axis)
Returns true if axis is stopping.
bool gclib_data_record_forward_limit(gclib_data_record_handle h, char axis)
Returns the state of the forward limit.
gclib_mode_of_motion_t gclib_data_record_mode_of_motion(gclib_data_record_handle h, char axis)
Returns the mode of motion being profiled.
bool gclib_data_record_hall_error(gclib_data_record_handle h, char axis)
Returns true if the amplifier for this axis has triggered a hall error.
int32_t gclib_data_record_aux_position(gclib_data_record_handle h, char axis)
Returns the auxiliary position.
bool gclib_data_record_slewing(gclib_data_record_handle h, char axis)
Returns true if axis is slewing.
int32_t gclib_data_record_position_error(gclib_data_record_handle h, char axis)
Returns the position error.
bool gclib_data_record_home_input(gclib_data_record_handle h, char axis)
Returns the state of the home input.
bool gclib_data_record_final_deceleration(gclib_data_record_handle h, char axis)
Returns true when axis is in final deceleration.
uint8_t gclib_data_record_stop_code(gclib_data_record_handle h, char axis)
Returns a code indicating why the motor has stopped. See the SC command reference for details.
double gclib_data_record_analog_input(gclib_data_record_handle h, char axis)
Returns the analog input.
bool gclib_data_record_latch_armed(gclib_data_record_handle h, char axis)
Get latch armed.
bool gclib_data_record_latch_occurred(gclib_data_record_handle h, char axis)
Returns whether the latch was triggered.
bool gclib_data_record_latch_input(gclib_data_record_handle h, char axis)
Returns the state of the latch input.
bool gclib_data_record_negative_direction_move(gclib_data_record_handle h, char axis)
Returns true if axis velocity is negative.
int32_t gclib_data_record_position(gclib_data_record_handle h, char axis)
Returns the position.
bool gclib_data_record_motor_off(gclib_data_record_handle h, char axis)
Get motor off status.
double gclib_data_record_torque(gclib_data_record_handle h, char axis)
Returns the torque.
bool gclib_data_record_stepper_mode(gclib_data_record_handle h, char axis)
Returns true if axis is configured as a stepper motor.
uint8_t gclib_data_record_halls(gclib_data_record_handle h, char axis)
Returns the hall state.
bool gclib_data_record_peak_current(gclib_data_record_handle h, char axis)
Returns true if the amplifier for this axis has triggered a peak current error.
gclib_result gclib_close(gclib_handle *h)
Close connection to controller.
gclib_result gclib_assign_ip(const char *mac, const char *ip)
Assign IP to a controller.
gclib_result gclib_address(gclib_handle h, char *address, size_t len)
Get connection address.
gclib_result gclib_set_baud_rate(gclib_handle h, size_t baud_rate)
Set baud rate of serial connection.
gclib_result gclib_ip_requests(char *ip_requests, size_t len)
Show MAC address, model, and serial of all controllers requesting IP addresses, comma-separated....
gclib_result gclib_addresses(char *addresses, size_t len)
Show address, model, and serial of detected controllers, where available. Detected controllers are ne...
const char * gclib_error(gclib_handle h)
Get library error string.
gclib_result gclib_open(gclib_handle *h, const char *address)
Open a connection to a controller.
void gclib_force_gcaps(bool on)
Force future library calls to use either gcaps or direct connections.
gclib_result gclib_connection_type(gclib_handle h, gclib_connection_t *type)
Get connection type.
@ GCLIB_SERIAL
Definition gclib.h:304
@ GCLIB_ETHERNET
Definition gclib.h:303
@ GCLIB_PCI
Definition gclib.h:305
gclib_result gclib_command(gclib_handle h, const char *command, char *buf, size_t len)
Issues a command to the controller and provides the response.
gclib_result gclib_serial_number(gclib_handle h, uint32_t *serial_number)
Get serial number from controller.
gclib_result gclib_revision_information(gclib_handle h, char *rev_info, size_t len)
Get revision information (^R^V) from controller.
gclib_result gclib_published(char *name, size_t len)
Provides published status of local gcaps server.
gclib_result gclib_set_server(const char *name)
Set gcaps server.
gclib_result gclib_list_servers(char *servers, size_t len)
List available gcaps servers separated by newline.
gclib_result gclib_server(char *name, size_t len)
Current gcaps server.
gclib_result gclib_set_published(const char *name)
Set published status of local gcaps server.
gclib_result gclib_set_program(gclib_handle h, const char *program, const char *insert)
Set the program on the controller.
gclib_result gclib_set_array(gclib_handle h, const char *name, const char *buf, size_t start, size_t end)
Set an array on the controller.
gclib_result gclib_array(gclib_handle h, const char *name, char *buf, size_t len, size_t start, size_t end)
Get an array from the controller.
gclib_result gclib_set_firmware(gclib_handle h, const char *file_path)
Set the firmware on the controller.
gclib_result gclib_program(gclib_handle h, char *program, size_t len)
Get the controller's current program.
gclib_result gclib_interrupt(gclib_handle h, gclib_interrupt_t *interrupt, int timeout)
Get a queued interrupt, or wait up to timeout ms for one to arrive.
gclib_result gclib_message(gclib_handle h, char *message, size_t len, int timeout)
Get a queued unsolicited message, or wait up to timeout ms for one to arrive.
gclib_result gclib_subscribe_data_records(gclib_handle h, void(callback)(void *user_data, gclib_data_record_handle data_record), void *user_data)
Subscribe to data records.
gclib_result gclib_set_interrupts(gclib_handle h, gclib_interrupt_type interrupt_mask, gclib_axis_flags motion_complete_axes, gclib_digital_input_flags digital_inputs)
Configure which interrupts will be generated by the controller.
gclib_result gclib_subscribe_interrupts(gclib_handle h, void(callback)(void *user_data, gclib_interrupt_t interrupt), void *user_data)
Subscribe to interrupts.
gclib_result gclib_unsubscribe(gclib_handle h, void *callback)
Unsubscribe from messages, interrupts, data records, or progress.
gclib_result gclib_set_data_records(gclib_handle h, size_t period_ms)
Configure controller data records.
gclib_result gclib_subscribe_progress(gclib_handle h, void(callback)(void *user_data, size_t current, size_t max), void *user_data)
Subscribe to progress for gclib_set_program(), gclib_set_array(), and gclib_set_firmware().
gclib_result gclib_subscribe_messages(gclib_handle h, void(callback)(void *user_data, const char *message), void *user_data)
Subscribe to unsolicited messages.
gclib_result gclib_data_record(gclib_handle h, gclib_data_record_handle *data_record, int timeout)
Get a queued data record, or wait up to timeout ms for one to arrive.
void * gclib_data_record_handle
A handle to a data record, for use in Data Record API calls.
Definition gclib.h:25
gclib_digital_input_flags
Flags to enable or disable GCLIB_DIGITAL_INPUT_LOW interrupts per digital input, for use in gclib_set...
Definition gclib.h:65
gclib_axis_flags
Flags for building an axis mask, for example in gclib_set_interrupts().
Definition gclib.h:78
gclib_result gclib_gcaps_version(char *gcaps_version, size_t len)
Get library version used by current gcaps server.
gclib_result gclib_version(char *version, size_t len)
Get library version.
gclib_interrupt_type
Definition gclib.h:41
struct gclib_context * gclib_handle
A handle to an open connection given by gclib_open() for use in future API calls.
Definition gclib.h:23
gclib_result
Definition gclib.h:29
struct gclib_interrupt_t gclib_interrupt_t
An interrupt generated by the controller.
@ GCLIB_USER_INTERRUPT
Definition gclib.h:43
@ GCLIB_PROGRAM_STOPPED
If multiple threads are running, this interrupt is only triggered when all threads are finished.
Definition gclib.h:49
@ GCLIB_EXCESS_POSITION_ERROR
Must be reenabled with gclib_set_interrupts() after occurrence.
Definition gclib.h:46
@ GCLIB_WATCHDOG_TIMER
Definition gclib.h:48
@ GCLIB_ALL_INTERRUPTS
Definition gclib.h:52
@ GCLIB_ALL_AXES_MOTION_COMPLETE
Definition gclib.h:45
@ GCLIB_COMMAND_DONE
Definition gclib.h:50
@ GCLIB_MOTION_COMPLETE
Definition gclib.h:44
@ GCLIB_NO_INTERRUPTS
Definition gclib.h:42
@ GCLIB_LIMIT_SWITCH
Must be reenabled with gclib_set_interrupts() after each occurrence.
Definition gclib.h:47
@ GCLIB_DIGITAL_INPUT_LOW
Must be reenabled with gclib_set_interrupts() after each occurrence.
Definition gclib.h:51
@ GCLIB_INTERNAL_ERROR
Definition gclib.h:32
@ GCLIB_INVALID_ARGUMENT
Definition gclib.h:31
@ GCLIB_COMMAND_ERROR
Definition gclib.h:34
@ GCLIB_NOT_CONNECTED
Definition gclib.h:36
@ GCLIB_BUFFER_TOO_SMALL
Definition gclib.h:35
@ GCLIB_NOT_SUBSCRIBED
Definition gclib.h:37
@ GCLIB_TIMEOUT
Definition gclib.h:33
bool gclib_data_record_coordinated_move_slewing(gclib_data_record_handle h, char plane)
Returns true if slewing.
uint16_t gclib_data_record_coordinated_move_status(gclib_data_record_handle h, char plane)
Returns the coordinated move status word.
bool gclib_data_record_coordinated_move_stopping(gclib_data_record_handle h, char plane)
Returns true if stopping.
uint16_t gclib_data_record_coordinated_move_segment_count(gclib_data_record_handle h, char plane)
Returns the segment count for the current move.
uint16_t gclib_data_record_coordinated_move_buffer_available(gclib_data_record_handle h, char plane)
Returns the available buffer space.
int32_t gclib_data_record_coordinated_move_distance(gclib_data_record_handle h, char plane)
Returns the distance covered in the current move.
bool gclib_data_record_coordinated_move_moving(gclib_data_record_handle h, char plane)
Returns true if moving.
bool gclib_data_record_coordinated_move_final_deceleration(gclib_data_record_handle h, char plane)
Returns true if in final deceleration.
uint8_t gclib_data_record_input_bank(gclib_data_record_handle h, size_t index)
Get a bank of inputs.
uint8_t gclib_data_record_error_code(gclib_data_record_handle h)
Get the error code.
gclib_ethernet_status_t gclib_data_record_ethernet_status(gclib_data_record_handle h, char handle)
Get ethernet handle status.
gclib_result gclib_data_record_bytes(gclib_data_record_handle h, char *data_record, size_t len)
Copy data record to user buffer.
bool gclib_data_record_output(gclib_data_record_handle h, size_t index)
Get an output.
uint32_t gclib_data_record_contour_segment_count(gclib_data_record_handle h)
Get the contour segment count.
bool gclib_data_record_thread_running(gclib_data_record_handle h, size_t thread)
Returns true if a given thread is running.
bool gclib_data_record_input(gclib_data_record_handle h, size_t index)
Get an input.
uint16_t gclib_data_record_contour_buffer_available(gclib_data_record_handle h)
Get remaining contour buffer.
uint8_t gclib_data_record_output_bank(gclib_data_record_handle h, size_t index)
Get a bank of outputs.
uint16_t gclib_data_record_sample(gclib_data_record_handle h)
The sample in which this data record was generated.
@ GCLIB_CONTOUR
Definition gclib.h:634
@ GCLIB_LINEAR_MOVE
Definition gclib.h:641
@ GCLIB_POSITION_RELATIVE
Definition gclib.h:636
@ GCLIB_HOME
Definition gclib.h:639
@ GCLIB_FIND_EDGE
Definition gclib.h:637
@ GCLIB_VECTOR_MOVE
Definition gclib.h:640
@ GCLIB_NO_MOTION
Definition gclib.h:633
@ GCLIB_POSITION_ABSOLUTE
Definition gclib.h:635
@ GCLIB_FIND_INDEX
Definition gclib.h:638
@ UDP_MASTER
Definition gclib.h:649
@ TCP_MASTER
Definition gclib.h:650
@ HANDLE_FREE
Definition gclib.h:646
@ UDP_SLAVE
Definition gclib.h:647
@ ESTABLISHING_TCP
Definition gclib.h:652
@ TCP_SLAVE
Definition gclib.h:648
@ ESTABLISHING_UDP
Definition gclib.h:651
Definition gclib.hpp:9
void set_published(std::string name={})
Publish local gcaps server as name, or unpublish if name is empty.
Definition gclib.hpp:300
void set_server(std::string name={})
Definition gclib.hpp:296
std::string published()
Return name of local gcaps server, or an empty string if unpublished.
Definition gclib.hpp:298
std::string ip_requests()
Show MAC address, model, and serial of all controllers requesting IP addresses. Detected controllers ...
Definition gclib.hpp:273
ConnectionType
Returned by Controller::connection_type().
Definition gclib.hpp:55
@ Ethernet
Definition gclib.hpp:56
@ Pci
Definition gclib.hpp:58
@ Serial
Definition gclib.hpp:57
std::string list_servers()
List available gcaps servers separated by newline.
Definition gclib.hpp:291
std::string server()
Current gcaps server, or an empty string if connected to the local gcaps server.
Definition gclib.hpp:293
std::string version()
Installed gclib version.
Definition gclib.hpp:242
std::string gcaps_version()
Installed gcaps version, as reported by current gcaps server.
Definition gclib.hpp:289
void force_gcaps(bool on)
Force future library calls to use either gcaps or direct connections.
Definition gclib.hpp:287
void assign_ip(std::string mac, std::string ip)
Definition gclib.hpp:274
std::string addresses()
Show address, model, and serial of detected controllers, where available. Detected controllers are ne...
Definition gclib.hpp:261
Holds amplifier-specific data record fields. Provided by DataRecord.amp().
Definition gclib.hpp:129
Amp(gclib_data_record_handle h, size_t amp)
Definition gclib.hpp:130
Holds axis-specific data record fields. Provided by DataRecord.axis().
Definition gclib.hpp:141
ModeOfMotion mode_of_motion()
Definition gclib.hpp:159
int32_t position_error()
Definition gclib.hpp:172
int32_t reference_position()
Definition gclib.hpp:170
Axis(gclib_data_record_handle h, char axis)
Definition gclib.hpp:142
bool negative_direction_move()
Definition gclib.hpp:160
Holds coordinated move specific data record fields. Provided by DataRecord.coordinated_move().
Definition gclib.hpp:186
CoordinatedMove(gclib_data_record_handle h, char plane)
Definition gclib.hpp:187
CoordinatedMove coordinated_move(char plane)
Get an instance of DataRecord.CoordinatedMove, which provides CM-specific data record fields.
Definition gclib.hpp:236
uint16_t sample()
Definition gclib.hpp:200
Axis axis(char axis)
Get an instance of DataRecord.Axis, which provides axis-specific data record fields.
Definition gclib.hpp:235
EthernetStatus ethernet_status(char handle)
Definition gclib.hpp:223
std::bitset< 8 > input_bank(size_t index)
Definition gclib.hpp:214
uint32_t contour_segment_count()
Definition gclib.hpp:217
uint8_t error_code()
Definition gclib.hpp:216
bool thread_running(size_t thread)
Definition gclib.hpp:219
uint16_t contour_buffer_available()
Definition gclib.hpp:218
std::vector< uint8_t > bytes()
Get data record as raw bytes.
Definition gclib.hpp:229
Amp amp(size_t amp)
Get an instance of DataRecord.Amp, which provides amplifier-specific data record fields.
Definition gclib.hpp:234
DataRecord(gclib_data_record_handle h)
Definition gclib.hpp:116
std::bitset< 8 > output_bank(size_t index)
Definition gclib.hpp:215
bool output(size_t index)
Definition gclib.hpp:213
bool input(size_t index)
Definition gclib.hpp:208
@ ProgramStopped
If multiple threads are running, this interrupt is only triggered when all threads are finished.
Definition gclib.hpp:100
@ AllAxesMotionComplete
Definition gclib.hpp:96
@ DigitalInputLow
Must be reenabled with set_interrupts() after each occurrence.
Definition gclib.hpp:102
@ LimitSwitch
Must be reenabled with set_interrupts() after each occurrence.
Definition gclib.hpp:98
@ ExcessPositionError
Must be reenabled with set_interrupts() after occurrence.
Definition gclib.hpp:97
uint8_t digital_input
If type is DigitalInputLow, holds the digital input that triggered the interrupt.
Definition gclib.hpp:109
uint8_t user_interrupt
If type is UserInterrupt, holds the user interrupt that was triggered.
Definition gclib.hpp:110
Interrupt(gclib_interrupt_t interrupt)
Definition gclib.hpp:89
char axis
If type is MotionComplete, holds the axis that triggered the interrupt.
Definition gclib.hpp:108
uint8_t status
The raw status byte generated by the controller. See the EI command reference for all possible values...
Definition gclib.hpp:112
An interrupt generated by the controller.
Definition gclib.h:55