GeminiMotorDrive.drivers¶
Module for the driver classes for the drives.
ASCII_RS232 (port[, check_echo, ...]) |
ASCII RS232 comm. |
ASCII_RS232¶
-
class
GeminiMotorDrive.drivers.
ASCII_RS232
(port, check_echo=True, writeTimeout=1.0, interCharTimeout=0.002)[source]¶ Bases:
object
ASCII RS232 comm. driver for a Parker Motion Gemini drive.
Communications driver to talk to a Parker Motion Gemini drive in ASCII mode over RS232.
Parameters: - port (serial port string) – The serial port (RS232) that the Gemini drive is connected to.
- check_echo (bool, optional) – Whether the echoing of the commands as they are being written to the drive should be used to correct mistakes in what the drive is seeing or not as the default.
- writeTimout (float, optional) –
The write timeout for the RS232 port. See
serial.Serial
. - interCharTimeout (float or None, optional) –
The inter-character timeout for writing on the RS232 port.
None
disables. Seeserial.Serial
.
Raises: serial.SerialException
– If port does not correspond to an available RS232 port or can’t be opened.Notes
The ASCII communications settings of the Gemini drive are changed while this object is connected and are returned to the default values when this object is deleted. Thus, the values of the communications settings before this object is created are lost.
See also
-
command_error
(response)[source]¶ Checks whether a command produced an error.
Checks whether a command procuded an error based on its processed response. The two types of errors are an error returned by the drive and the command that the drive received being different than the one that was sent (error in transmission).
Parameters: response (processed response (list)) – The processed response list
for the command that was executed.Returns: error (bool) – True
if there was an error andFalse
otherwise.
-
send_command
(command, immediate=False, timeout=1.0, max_retries=0, eor=('\n', '\n- '))[source]¶ Sends a single command to the drive and returns output.
Takes a single given command, sanitizes it, sends it to the drive, reads the response, and returns the processed response. The command is first sanitized by removing comments, extra whitespace, and newline characters. If immediate is set, the command is made to be an immediate command. Note, the command is NOT checked for validity. If the drive returns an error, the command is re-executed up to max_tries more times. The response from the final execution is processed and returned. The response from the drive is broken down into the echoed command (drive echoes it back), any error returned by the drive (leading ‘*’ is stripped), and the different lines of the response; which are all returned.
Parameters: - command (str) – The command to send to the Gemini drive.
- immediate (bool, optional) – Whether to make it so the command is executed immediately or not.
- timeout (float or None, optional) –
Optional timeout in seconds to use when reading the
response. A negative value or
None
indicates that the an infinite timeout should be used. - max_retries (int, optional) – Maximum number of retries to do per command in the case of errors.
- eor (str or iterable of str, optional) –
str
or an iterable ofstr
that denote the allowed End Of Response. For most commands, it should be('\n', '\n- ')
, but for running a program, it should be'*END\n'
. The default is('\n', '\n- ')
.
Returns: output (list) – A 5-element
list
. The elements, in order, are the sanitized command (str
), the full response (str
), the echoed command (str
), any error response (None
if none, or thestr
of the error), and the lines of the response that are not the echo or error line (list
ofstr
with newlines stripped).See also
send_commands()
- Send multiple commands.
Examples
Simple command energizing the motor with no response and no errors.
>>> from GeminiMotorDrive.drivers import ASCII_RS232 >>> ar = ASCII_RS232('/dev/ttyS1') >>> ar.send_command('DRIVE1', immediate=False, timeout=1.0) ['DRIVE1', 'DRIVE1\r\r\n', 'DRIVE1', None, []]
Same command but made immediate.
>>> from GeminiMotorDrive.drivers import ASCII_RS232 >>> ar = ASCII_RS232('/dev/ttyS1') >>> ar.send_command('DRIVE1', immediate=True, timeout=1.0) ['!DRIVE1', '!DRIVE1\r\r\n', '!DRIVE1', None, []]
Same command with a typo.
>>> from GeminiMotorDrive.drivers import ASCII_RS232 >>> ar = ASCII_RS232('/dev/ttyS1') >>> ar.send_command('DRIV1', immediate=False, timeout=1.0) ['DRIV1', 'DRIV1\r*UNDEFINED_LABEL\r\r\n', 'DRIV1', 'UNDEFINED_LABEL', []]
Simple command asking whether the motor is energized or not.
>>> from GeminiMotorDrive.drivers import ASCII_RS232 >>> ar = ASCII_RS232('/dev/ttyS1') >>> ar.send_command('DRIVE', immediate=False, timeout=1.0) ['DRIVE', 'DRIVE\r*DRIVE1\r\r\n', 'DRIVE', None, ['*DRIVE1']]
-
send_commands
(commands, timeout=1.0, max_retries=1, eor=('\n', '\n- '))[source]¶ Send a sequence of commands to the drive and collect output.
Takes a sequence of many commands and executes them one by one till either all are executed or one runs out of retries (max_retries). Retries are optionally performed if a command’s repsonse indicates that there was an error. Remaining commands are not executed. The processed output of the final execution (last try or retry) of each command that was actually executed is returned.
This function basically feeds commands one by one to
send_command
and collates the outputs.Parameters: - commands (iterable of str) –
Iterable of commands to send to the drive. Each command must
be an
str
. - timeout (float or None, optional) –
Optional timeout in seconds to use when reading the
response. A negative value or
None
indicates that the an infinite timeout should be used. - max_retries (int, optional) – Maximum number of retries to do per command in the case of errors.
- eor (str or iterable of str, optional) –
End Of Resonse. An EOR is either a
str
or an iterable ofstr
that denote the possible endings of a response. ‘eor’ can be a single EOR, in which case it is used for all commands, or it can be an iterable of EOR to use for each individual command. For most commands, it should be('\n', '\n- ')
, but for running a program, it should be'*END\n'
. The default is('\n', '\n- ')
.
Returns: outputs (list of lists) –
list
composed of the processed responses of each command in the order that they were done up to and including the last command executed. Seesend_command
for the format of processed responses.See also
send_command()
- Send a single command.
Examples
A sequence of commands to energize the motor, move it a bit away from the starting position, and then do 4 forward/reverse cycles, and de-energize the motor. DO NOT try these specific movement distances without checking that the motion won’t damage something (very motor and application specific).
>>> from GeminiMotorDrive.drivers import ASCII_RS232 >>> ra = ASCII_RS232('/dev/ttyS1') >>> ra.send_commands(['DRIVE1', 'D-10000', 'GO'] ... + ['D-10000','GO','D10000','GO']*4 ... + [ 'DRIVE0']) [['DRIVE1', 'DRIVE1\r', 'DRIVE1', None, []], ['D-10000', 'D-10000\r', 'D-10000', None, []], ['GO', 'GO\r', 'GO', None, []], ['D-10000', 'D-10000\r', 'D-10000', None, []], ['GO', 'GO\r', 'GO', None, []], ['D10000', 'D10000\r', 'D10000', None, []], ['GO', 'GO\r', 'GO', None, []], ['D-10000', 'D-10000\r', 'D-10000', None, []], ['GO', 'GO\r', 'GO', None, []], ['D10000', 'D10000\r', 'D10000', None, []], ['GO', 'GO\r', 'GO', None, []], ['D-10000', 'D-10000\r', 'D-10000', None, []], ['GO', 'GO\r', 'GO', None, []], ['D10000', 'D10000\r', 'D10000', None, []], ['GO', 'GO\r', 'GO', None, []], ['D-10000', 'D-10000\r', 'D-10000', None, []], ['GO', 'GO\r', 'GO', None, []], ['D10000', 'D10000\r', 'D10000', None, []], ['GO', 'GO\r', 'GO', None, []], ['DRIVE0', 'DRIVE0\r', 'DRIVE0', None, []]]
- commands (iterable of str) –
Iterable of commands to send to the drive. Each command must
be an