gclib 2.5.0
Galil Communications Library
Loading...
Searching...
No Matches
Controller Class Reference

Manages a connection to a controller. More...

#include <gclib.hpp>

Public Member Functions

 Controller (std::string address)
 Open a connection to a controller reported by addresses().
 Controller (std::string address, size_t baud_rate)
 Open a serial connection to a controller reported by addresses().
 ~Controller ()
void open ()
 Open the connection. If connection is already open, it will be closed and reopened.
void close ()
std::string address ()
 Returns the address that was used to connect to the controller.
ConnectionType connection_type ()
 Returns the type of address that was used to connect to the controller.
std::string revision_information ()
 Returns controller ^R^V output.
uint32_t serial_number ()
template<typename T = std::string>
command (std::string command)
 Issues a command to the controller and provides the response.
std::string program ()
void set_program (std::string program, std::string insert="")
std::string array (std::string name, size_t start=0, size_t end=0)
void set_array (std::string name, std::string array, size_t start=0, size_t end=0)
void set_firmware (std::string file_path)
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.
void set_data_records (size_t period_ms)
 Configure controller data records.
void subscribe_messages (std::function< void(std::string message)> callback)
 Subscribe to unsolicited messages.
void subscribe_messages ()
 Subscribe to unsolicited messages.
void subscribe_interrupts (std::function< void(Interrupt interrupt)> callback)
 Subscribe to interrupts.
void subscribe_interrupts ()
 Subscribe to interrupts.
void subscribe_data_records (std::function< void(DataRecord data_record)> callback)
 Subscribe to data records.
void subscribe_data_records ()
 Subscribe to data records.
void subscribe_progress (std::function< void(size_t current, size_t max)> callback)
 Register a progress callback.
void unsubscribe_messages ()
void unsubscribe_interrupts ()
void unsubscribe_data_records ()
void unsubscribe_progress ()
std::string message (int timeout=-1)
Interrupt interrupt (int timeout=-1)
DataRecord data_record (int timeout=-1)

Detailed Description

Manages a connection to a controller.

Definition at line 303 of file gclib.hpp.

Constructor & Destructor Documentation

◆ Controller() [1/2]

Controller ( std::string address)
inline

Open a connection to a controller reported by addresses().

Definition at line 306 of file gclib.hpp.

◆ Controller() [2/2]

Controller ( std::string address,
size_t baud_rate )
inline

Open a serial connection to a controller reported by addresses().

Definition at line 311 of file gclib.hpp.

◆ ~Controller()

~Controller ( )
inline

Definition at line 315 of file gclib.hpp.

Member Function Documentation

◆ open()

void open ( )
inline

Open the connection. If connection is already open, it will be closed and reopened.

Definition at line 318 of file gclib.hpp.

◆ close()

void close ( )
inline

Definition at line 324 of file gclib.hpp.

◆ address()

std::string address ( )
inline

Returns the address that was used to connect to the controller.

Definition at line 327 of file gclib.hpp.

◆ connection_type()

ConnectionType connection_type ( )
inline

Returns the type of address that was used to connect to the controller.

Definition at line 329 of file gclib.hpp.

◆ revision_information()

std::string revision_information ( )
inline

Returns controller ^R^V output.

Definition at line 332 of file gclib.hpp.

◆ serial_number()

uint32_t serial_number ( )
inline

Definition at line 333 of file gclib.hpp.

◆ command()

template<typename T = std::string>
T command ( std::string command)
inline

Issues a command to the controller and provides the response.

Note that a single command cannot be longer than 80 characters, similar to a program line.

Parameters
commandCommand to be sent to the controller. Will be terminated with a carriage return.
Returns
The controller response.

Definition at line 345 of file gclib.hpp.

◆ program()

std::string program ( )
inline

Definition at line 354 of file gclib.hpp.

◆ set_program()

void set_program ( std::string program,
std::string insert = "" )
inline

Definition at line 355 of file gclib.hpp.

◆ array()

std::string array ( std::string name,
size_t start = 0,
size_t end = 0 )
inline

Definition at line 356 of file gclib.hpp.

◆ set_array()

void set_array ( std::string name,
std::string array,
size_t start = 0,
size_t end = 0 )
inline

Definition at line 357 of file gclib.hpp.

◆ set_firmware()

void set_firmware ( std::string file_path)
inline

Definition at line 358 of file gclib.hpp.

◆ set_interrupts()

void set_interrupts ( Interrupt::Type mask,
std::bitset< 8 > motion_complete_axes = 0,
std::bitset< 8 > digital_inputs = 0 )
inline

Configure which interrupts will be generated by the controller.

By default, the controller will not generate any interrupts.

Controllers can be configured to send only an exact list of desired interrupts, to avoid unnecessary processing and network traffic.

Example usage:

controller.set_interrupts(AllInterrupts); // Enable all interrupts.
controller.set_interrupts(
MotionComplete | DigitalInputLow, // Only enable two interrupts
{0, 7}, // Only trigger MotionComplete on axis A or F
{0, 3}); // Only trigger DigitalInputLow on digital input 1 and 4.
controller.set_interrupts(); // Disable interrupts

See subscribe_interrupts() to enable receiving interrupts from the controller.

Parameters
interrupt_maskBitmask of desired interrupts. Use ::NoInterrupts (0) to disable interrupts. Note that User Interrupts cannot be disabled.
axis_maskWhen ::MotionComplete is in interrupt_mask, this axis mask controls which axes will trigger a ::MotionComplete interrupt. If 0 (default), all axes will be selected.
digital_input_maskWhen ::DigitalInputLow is in interrupt_mask, this bitmask selects which digital inputs will trigger an interrupt. If 0 (default), all digital inputs will be selected.

Definition at line 390 of file gclib.hpp.

◆ set_data_records()

void set_data_records ( size_t period_ms)
inline

Configure controller data records.

By default, data records are not sent by the controller.

See subscribe_data_records() to enable receiving data records from the controller.

Parameters
period_msPeriod (in milliseconds) between data records. Pass 0 (default) to disable data records.

Definition at line 403 of file gclib.hpp.

◆ subscribe_messages() [1/2]

void subscribe_messages ( std::function< void(std::string message)> callback)
inline

Subscribe to unsolicited messages.

This method registers a callback to be run every time an unsolicited message is received from the controller.

Note
The callback will be invoked on a separate, dedicated thread. Be careful when accessing any shared state.

On ethernet connections, a handle is opened for unsolicited data (if not already open) and the controller is configured to use it for messages.

Parameters
callbackA callback function, which will be invoked each time a message arrives. Replaces any previously set message callback.

Definition at line 420 of file gclib.hpp.

◆ subscribe_messages() [2/2]

void subscribe_messages ( )
inline

Subscribe to unsolicited messages.

This method begins queueing unsolicited messages for later retrieval by message().

On ethernet connections, a handle is opened for unsolicited data (if not already open) and the controller is configured to use it for messages.

Definition at line 433 of file gclib.hpp.

◆ subscribe_interrupts() [1/2]

void subscribe_interrupts ( std::function< void(Interrupt interrupt)> callback)
inline

Subscribe to interrupts.

This method registers a callback to be run every time an interrupt is received from the controller. See set_interrupts() to enable and configure controller interrupts.

Note
The callback will be invoked on a separate, dedicated thread. Be careful when accessing any shared state.

On ethernet connections, a handle is opened for unsolicited data (if not already open) and the controller is configured to use it for interrupts.

Parameters
callbackA callback function, which will be invoked each time an interrupt arrives. Replaces any previously set message callback.

Definition at line 453 of file gclib.hpp.

◆ subscribe_interrupts() [2/2]

void subscribe_interrupts ( )
inline

Subscribe to interrupts.

This method begins queueing unsolicited interrupts for later retrieval by interrupt().

See set_interrupts() to enable and configure controller interrupts.

On ethernet connections, a handle is opened for unsolicited data (if not already open) and the controller is configured to use it for interrupts.

Definition at line 469 of file gclib.hpp.

◆ subscribe_data_records() [1/2]

void subscribe_data_records ( std::function< void(DataRecord data_record)> callback)
inline

Subscribe to data records.

This method registers a callback to be run every time a data record is received from the controller. See set_data_records() to enable data records and configure how often they will be generated by the controller.

Note
The callback will be invoked on a separate, dedicated thread. Be careful when accessing any shared state.

On ethernet connections, a handle is opened for unsolicited data (if not already open) and the controller is configured to use it for data records.

Parameters
callbackA callback function, which will be invoked each time a data record arrives. Replaces any previously set message callback.

Definition at line 489 of file gclib.hpp.

◆ subscribe_data_records() [2/2]

void subscribe_data_records ( )
inline

Subscribe to data records.

This method begins queueing unsolicited interrupts for later retrieval by data_record().

On ethernet connections, a handle is opened for unsolicited data (if not already open) and the controller is configured to use it for data records.

Definition at line 502 of file gclib.hpp.

◆ subscribe_progress()

void subscribe_progress ( std::function< void(size_t current, size_t max)> callback)
inline

Register a progress callback.

This method registers a callback to be run every time data is written to the controller during a set_firmware, set_array, or set_program call.

Note
The callback will be invoked on a separate, dedicated thread. Be careful when accessing any shared state.
Parameters
callbackA callback function, which will be invoked each time data is written to the controller. Replaces any previously set message callback.

Definition at line 518 of file gclib.hpp.

◆ unsubscribe_messages()

void unsubscribe_messages ( )
inline

Definition at line 523 of file gclib.hpp.

◆ unsubscribe_interrupts()

void unsubscribe_interrupts ( )
inline

Definition at line 524 of file gclib.hpp.

◆ unsubscribe_data_records()

void unsubscribe_data_records ( )
inline

Definition at line 525 of file gclib.hpp.

◆ unsubscribe_progress()

void unsubscribe_progress ( )
inline

Definition at line 526 of file gclib.hpp.

◆ message()

std::string message ( int timeout = -1)
inline

Get a queued message, or wait up to timeout ms for one to arrive.

Parameters
timeoutTimeout value in milliseconds. If -1, wait forever.

Definition at line 530 of file gclib.hpp.

◆ interrupt()

Interrupt interrupt ( int timeout = -1)
inline

Get a queued interrupt, or wait up to timeout ms for one to arrive.

Parameters
timeoutTimeout value in milliseconds. If -1, wait forever.

Definition at line 533 of file gclib.hpp.

◆ data_record()

DataRecord data_record ( int timeout = -1)
inline

Get a queued data record, or wait up to timeout ms for one to arrive.

Parameters
timeoutTimeout value in milliseconds. If -1, wait forever.

Definition at line 536 of file gclib.hpp.


The documentation for this class was generated from the following file: