API

PTHat class

class pthat.PTHat(command_type='I', command_id=0, serial_device='/dev/ttyS0', baud_rate=115200, test_mode=False)

Bases: object

class PTHat

This is the main Pulse Train Hat class. It is used to run commands against the PTHat and to run general commands.

Parameters
  • command_type (str, optional) – type of command, I = instant, B = buffered - defaults to I

  • command_id (int, optional) – optional command ID, 0-99 - defaults to 0

  • serial_device (str, optional) – path to the serial device - defaults to /dev/ttyS0

  • baud_rate (int, optional) – serial port baud rate - defaults to 115200

  • test_mode (boolean, optional) – if true then serial commands will not actually be sent - defaults to False

debug = False

Sets debug mode. This just prints additional information. This must be set directly

wait_delay = 0
Wait delay between commands - 0-9999 - This can be set directly.
  • Delay in milliseconds: 1000ms = 1 second delay,

  • Delay in microseconds: 1000us = 0.001 of a second

auto_send_command = False

Automatically send the command when command methods are called. This can be set directly.

command_type = 'I'
Type of command, instant or buffer. This can be set directly.
I = Instant or B = Buffer.
command_id = 0
Optional command ID. This can be set directly.
Any value between 0 and 99.
test_mode = False

This lets all methods to be run without actually sending them to the serial port. This can be set directly.

serial = None

The path to the serial device such as /dev/ttyS0. This can be set directly.

property motor_enabled
Specifies if the motor is enabled or not. Do not set this as it is set internally.
Read-only property
Returns

True or False

Return type

bool

property received_command_replies_enabled
If received command replies are enabled or not.
Read-only property
Returns

True or False

Return type

bool

property completed_command_replies_enabled
If completed command replies are enabled or not.
Read-only property
Returns

True or False

Return type

bool

property command_end
Serial command ending character. Set to *.
Read-only property
Returns

command end character

Return type

str

property version
Version of this API.
Read-only property
Returns

version number

Return type

str

init_serial_interface(write_timeout=2, timeout=2)

Initializes the serial port

Parameters
  • write_timeout – write timeout - default 2

  • timeout – read timeout - default 2

Returns

serial port object

Return type

class:serial.Serial

send_command(command)

This method sends the command to the serial port asynchronously

Parameters

command – command to send

get_all_responses()

This method gets all responses until no more can be returned

Returns

a list of responses

Return type

list

get_response()

This method gets a single response. A response is the value returned up to an *.

Returns

a single response as a string

Return type

str

parse_responses(responses)

Parse the list of responses and set the various values in the class. Returns responses that were not parsed as some responses may come from the other classes such as Axis or AUX.

Parameters

responses – list of responses to parse

Todo

finish parsing

get_io_port_status()

When this request is sent, it will return the state of the Emergency Stop input port and each of the Limit Switch input ports. This allows them to be used as general inputs when limits disabled.

Returns

the command to send to the serial port

Return type

str

Command

Byte 1

Byte 2-3

Byte 4-5

Byte 6

I

00

LI

*


Command breakdown

Byte

Setting

Description

Byte 1

I=Instant Command
B=Buffer Command

Sets command to either Instant or Buffer.

Byte 2-3

0-99

Optional Command ID

Byte 4-5

LI = Port Status

Request current Port Status

Byte 6

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command and also when it has completed a command. In this case the received command will be sent back along with the state of the ES/Limit inputs and then completed command. If the Command sent ID number was set for bytes 2-3, then this will be returned in the reply.

IO Port Status Received *Result*

IO Port Status Completed

RI00LI**Result*

CI00LI*

Result will show as
L11111*
Bit5=ES input
Bit4=X Limit input
Bit3=Y Limit input
Bit2=Z Limit input
Bit1=E Limit input
set_wait_delay(period='W', delay=None)

When this request is sent, it causes a wait delay between buffered commands. Typical use is when switching one of the AUX outputs and you want to wait a while for it to complete. Note this is a wait and will pause the firmware routines, so do not use if a pulse train channel is running. You can set the Wait period to be in Milliseconds or Microseconds.

Parameters
  • period – period of time for the delay, W = Milliseconds, M = Microseconds - default W

  • delay – length of delay - default 0

Returns

the command to send to the serial port

Return type

str

Command

Byte 1

Byte 2-3

Byte 4-5

Byte 6-9

Byte 10

I

00

WW

1000

*


Command breakdown

Byte

Setting

Description

Byte 1

I=Instant Command B=Buffer Command

Sets command to either Instant or Buffer.

Byte 2-3

0-99

Optional Command ID

Byte 4-5

WW = Milliseconds
WM = Microseconds

Set Wait Delay in either Milliseconds or Microseconds

Byte 6-9

0-9999

Delay in ms so 1000ms = 1 second delay
Delay is us so 1000us = 0.001 of a second

Byte 10

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command and also when it has completed a command. If the Command sent ID number was set for bytes 2-3, then this will be returned in the reply.

Received

Completed

R00WW*

C00WW*

toggle_motor_enable_line()

Toggles the Motor Enable Line

Returns

the command to send to the serial port

Return type

str

Command

Byte 1

Byte 2-3

Byte 4-5

Byte 6

I

00

HT

*


Command breakdown

Byte

Setting

Description

Byte 1

I=Instant Command B=Buffer Command

Sets command to either Instant or Buffer.

Byte 2-3

0-99

Optional Command ID

Byte 4-5

HT

Toggle Motor Enable Line On/Off

Byte 6

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command and also when it has completed a command. If the Command sent ID number was set for bytes 2-3, then this will be returned in the reply.

Toggle Enable Command Received

Toggle Enable Command Completed

R00HT*

C00HT*

received_command_replies_on()

Turns on the Received Replies.

Returns

the command to send to the serial port

Return type

str

Command

Byte 1

Byte 2-3

Byte 4-5

Byte 6

I

00

R1

*


Command breakdown

Byte

Setting

Description

Byte 1

I=Instant Command B=Buffer Command

Sets command to either Instant or Buffer.

Byte 2-3

0-99

Optional Command ID

Byte 4-5

R1 = Turn On
R0 = Turn Off

Turn on/off Received Command Replies

Byte 6

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command and also when it has completed a command. If the Command sent ID number was set for bytes 2-3, then this will be returned in the reply.

Received Command Replies Turned On Received

Received Command Replies Turned Off Received

Received Command Replies Turned On Completed

Received Command Replies Turned Off Completed

RI00R1*

RI00R0*

CI00R1*

CI00R0*

received_command_replies_off()

Turns off the Received Replies.

Returns

the command to send to the serial port

Return type

str

Command

Byte 1

Byte 2-3

Byte 4-5

Byte 6

I

00

R0

*


Command breakdown

Byte

Setting

Description

Byte 1

I=Instant Command B=Buffer Command

Sets command to either Instant or Buffer.

Byte 2-3

0-99

Optional Command ID

Byte 4-5

R1 = Turn On
R0 = Turn Off

Turn on/off Received Command Replies

Byte 6

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command and also when it has completed a command. If the Command sent ID number was set for bytes 2-3, then this will be returned in the reply.

Received Command Replies Turned On Received

Received Command Replies Turned Off Received

Received Command Replies Turned On Completed

Received Command Replies Turned Off Completed

RI00R1*

RI00R0*

CI00R1*

CI00R0*

completed_command_replies_on()

Turns on the Completed Replies.

Returns

the command to send to the serial port

Return type

str

Command

Byte 1

Byte 2-3

Byte 4-5

Byte 6

I

00

G1

*


Command breakdown

Byte

Setting

Description

Byte 1

I=Instant Command B=Buffer Command

Sets command to either Instant or Buffer.

Byte 2-3

0-99

Optional Command ID

Byte 4-5

G1 = Turn On
G0 = Turn Off

Turn on/off Completed Command Replies

Byte 6

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command and also when it has completed a command. If the Command sent ID number was set for bytes 2-3, then this will be returned in the reply.

Received Command Replies Turned On Received

Received Command Replies Turned Off Received

Received Command Replies Turned On Completed

Received Command Replies Turned Off Completed

RI00G1*

RI00G0*

CI00G1*

CI00G0*

completed_command_replies_off()

Turns off the Completed Replies.

Returns

the command to send to the serial port

Return type

str

Command

Byte 1

Byte 2-3

Byte 4-5

Byte 6

I

00

G0

*


Command breakdown

Byte

Setting

Description

Byte 1

I=Instant Command B=Buffer Command

Sets command to either Instant or Buffer.

Byte 2-3

0-99

Optional Command ID

Byte 4-5

G1 = Turn On
G0 = Turn Off

Turn on/off Completed Command Replies

Byte 6

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command and also when it has completed a command. If the Command sent ID number was set for bytes 2-3, then this will be returned in the reply.

Received Command Replies Turned On Received

Received Command Replies Turned Off Received

Received Command Replies Turned On Completed

Received Command Replies Turned Off Completed

RI00G1*

RI00G0*

CI00G1*

CI00G0*

get_firmware_version()

Requests the Firmware Version from the PTHAT

Returns

the command to send to the serial port

Return type

str

Command

Byte 1

Byte 2-3

Byte 4-5

Byte 6

I

00

FW

*


Command breakdown

Byte

Setting

Description

Byte 1

I=Instant Command B=Buffer Command

Sets command to either Instant or Buffer.

Byte 2-3

0-99

Optional Command ID

Byte 4-5

FW

Request Firmware version

Byte 6

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command and also when it has completed a command. If the Command sent ID number was set for bytes 2-3, then this will be returned in the reply.

Firmware Command Received
*Version*

Firmware Command Completed Turned Off

RI00FW**Version*

CI00FW*

reset()

Resets the PTHAT back to turn on state and resets all pulse generators. Can be used in an emergency to close everything down and stop the pulse trains.

Returns

the command to send to the serial port

Return type

str

Command

Byte 1

Byte 2

N

*


Command breakdown

Byte

Setting

Description

Byte 1

N

Sends a Reset to the PTHAT.

Byte 2

*

End of Command


Reply

The PTHAT will send back a reply when it receives this command.

Reset Command Received

Reset Command Completed

Nothing

Nothing

initiate_buffer()

With all the Instant commands you can also send as buffered commands, but you will need to use a couple of extra commands to initiate the buffer first using the H0000* command.

Next you would need to decide how many commands you would like to store in the buffer (up to a maximum of 100 commands) before sending a Buffer Start command Z0000*.

With the release of Firmware V5.3 upwards you can now store 2000 commands in the buffer.

Buffering commands allow you to queue up your commands, so they execute one after the other and reduce latency between commands being executed. Instant commands apart from the Stop command cannot be sent while sending Buffered commands. We recommend to buffer around 20 commands before sending a Buffer Start command and then to send a new command when you get the Complete Reply back, until all your commands have been sent. When all commands have been executed from the buffer you will get a Buffer Empty Reply come back and you will have to Initiate the buffer again to start.

Initiate the buffer before sending any buffered commands.

Returns

the command to send to the serial port

Return type

str

Command

Byte 1

Byte 2-5

Byte 6

H

0000

*


Command breakdown

Byte

Setting

Description

Byte 1

H

Byte 2-5

0000

Byte 6

*

End of Command


Reply

The PTHAT will send back a reply when it receives this command.

Initiate Buffer Command Received

RBH000*

start_buffer()

Start executing buffered commands.

Returns

the command to send to the serial port

Return type

str

Command

Byte 1

Byte 2-5

Byte 6

Z

0000

*


Command breakdown

Byte

Setting

Description

Byte 1

Z

Byte 2-5

0000

Byte 6

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command.

Start Buffer Command Received

RBZ000*

start_buffer_loop()

*Available Firmware V5.3 upwards* Start executing buffered commands. With this command it will run through the buffered commands and when it gets to the last, it will go back to the first command and repeat all commands in a loop until a Stop command is sent.

Returns

the command to send to the serial port

Return type

str

Command

Byte 1

Byte 2-5

Byte 6

W

0000

*


Command breakdown

Byte

Setting

Description

Byte 1

W

Byte 2-5

0000

Byte 6

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command.

Start Buffer Loop Command Received

RBW000*

rpm_to_frequency(rpm, steps_per_rev, round_digits)
Convert RPM to frequency

Formula for calculating stepping motor speed.
Below is the RPM formula for stepping motor drives that use pulse signals to create motion.

RPM = a/360 * fz * 60

RPM = Revolutions per minute.
“a” = step angle (degrees of rotation per step)
“fz” = pulse frequency in hertz

step angle = degrees of rotation (360) / steps per revolution

Example 1: Drive step resolution is set for 1000 steps per revolution.
Find step angle: 360 (degrees of rotation) divided by 1000 (steps per revolution) =
.36 (degrees of rotation per step)
With input frequency of 1000hz, .36 / 360 * 1000 * 60 = 60 rpm

Example 2: Drive step resolution is set for 500 steps per revolution.
Find step angle: 360 (degrees of rotation) divided by 500 (steps per revolution) =
.72 (degrees of rotation per step)
With input frequency of 1000hz, .72 / 360 * 1000 * 60 = 120 rpm.

:param round_digits number of digits to round to :param rpm RPM to convert :param steps_per_rev steps per revolution :returns: frequency :rtype: float

frequency_to_rpm(frequency, steps_per_rev)
Convert frequency to RPM

Formula for calculating stepping motor speed.
Below is the frequency formula for stepping motor drives that use pulse signals to create motion.

To find required frequency to meet desired speed we must find Fz:
Fz = RPM / ( (a/360) * 60)

“fz” = pulse frequency in hertz
“a” = step angle (degrees of rotation per step)
RPM = Revolutions per minute.

step angle = degrees of rotation (360) / steps per revolution

Step 1. Divide step angle by 360: .36/360 = .001, then multiply by 60 (seconds) .001 * 60 = .06
Step 2. Divide desired speed by .06: Desired speed of 500 rpm’s. Therefore ; 500 / .06 = 8333.33
( 8333.33 is the frequency in hertz required to reach 500 rpm’s for drive set at 1000 steps per revolution)

:param frequency the frequency :param steps_per_rev steps per revolution :returns: RPM :rtype: int

calculate_pulse_count(steps_per_rev, total_revs)
Calculates the pulse count from the steps per revolution and the total revolutions desired.

Calculation is

pulse count = steps per rev * total revs
Parameters
  • steps_per_rev – steps per revolution

  • total_revs – total revolutions desired

Returns

pulse count

Return type

int

calculate_revolutions(steps_per_rev, pulse_count)
Calculates the number of revolutions from the steps per revolution and the pulse count.

Calculation is

total revs = pulse count / steps per rev
Parameters
  • steps_per_rev – steps per revolution

  • pulse_count – total pulse count

Returns

number of revolutions

Return type

int


Axis class

class pthat.Axis(axis, command_type='I', command_id=0, serial_device='/dev/ttyS0', baud_rate=115200, test_mode=False)

Bases: pthat.PTHat

class Axis

This is an Axis object that contains info about an axis. It inherits from PTHat so contains all functionality needed to communicate with the PTHat via the serial interface.

Parameters
  • command_type – type of command, I = instant, B = buffered - default I

  • command_id – optional command ID, 0-99 - default 0

  • serial_device – serial device - default /dev/ttyS0

  • baud_rate – serial port baud rate - default 115200

  • test_mode – if true then serial commands will not actually be sent - default False

frequency = 0.0

Frequency of the pulse train - 000000.000 - 500000.000. This can be set directly.

pulse_count = 0

Required pulse count - 0000000000 - 4294967295. This can be set directly.

direction = 0

Direction - 0 = clockwise (cw - forward), 1 = counter clockwise (ccw - reverse). This can be set directly.

start_ramp = 0

Start ramp - 0 = No Ramp, 1 = Ramp. This can be set directly.

finish_ramp = 0

Finish ramp - 0 = No Ramp, 1 = Ramp. This can be set directly.

ramp_divide = 0

Ramp divide. Divides target frequency by this value for each ramp increment. 0 - 255. This can be set directly.

ramp_pause = 0

Ramp pause between each ramp increment. 0 - 255. This can be set directly.

Link to ADC - 0 = No ADC, 1 = Link to ADC1, 2= Link to ADC2. This can be set directly.

enable_line_polarity = 0

Enable line polarity - 0 = Enable Line 0 Volts, 1 = Enable Line 5 Volts. This can be set directly.

pulse_count_change_direction = 0

Sets the Pulse count to change direction on the fly - 0000000000-4294967295. This can be set directly.

pulse_counts_sent_back = 0

Sets the Pulse count at which all Axis pulse counts will be sent back - 0000000000-4294967295. This can be set directly.

enable_disable_x_pulse_count_replies = 1
Enable/disable X axis pulse count replies. This can be set directly.
0=Disable X Axis Pulse Replies, 1=Enable X Axis Pulse Reply
enable_disable_y_pulse_count_replies = 0
Enable/disable Y axis pulse count replies. This can be set directly.
0=Disable Y Axis Pulse Replies, 1=Enable Y Axis Pulse Reply
enable_disable_z_pulse_count_replies = 0
Enable/disable Z axis pulse count replies. This can be set directly.
0=Disable Z Axis Pulse Replies, 1=Enable Z Axis Pulse Reply
enable_disable_e_pulse_count_replies = 0
Enable/disable E axis pulse count replies. This can be set directly.
0=Disable E Axis Pulse Replies, 1=Enable E Axis Pulse Reply
pause_all_return_x_pulse_count = 0
Pause all and send back pulse count replies for X axis. This can be set directly.
0=Disable X Axis Pulse Count Replies, 1=Enable X Axis Pulse Count Reply
pause_all_return_y_pulse_count = 0
Pause all and send back pulse count replies for Y axis.This can be set directly.
0=Disable X Axis Pulse Count Replies, 1=Enable X Axis Pulse Count Reply
pause_all_return_z_pulse_count = 0
Pause all and send back pulse count replies for Z axis. This can be set directly.
0=Disable X Axis Pulse Count Replies, 1=Enable X Axis Pulse Count Reply
pause_all_return_e_pulse_count = 0
Pause all and send back pulse count replies for E axis. This can be set directly.
0=Disable X Axis Pulse Count Replies, 1=Enable X Axis Pulse Count Reply
axis = 'X'
The axis this object represents. This can be set directly.
X, Y, Z or E or A (all)
set_axis(frequency=None, pulse_count=None, direction=None, start_ramp=None, finish_ramp=None, ramp_divide=None, ramp_pause=None, link_to_adc=None, enable_line_polarity=None)

This Command sets the properties of each Axis, but does not start the pulse train on that Axis. A Start Command must be used after to activate.

Parameters
  • frequency – frequency of the pulse train, 0.0-500000.0 - default 0.0 or self.frequency

  • pulse_count – required pulse count, 0-4294967295 - default 0 or self.pulse_count

  • direction – direction, 0 = forward (CW), 1 = reverse (CCW) - default 0 (forward - CW) or self.direction

  • start_ramp – start ramp, no ramp = 0, ramp = 1 - default 0 or self.start_ramp

  • finish_ramp – finish ramp, no ramp = 0, ramp = 1 - default 0 or self.finish_ramp

  • ramp_divide – ramp divide, 0-255, will divide the target frequency by this value for each ramp increment - default 0 or self.ramp_divide

  • ramp_pause – ramp pause between each ramp increment, 0-255 - default 0 or self.ramp_pause

  • link_to_adc – link to ADC, no ADC = 0, ADC1 = 1, ADC2 = 2 - default 0 or self.link_to_adc

  • enable_line_polarity – enable line polarity, enable line 0 volts = 0, enable line 5 volts = 1 - default 0 or self.enable_line_polarity

Returns

the command to send to the serial port

Return type

str

Command

Byte 1

Byte 2-3

Byte 4-5

Byte 6-15

Byte 16-25

Byte 26

Byte 27

Byte 28

Byte 29-31

Byte 32-34

Byte 35

Byte 36

Byte 37

I

00

CX

125000.000

4294967295

1

1

1

100

010

0

1

*


Command breakdown

Byte

Setting

Description

Byte 1

I=Instant Command B=Buffer Command

Sets command to either Instant or Buffer.

Byte 2-3

0-99

Optional Command ID

Byte 4-5

CX = Set X-Axis
CY = Set Y-Axis
CZ = Set Z-Axis
CE = Set E-Axis

Sets which Axis is to be set

Byte 6-15

000000.000-500000.000

Sets the frequency of the pulse train

Byte 16-25

0000000000-4294967295

Sets the required pulse count.

Byte 26

0-1

Direction
0=CW (forward)
1=CCW (reverse)

Byte 27

0-1

Start Ramp
0=No ramp
1=Ramp

Byte 28

0-1

Finish Ramp
0=No ramp
1=Ramp

Byte 29-31

0-255

Ramp divide. This will divide the target frequency by this value for each ramp increment

Byte 32-34

0-255

Ramp pause between each ramp increment

Byte 35

0-2

Link to ADC 0=No ADC 1=Link to ADC1 2=Link to ADC2

Byte 36

0-1

Enable Line Polarity 0=Enable Line 0 Volts 1=Enable Line 5 Volts

Byte 37

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command and also when it has completed a command. If the Command sent ID number was set for bytes 2-3, then this will be returned in the reply. These can be turned off if needed.

X set
Received
Y set
Received
Z set
Received
E set
Received
X set
Completed
Y set
Completed
Z set
Completed
E set
Completed

RI00CX*

RI00CY*

RI00CZ*

RI00CE*

CI00CX*

CI00CY*

CI00CZ*

CI00CE*

set_direction_forward()

Sets the direction to forward

Returns

the command to send to the serial port

Return type

str

set_direction_reverse()

Sets the direction to reverse

Returns

the command to send to the serial port

Return type

str

enable_start_ramp()

Enables the start ramp

Returns

the command to send to the serial port

Return type

str

disable_start_ramp()

Disables the start ramp

Returns

the command to send to the serial port

Return type

str

enable_finish_ramp()

Enables the finish ramp

Returns

the command to send to the serial port

Return type

str

disable_finish_ramp()

Disables the finish ramp

Returns

the command to send to the serial port

Return type

str

enable_line_polarity_0_volts()

Enable the line polarity at 0 volts

Returns

the command to send to the serial port

Return type

str

enable_line_polarity_5_volts()

Enable the line polarity at 5 volts

Returns

the command to send to the serial port

Return type

str

set_auto_direction_change(pulse_count=None)

This Command sets the Auto Direction Change of each Axis, but does not start the pulse train on that Axis. A Start Command must be used after to activate.

Parameters

pulse_count – pulse count to change direction on the fly, 0-4294967295 - default 0 or self.pulse_count

Returns

the command to send to the serial port

Return type

str

Command

Byte 1

Byte 2-3

Byte 4-5

Byte 6-15

Byte 16

I

00

BX

0000000100

*


Command breakdown

Byte

Setting

Description

Byte 1

I=Instant Command B=Buffer Command

Sets command to either Instant or Buffer.

Byte 2-3

0-99

Optional Command ID

Byte 4-5

BX = Set X-Axis
BY = Set Y-Axis
BZ = Set Z-Axis
BE = Set E-Axis

Sets which Axis is to be set to auto change direction

Byte 6-15

0000000000-4294967295

Sets the Pulse count to change direction on the fly

Byte 16

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command and also when it has completed a command. If the Command sent ID number was set for bytes 2-3, then this will be returned in the reply. These can be turned off if needed.

X set
Received
Y set
Received
Z set
Received
E set
Received
X set
Completed
Y set
Completed
Z set
Completed
E set
Completed

RI00BX*

RI00BY*

RI00BZ*

RI00BE*

CI00BX*

CI00BY*

CI00BZ*

CI00BE*

set_auto_count_pulse_out(pulse_count=None, xreplies=None, yreplies=None, zreplies=None, ereplies=None)

This Command sets which Axis and at what pulse count it should send back the current pulse count of each axis. It also sends back direction of travel. You can also choose what pulse replies are sent back X, Y, Z or E. A Start Command must be used after to activate.

Be aware that this command can cause a lot of data being sent back over the serial port and if you try to send other commands while it is sending data back, there could be a clash.

param pulse_count

pulse count at which all Axis pulse counts will be sent back, 0-4294967295 - default 0 or self.pulse_count

param xreplies

enable/disable X axis pulse count replies, disable = 0, enable = 1 - default 1 or self.enable_disable_x_pulse_count_replies

param yreplies

enable/disable Y axis pulse count replies, disable = 0, enable = 1 - default 0 or self.enable_disable_y_pulse_count_replies

param zreplies

enable/disable Z axis pulse count replies, disable = 0, enable = 1 - default 0 or self.enable_disable_z_pulse_count_replies

param ereplies

enable/disable E axis pulse count replies, disable = 0, enable = 1 - default 0 or self.enable_disable_e_pulse_count_replies

returns

the command to send to the serial port

rtype

str

Command

Byte 1

Byte 2-3

Byte 4-5

Byte 6-15

Byte 16

Byte 17

Byte 18

Byte 19

Byte 20

I

00

JX

0000000100

1

1

1

1

*

I01JX00000064001111

Command breakdown

Byte

Setting

Description

Byte 1

I=Instant Command B=Buffer Command

Sets command to either Instant or Buffer.

Byte 2-3

0-99

Optional Command ID

Byte 4-5

JX = Set X-Axis
JY = Set Y-Axis
JZ = Set Z-Axis
JE = Set E-Axis

Sets which Axis is to be set to auto send pulse counts on

Byte 6-15

0000000000-4294967295

Sets the Pulse count at which all Axis pulse counts will be sent back

Byte 16

0-1

Enable/Disable X Axis Pulse Replies
0 = Disable
1 = Enable

Byte 17

0-1

Enable/Disable Y Axis Pulse Replies
0 = Disable
1 = Enable

Byte 18

0-1

Enable/Disable Z Axis Pulse Replies
0 = Disable
1 = Enable

Byte 19

0-1

Enable/Disable E Axis Pulse Replies
0 = Disable
1 = Enable

Byte 20

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command and also when it has completed a command. The Pulse Count and direction that the motor is travelling will be sent back when pulse target is hit. If the Command sent ID number was set for bytes 2-3, then this will be returned in the reply. These can be turned off if needed.

X set
Received
Y set
Received
Z set
Received
E set
Received
X set
Completed
Y set
Completed
Z set
Completed
E set
Completed

RI00JX*

RI00JY*

RI00JZ*

RI00JE*

CI00JX*

CI00JY*

CI00JZ*

CI00JE*

DI00JX*
XP(D)XResult*
YP(D)XResult*
ZP(D)XResult*
EP(D)XResult*

(D)=Direction
of motor
travel

Result=
0000000000-
4294967295
DI00JY*
XP(D)XResult*
YP(D)XResult*
ZP(D)XResult*
EP(D)XResult*

(D)=Direction
of motor
travel

Result=
0000000000-
4294967295
DI00JZ*
XP(D)XResult*
YP(D)XResult*
ZP(D)XResult*
EP(D)XResult*

(D)=Direction
of motor
travel

Result=
0000000000-
4294967295
DI00JE*
XP(D)XResult*
YP(D)XResult*
ZP(D)XResult*
EP(D)XResult*

(D)=Direction
of motor
travel

Result=
0000000000-
4294967295
start()

Start one of the pulse trains running.

Returns

the command to send to the serial port

Return type

str

Command

Byte 1

Byte 2-3

Byte 4-5

Byte 6

I

00

SX

*


Command breakdown

Byte

Setting

Description

Byte 1

I=Instant Command B=Buffer Command

Sets command to either Instant or Buffer.

Byte 2-3

0-99

Optional Command ID

Byte 4-5

SX = Start X-Axis
SY = Start Y-Axis
SZ = Start Z-Axis
SE = Start E-Axis
SA = Start All

Sets which Axis is to be started

Byte 6

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command and also when it has completed a command. In this case the completed command will be sent back when the Axis that has been started completes the Pulse Count. If the Command sent ID number was set for bytes 2-3, then this will be returned in the reply.

X Start
Received
Y Start
Received
Z Start
Received
E Start
Received
All Start
Received
X Pulse
Count
Completed
Y Pulse
Count
Completed
Z Pulse
Count
Completed
E Pulse
Count
Completed

RI00SX*

RI00SY*

RI00SZ*

RI00SE*

CI00SA*

CI00SX*

CI00SY*

CI00SZ*

CI00SE*

start_all()

Start all of the pulse trains running.

Returns

the command to send to the serial port

Return type

str

Command

Byte 1

Byte 2-3

Byte 4-5

Byte 6

I

00

SA

*


Command breakdown

Byte

Setting

Description

Byte 1

I=Instant Command B=Buffer Command

Sets command to either Instant or Buffer.

Byte 2-3

0-99

Optional Command ID

Byte 4-5

SX = Start X-Axis
SY = Start Y-Axis
SZ = Start Z-Axis
SE = Start E-Axis
SA = Start All

Sets which Axis is to be started

Byte 6

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command and also when it has completed a command. In this case the completed command will be sent back when the Axis that has been started completes the Pulse Count. If the Command sent ID number was set for bytes 2-3, then this will be returned in the reply.

X Start
Received
Y Start
Received
Z Start
Received
E Start
Received
All Start
Received
X Pulse
Count
Completed
Y Pulse
Count
Completed
Z Pulse
Count
Completed
E Pulse
Count
Completed

RI00SX*

RI00SY*

RI00SZ*

RI00SE*

CI00SA*

CI00SX*

CI00SY*

CI00SZ*

CI00SE*

stop()

Stop one of the pulse trains from running. This is a controlled stop, in that the Axis will ramp down and not just stop to protect the motors. If you want to use a sudden stop then we recommend a external Emergency Stop button that cuts the power or send a Reset command.

Returns

the command to send to the serial port

Return type

str

Command

Byte 1

Byte 2-3

Byte 4-5

Byte 6

I

00

TX

*


Command breakdown

Byte

Setting

Description

Byte 1

I=Instant Command B=Buffer Command

Sets command to either Instant or Buffer.

Byte 2-3

0-99

Optional Command ID

Byte 4-5

TX = Stop X-Axis
TY = Stop Y-Axis
TZ = Stop Z-Axis
TE = Stop E-Axis
TA = Stop All

Sets which Axis is to be stopped

Byte 6

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command and also when it has completed a command. In this case the completed command will be sent back when the Axis that has came to a stop. If the Command sent ID number was set for bytes 2-3, then this will be returned in the Received reply, but the completed command ID will be from the original ID used in the Start command.

X Stop
Received
Y Stop
Received
Z Stop
Received
E Stop
Received
All Stop
Received
X Pulse
Stopped
Y Pulse
Stopped
Z Pulse
Stopped
E Pulse
Stopped

RI00TX*

RI00TY*

RI00TZ*

RI00TE*

RI00TA*

CI00TX*

CI00TY*

CI00TZ*

CI00TE*

stop_all()

Stop all of the pulse trains from running. This is a controlled stop, in that the Axis will ramp down and not just stop to protect the motors. If you want to use a sudden stop then we recommend a external Emergency Stop button that cuts the power or send a Reset command.

Returns

the command to send to the serial port

Return type

str

Command

Byte 1

Byte 2-3

Byte 4-5

Byte 6

I

00

TA

*


Command breakdown

Byte

Setting

Description

Byte 1

I=Instant Command B=Buffer Command

Sets command to either Instant or Buffer.

Byte 2-3

0-99

Optional Command ID

Byte 4-5

TX = Stop X-Axis
TY = Stop Y-Axis
TZ = Stop Z-Axis
TE = Stop E-Axis
TA = Stop All

Sets which Axis is to be stopped

Byte 6

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command and also when it has completed a command. In this case the completed command will be sent back when the Axis that has came to a stop. If the Command sent ID number was set for bytes 2-3, then this will be returned in the Received reply, but the completed command ID will be from the original ID used in the Start command.

X Stop
Received
Y Stop
Received
Z Stop
Received
E Stop
Received
All Stop
Received
X Pulse
Stopped
Y Pulse
Stopped
Z Pulse
Stopped
E Pulse
Stopped

RI00TX*

RI00TY*

RI00TZ*

RI00TE*

RI00TA*

CI00TX*

CI00TY*

CI00TZ*

CI00TE*

pause(return_x_pulse_cnt=None, return_y_pulse_cnt=None, return_z_pulse_cnt=None, return_e_pulse_cnt=None)

Pauses one of the pulse trains from running. Bytes 6-9 choose to send Pulse count back after pause for each Axis.

Parameters
  • return_x_pulse_cnt – X axis pulse count replies, disable = 0, enable = 1 - default 0 or self.pause_all_return_x_pulse_count

  • return_y_pulse_cnt – Y axis pulse count replies, disable = 0, enable = 1 - default 0 or self.pause_all_return_y_pulse_count

  • return_z_pulse_cnt – Z axis pulse count replies, disable = 0, enable = 1 - default 0 or self.pause_all_return_z_pulse_count

  • return_e_pulse_cnt – E axis pulse count replies, disable = 0, enable = 1 - default 0 or self.pause_all_return_e_pulse_count

Returns

the command to send to the serial port

Return type

str

Command

Byte 1

Byte 2-3

Byte 4-5

Byte 6

Byte 7

Byte 8

Byte 9

Byte 10

I

00

PX

1

0

0

0

*


Command breakdown

Byte

Setting

Description

Byte 1

I=Instant Command B=Buffer Command

Sets command to either Instant or Buffer.

Byte 2-3

0-99

Optional Command ID

Byte 4-5

PX = Pause X-Axis
PY = Pause Y-Axis
PZ = Pause Z-Axis
PE = Pause E-Axis
PA = Pause All

Sets which Axis is to be Paused

Byte 6

0-1

Sends back pulse count from Axis if set to 1 with:
PA = X-Axis
PX = X-Axis
PY = Y-Axis
PZ = Z-Axis
PE = E-Axis

Byte 7

0-1

Sends back pulse count from Axis if set to 1 with:
PA = Y-Axis
Set to 0 for PX, PY, PZ, PE

Byte 8

0-1

Sends back pulse count from Axis if set to 1 with:
PA = Z-Axis
Set to 0 for PX, PY, PZ, PE

Byte 9

0-1

Sends back pulse count from Axis if set to 1 with:
PA = E-Axis
Set to 0 for PX, PY, PZ, PE

Byte 10

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command and also when it has completed a command. If Pulse Count is selected then it will also send back the pulse count of chosen Axis. In this case the completed command will be sent back when the Axis is resumed, after a Pause. If the Command sent ID number was set for bytes 2-3, then this will be returned in the reply.

X Pause
Received
Y Pause
Received
Z Pause
Received
E Pause
Received
Pause All
Received

RI00PX*

RI00PY*

RI00PZ*

RI00PE*

RI00PA*

DI00PX*
XP(D)XResult*
YP(D)XResult*
ZP(D)XResult*
EP(D)XResult*

(D)=Direction
of motor
travel

Result=
0000000000-
4294967295
DI00PY*
XP(D)XResult*
YP(D)XResult*
ZP(D)XResult*
EP(D)XResult*

(D)=Direction
of motor
travel

Result=
0000000000-
4294967295
DI00PZ*
XP(D)XResult*
YP(D)XResult*
ZP(D)XResult*
EP(D)XResult*

(D)=Direction
of motor
travel

Result=
0000000000-
4294967295
DI00PE*
XP(D)XResult*
YP(D)XResult*
ZP(D)XResult*
EP(D)XResult*

(D)=Direction
of motor
travel

Result=
0000000000-
4294967295
DI00PX to E*
XP(D)XResult*
YP(D)XResult*
ZP(D)XResult*
EP(D)XResult*
(D)=Direction
of motor
travel

Result=
0000000000-
4294967295
pause_all(return_x_pulse_cnt=None, return_y_pulse_cnt=None, return_z_pulse_cnt=None, return_e_pulse_cnt=None)

Pauses all of the pulse trains from running. Bytes 6-9 choose to send Pulse count back after pause for each Axis.

Parameters
  • return_x_pulse_cnt – X axis pulse count replies, disable = 0, enable = 1 - default 0 or self.pause_all_return_x_pulse_count

  • return_y_pulse_cnt – Y axis pulse count replies, disable = 0, enable = 1 - default 0 or self.pause_all_return_y_pulse_count

  • return_z_pulse_cnt – Z axis pulse count replies, disable = 0, enable = 1 - default 0 or self.pause_all_return_z_pulse_count

  • return_e_pulse_cnt – E axis pulse count replies, disable = 0, enable = 1 - default 0 or self.pause_all_return_e_pulse_count

Returns

the command to send to the serial port

Return type

str

Command

Byte 1

Byte 2-3

Byte 4-5

Byte 6

Byte 7

Byte 8

Byte 9

Byte 10

I

00

PA

1

0

0

0

*


Command breakdown

Byte

Setting

Description

Byte 1

I=Instant Command B=Buffer Command

Sets command to either Instant or Buffer.

Byte 2-3

0-99

Optional Command ID

Byte 4-5

PX = Pause X-Axis
PY = Pause Y-Axis
PZ = Pause Z-Axis
PE = Pause E-Axis
PA = Pause All

Sets which Axis is to be Paused

Byte 6

0-1

Sends back pulse count from Axis if set to 1 with:
PA = X-Axis
PX = X-Axis
PY = Y-Axis
PZ = Z-Axis
PE = E-Axis

Byte 7

0-1

Sends back pulse count from Axis if set to 1 with:
PA = Y-Axis
Set to 0 for PX, PY, PZ, PE

Byte 8

0-1

Sends back pulse count from Axis if set to 1 with:
PA = Z-Axis
Set to 0 for PX, PY, PZ, PE

Byte 9

0-1

Sends back pulse count from Axis if set to 1 with:
PA = E-Axis
Set to 0 for PX, PY, PZ, PE

Byte 10

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command and also when it has completed a command. If Pulse Count is selected then it will also send back the pulse count of chosen Axis. In this case the completed command will be sent back when the Axis is resumed, after a Pause. If the Command sent ID number was set for bytes 2-3, then this will be returned in the reply.

X Pause
Received
Y Pause
Received
Z Pause
Received
E Pause
Received
Pause All
Received

RI00PX*

RI00PY*

RI00PZ*

RI00PE*

RI00PA*

DI00PX*
XP(D)XResult*
YP(D)XResult*
ZP(D)XResult*
EP(D)XResult*

(D)=Direction
of motor
travel

Result=
0000000000-
4294967295
DI00PY*
XP(D)XResult*
YP(D)XResult*
ZP(D)XResult*
EP(D)XResult*

(D)=Direction
of motor
travel

Result=
0000000000-
4294967295
DI00PZ*
XP(D)XResult*
YP(D)XResult*
ZP(D)XResult*
EP(D)XResult*

(D)=Direction
of motor
travel

Result=
0000000000-
4294967295
DI00PE*
XP(D)XResult*
YP(D)XResult*
ZP(D)XResult*
EP(D)XResult*

(D)=Direction
of motor
travel

Result=
0000000000-
4294967295
DI00PX to E*
XP(D)XResult*
YP(D)XResult*
ZP(D)XResult*
EP(D)XResult*
(D)=Direction
of motor
travel

Result=
0000000000-
4294967295
resume(return_x_pulse_cnt=None, return_y_pulse_cnt=None, return_z_pulse_cnt=None, return_e_pulse_cnt=None)

Resumes one of the pulse trains from running. Bytes 6-9 choose to send Pulse count back after pause for each Axis.

Parameters
  • return_x_pulse_cnt – X axis pulse count replies, disable = 0, enable = 1 - default 0 or self.pause_all_return_x_pulse_count

  • return_y_pulse_cnt – Y axis pulse count replies, disable = 0, enable = 1 - default 0 or self.pause_all_return_y_pulse_count

  • return_z_pulse_cnt – Z axis pulse count replies, disable = 0, enable = 1 - default 0 or self.pause_all_return_z_pulse_count

  • return_e_pulse_cnt – E axis pulse count replies, disable = 0, enable = 1 - default 0 or self.pause_all_return_e_pulse_count

Returns

the command to send to the serial port

Return type

str

Command

Byte 1

Byte 2-3

Byte 4-5

Byte 6

Byte 7

Byte 8

Byte 9

Byte 10

I

00

PX

1

0

0

0

*


Command breakdown

Byte

Setting

Description

Byte 1

I=Instant Command B=Buffer Command

Sets command to either Instant or Buffer.

Byte 2-3

0-99

Optional Command ID

Byte 4-5

PX = Pause X-Axis
PY = Pause Y-Axis
PZ = Pause Z-Axis
PE = Pause E-Axis
PA = Pause All

Sets which Axis is to be Paused

Byte 6

0-1

Sends back pulse count from Axis if set to 1 with:
PA = X-Axis
PX = X-Axis
PY = Y-Axis
PZ = Z-Axis
PE = E-Axis

Byte 7

0-1

Sends back pulse count from Axis if set to 1 with:
PA = Y-Axis
Set to 0 for PX, PY, PZ, PE

Byte 8

0-1

Sends back pulse count from Axis if set to 1 with:
PA = Z-Axis
Set to 0 for PX, PY, PZ, PE

Byte 9

0-1

Sends back pulse count from Axis if set to 1 with:
PA = E-Axis
Set to 0 for PX, PY, PZ, PE

Byte 10

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command and also when it has completed a command. If Pulse Count is selected then it will also send back the pulse count of chosen Axis. In this case the completed command will be sent back when the Axis is resumed, after a Pause. If the Command sent ID number was set for bytes 2-3, then this will be returned in the reply.

X Resume
Received
Y Resume
Received
Z Resume
Received
E Resume
Received
Resume All
Received

CI00PX*

CI00PY*

CI00PZ*

CI00PE*

CI00PA*

resume_all(return_x_pulse_cnt=None, return_y_pulse_cnt=None, return_z_pulse_cnt=None, return_e_pulse_cnt=None)

Resumes all of the pulse trains from running. Bytes 6-9 choose to send Pulse count back after pause for each Axis.

Parameters
  • return_x_pulse_cnt – X axis pulse count replies, disable = 0, enable = 1 - default 0 or self.pause_all_return_x_pulse_count

  • return_y_pulse_cnt – Y axis pulse count replies, disable = 0, enable = 1 - default 0 or self.pause_all_return_y_pulse_count

  • return_z_pulse_cnt – Z axis pulse count replies, disable = 0, enable = 1 - default 0 or self.pause_all_return_z_pulse_count

  • return_e_pulse_cnt – E axis pulse count replies, disable = 0, enable = 1 - default 0 or self.pause_all_return_e_pulse_count

Returns

the command to send to the serial port

Return type

str

Command

Byte 1

Byte 2-3

Byte 4-5

Byte 6

Byte 7

Byte 8

Byte 9

Byte 10

I

00

PA

1

0

0

0

*


Command breakdown

Byte

Setting

Description

Byte 1

I=Instant Command B=Buffer Command

Sets command to either Instant or Buffer.

Byte 2-3

0-99

Optional Command ID

Byte 4-5

PX = Pause X-Axis
PY = Pause Y-Axis
PZ = Pause Z-Axis
PE = Pause E-Axis
PA = Pause All

Sets which Axis is to be Paused

Byte 6

0-1

Sends back pulse count from Axis if set to 1 with:
PA = X-Axis
PX = X-Axis
PY = Y-Axis
PZ = Z-Axis
PE = E-Axis

Byte 7

0-1

Sends back pulse count from Axis if set to 1 with:
PA = Y-Axis
Set to 0 for PX, PY, PZ, PE

Byte 8

0-1

Sends back pulse count from Axis if set to 1 with:
PA = Z-Axis
Set to 0 for PX, PY, PZ, PE

Byte 9

0-1

Sends back pulse count from Axis if set to 1 with:
PA = E-Axis
Set to 0 for PX, PY, PZ, PE

Byte 10

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command and also when it has completed a command. If Pulse Count is selected then it will also send back the pulse count of chosen Axis. In this case the completed command will be sent back when the Axis is resumed, after a Pause. If the Command sent ID number was set for bytes 2-3, then this will be returned in the reply.

X Resume
Received
Y Resume
Received
Z Resume
Received
E Resume
Received
Resume All
Received

CI00PX*

CI00PY*

CI00PZ*

CI00PE*

CI00PA*

get_current_pulse_count()

When this request is sent, it will return of the current pulse count of the running Axis.

Returns

the command to send to the serial port

Return type

str

Byte 1

Byte 2-3

Byte 4-5

Byte 6

I

00

XP

*


Command breakdown

Byte

Setting

Description

Byte 1

I=Instant Command B=Buffer Command

Sets command to either Instant or Buffer.

Byte 2-3

0-99

Optional Command ID

Byte 4-5

XP = Pulse Count X-Axis
YP = Pulse Count Y-Axis
ZP = Pulse Count Z-Axis
EP = Pulse Count E-Axis

Request current pulse count for Axis specified

Byte 6

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command and also when it has completed a command. In this case the received command will be sent back along with the Pulse Count and direction that the motor is travelling, then completed command. If the Command sent ID number was set for bytes 2-3, then this will be returned in the reply.

X Pulse Count
Received
Result
Y Pulse Count
Received
Result
Z Pulse Count
Received
Result
E Pulse Count
Received
Result
X Pulse
Count
Completed
X Pulse
Count
Completed
X Pulse
Count
Completed
X Pulse
Count
Completed

RI00XP*

RI00YP*

RI00ZP*

RI00EP*

CI00XP*

CI00YP*

CI00ZP*

CI00EP*

XP(D)XResult*

(D)=Direction
of X motor
travel

XResult=
0000000000-
4294967295
YP(D)XResult*

(D)=Direction
of Y motor
travel

XResult=
0000000000-
4294967295
ZP(D)XResult*

(D)=Direction
of Z motor
travel

XResult=
0000000000-
4294967295
EP(D)XResult*

(D)=Direction
of E motor
travel

XResult=
0000000000-
4294967295
change_speed(new_frequency)

This Command changes the speed of each Axis on the fly. A Set Axis Command and a Start Command must be used to set the Axis running before this command can be used. Note that this command does not have a ramp up and ramp down value so speed adjustments must be made in smaller increments with a stepper motor so as to not cause it to stall.

Parameters

new_frequency – new frequency to change the speed to, 0.0-125000.0 - required

Returns

the command to send to the serial port

Return type

str

Command

Byte 1

Byte 2-3

Byte 4-5

Byte 6-15 | Byte 16

I

00

QX

001000.000 | *


Command breakdown

Byte

Setting

Description

Byte 1

I=Instant Command B=Buffer Command

Sets command to either Instant or Buffer.

Byte 2-3

0-99

Optional Command ID

Byte 4-5

QX = Set X-Axis
QY = Set Y-Axis
QZ = Set Z-Axis
QE = Set E-Axis

Sets which Axis is to be set

Byte 6-15

000000.000-125000.000

Sets the new frequency of the pulse train

Byte 16

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command and also when it has completed a command. If the Command sent ID number was set for bytes 2-3, then this will be returned in the reply. These can be turned off if needed.

X Set
Received
Y Set
Received
Z Set
Received
E Set
Received
X Set
Completed
Y Set
Completed
Z Set
Completed
E Set
Completed

RI00QX*

RI00QY*

RI00QZ*

RI00QE*

CI00QX*

CI00QY*

CI00QZ*

CI00QE*

enable_limit_switches()

When this request is sent, it will Enable Limit Switch or Emergency Stop inputs. A reset on the PTHAT will set them to default of Disable

Returns

the command to send to the serial port

Return type

str

Command

Byte 1

Byte 2-3

Byte 4-5

Byte 6 | Byte 7

I

00

KX

1 | *


Command breakdown

Byte

Setting

Description

Byte 1

I=Instant Command B=Buffer Command

Sets command to either Instant or Buffer.

Byte 2-3

0-99

Optional Command ID

Byte 4-5

KX = Set Limit Switch X
KY = Set Limit Switch Y
KZ = Set Limit Switch Z
KE = Set Limit Switch E

Set Limit Switch or Emergency Stop Enable/Disable

Byte 6

0-1

Switches selected Limit Switch to Enable/Disable
0=Disable
1=Enable

Byte 7

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command and also when it has completed a command. If the Command sent ID number was set for bytes 2-3, then this will be returned in the reply.

X Limit
Received
Y Limit
Received
Z Limit
Received
E Limit
Received
Emergency
Stop
Received
X Limit
Completed
Y Limit
Completed
Z Limit
Completed
E Limit
Completed
Emergency
Stop
Completed

R00KX*

R00KY*

R00KZ*

R00KE*

R00KS*

C00KX*

C00KY*

C00KZ*

C00KE*

C00KS*

disable_limit_switches()

When this request is sent, it will Disable Limit Switch or Emergency Stop inputs. A reset on the PTHAT will set them to default of Disable

Returns

the command to send to the serial port

Return type

str

Command

Byte 1

Byte 2-3

Byte 4-5

Byte 6 | Byte 7

I

00

KX

0 | *


Command breakdown

Byte

Setting

Description

Byte 1

I=Instant Command B=Buffer Command

Sets command to either Instant or Buffer.

Byte 2-3

0-99

Optional Command ID

Byte 4-5

KX = Set Limit Switch X
KY = Set Limit Switch Y
KZ = Set Limit Switch Z
KE = Set Limit Switch E

Set Limit Switch or Emergency Stop Enable/Disable

Byte 6

0-1

Switches selected Limit Switch to Enable/Disable
0=Disable
1=Enable

Byte 7

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command and also when it has completed a command. If the Command sent ID number was set for bytes 2-3, then this will be returned in the reply.

X Limit
Received
Y Limit
Received
Z Limit
Received
E Limit
Received
Emergency
Stop
Received
X Limit
Completed
Y Limit
Completed
Z Limit
Completed
E Limit
Completed
Emergency
Stop
Completed

R00KX*

R00KY*

R00KZ*

R00KE*

R00KS*

C00KX*

C00KY*

C00KZ*

C00KE*

C00KS*

enable_emergency_stop()

When this request is sent, it will Disable Limit Switch or Emergency Stop inputs. A reset on the PTHAT will set them to default of Disable

Returns

the command to send to the serial port

Return type

str

Command

Byte 1

Byte 2-3

Byte 4-5

Byte 6 | Byte 7

I

00

KS

1 | *


Command breakdown

Byte

Setting

Description

Byte 1

I=Instant Command B=Buffer Command

Sets command to either Instant or Buffer.

Byte 2-3

0-99

Optional Command ID

Byte 4-5

KX = Set Limit Switch X
KY = Set Limit Switch Y
KZ = Set Limit Switch Z
KE = Set Limit Switch E

Set Limit Switch or Emergency Stop Enable/Disable

Byte 6

0-1

Switches selected Limit Switch to Enable/Disable
0=Disable
1=Enable

Byte 7

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command and also when it has completed a command. If the Command sent ID number was set for bytes 2-3, then this will be returned in the reply.

X Limit
Received
Y Limit
Received
Z Limit
Received
E Limit
Received
Emergency
Stop
Received
X Limit
Completed
Y Limit
Completed
Z Limit
Completed
E Limit
Completed
Emergency
Stop
Completed

R00KX*

R00KY*

R00KZ*

R00KE*

R00KS*

C00KX*

C00KY*

C00KZ*

C00KE*

C00KS*

disable_emergency_stop()

When this request is sent, it will Disable Limit Switch or Emergency Stop inputs. A reset on the PTHAT will set them to default of Disable

Returns

the command to send to the serial port

Return type

str

Command

Byte 1

Byte 2-3

Byte 4-5

Byte 6 | Byte 7

I

00

KS

0 | *


Command breakdown

Byte

Setting

Description

Byte 1

I=Instant Command B=Buffer Command

Sets command to either Instant or Buffer.

Byte 2-3

0-99

Optional Command ID

Byte 4-5

KX = Set Limit Switch X
KY = Set Limit Switch Y
KZ = Set Limit Switch Z
KE = Set Limit Switch E

Set Limit Switch or Emergency Stop Enable/Disable

Byte 6

0-1

Switches selected Limit Switch to Enable/Disable
0=Disable
1=Enable

Byte 7

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command and also when it has completed a command. If the Command sent ID number was set for bytes 2-3, then this will be returned in the reply.

X Limit
Received
Y Limit
Received
Z Limit
Received
E Limit
Received
Emergency
Stop
Received
X Limit
Completed
Y Limit
Completed
Z Limit
Completed
E Limit
Completed
Emergency
Stop
Completed

R00KX*

R00KY*

R00KZ*

R00KE*

R00KS*

C00KX*

C00KY*

C00KZ*

C00KE*

C00KS*

reset()

Call reset on the parent class and then reset all the variables


ADC class

class pthat.ADC(adc_number, command_type='I', command_id=0, serial_device='/dev/ttyS0', baud_rate=115200, test_mode=False)

Bases: pthat.PTHat

class ADC

This is an ADC class containing info about an ADC. It inherits from PTHat so contains all functionality needed to communicate with the PTHat via the serial interface.

Parameters
  • adc_number – ADC number, 1 or 2

  • command_type – type of command, I = instant, B = buffered - default I

  • command_id – optional command ID, 0-99 - default 0

  • serial_device – serial device - default /dev/ttyS0

  • baud_rate – serial port baud rate - default 115200

  • test_mode – if true then serial commands will not actually be sent - default False

adc_number = 1

ADC number - Currently 1 or 2. This can be set directly.

get_reading(adc_number=None)

When this request is sent, it will return the value of the ADC requested.

:param adc_number ADC number, 1 or 2 - default 1 or self.adc_number :returns: the command to send to the serial port :rtype: str

Command

Byte 1

Byte 2-3

Byte 4-5

Byte 6

I

00

D1

*


Command breakdown

Byte

Setting

Description

Byte 1

I=Instant Command B=Buffer Command

Sets command to either Instant or Buffer.

Byte 2-3

0-99

Optional Command ID

Byte 4-5

D1 = ADC1 Result
D2 = ADC2 Result

Request current ADC value

Byte 6

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command and also when it has completed a command. In this case the received command will be sent back along with the ADC result and then completed command. If the Command sent ID number was set for bytes 2-3, then this will be returned in the reply.

ADC1 Received
*Result*
ADC1 Received
*Result*
ADC1
Completed
ADC2
Completed

RI00D1**Result*

RI00D2**Result*

CI00D1*

CI00D2*

reset()

Call reset on the parent class and then reset all the variables


AUX class

class pthat.AUX(aux_number, command_type='I', command_id=0, serial_device='/dev/ttyS0', baud_rate=115200, test_mode=False)

Bases: pthat.PTHat

class AUX

This is an AUC class containing info about an AUX. It inherits from PTHat so contains all functionality needed to communicate with the PTHat via the serial interface.

Parameters
  • aux_number – AUX number, 1-3

  • command_type – type of command, I = instant, B = buffered - default I

  • command_id – optional command ID, 0-99 - default 0

  • serial_device – serial device - default /dev/ttyS0

  • baud_rate – serial port baud rate - default 115200

  • test_mode – if true then serial commands will not actually be sent - default False

aux_number = 1

ADC number, currently 1, 2 or 3. This can be set directly.

output_on(aux_number=None)

When this request is sent, it will switch on the Aux port.

Parameters

aux_number – AUX number, 1-3, default 1 or self.aux_number

Returns

the command to send to the serial port

Return type

str

Command

Byte 1

Byte 2-3

Byte 4-5

Byte 6 | Byte 7

I

00

A1

1 | *


Command breakdown

Byte

Setting

Description

Byte 1

I=Instant Command B=Buffer Command

Sets command to either Instant or Buffer.

Byte 2-3

0-99

Optional Command ID

Byte 4-5

A1 = Set Aux1 A2 = Set Aux2 A3 = Set Aux3

Set Aux port for switching

Byte 6

0-1

Switches selected Aux On or Off
0 = Off
1 = On

Byte 7

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command and also when it has completed a command. If the Command sent ID number was set for bytes 2-3, then this will be returned in the reply.

Aux1 Received

Aux2 Received

Aux3 Received

Aux3 Completed

Aux3 Completed

Aux3 Completed

R00A1*

R00A2*

R00A3*

C00A1*

C00A1*

C00A1*

output_off(aux_number=None)

When this request is sent, it will switch off the Aux port.

Parameters

aux_number – AUX number, 1-3, default 1 or self.aux_number

Returns

the command to send to the serial port

Return type

str

Command

Byte 1

Byte 2-3

Byte 4-5

Byte 6 | Byte 7

I

00

A1

0 | *


Command breakdown

Byte

Setting

Description

Byte 1

I=Instant Command B=Buffer Command

Sets command to either Instant or Buffer.

Byte 2-3

0-99

Optional Command ID

Byte 4-5

A1 = Set Aux1 A2 = Set Aux2 A3 = Set Aux3

Set Aux port for switching

Byte 6

0-1

Switches selected Aux On or Off
0 = Off
1 = On

Byte 7

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command and also when it has completed a command. If the Command sent ID number was set for bytes 2-3, then this will be returned in the reply.

Aux1 Received

Aux2 Received

Aux3 Received

Aux3 Completed

Aux3 Completed

Aux3 Completed

R00A1*

R00A2*

R00A3*

C00A1*

C00A1*

C00A1*

reset()

Call reset on the parent class and then reset all the variables


PWM class

class pthat.PWM(axis, command_type='I', command_id=0, serial_device='/dev/ttyS0', baud_rate=115200, test_mode=False)

Bases: pthat.PTHat

class PWM

This is an PWM class containing info about an PWM. It inherits from PTHat so contains all functionality needed to communicate with the PTHat via the serial interface.

From Firmware V5.3 onwards there are commands for controlling two dedicated PWM channels. Details for PWM can be found here: http://pthat.com/index.php/pwm/

Parameters
  • axis – axis for this class

  • command_type – type of command, I = instant, B = buffered - default I

  • command_id – optional command ID, 0-99 - default 0

  • serial_device – serial device - default /dev/ttyS0

  • baud_rate – serial port baud rate - default 115200

  • test_mode – if true then serial commands will not actually be sent - default False

frequency = 0

Frequency for the channel is in 1Hz steps - 0000000-1000000. This can be set directly.

duty_cycle = 0

Sets the Duty Cycle 0-100%, The last 2 digits are decimal places. So 08050 would be 80.5%. This can be set directly.

frequency_x = 0
Used for Set Both PWM Channels Command only
Sets the Frequency for the channel in 1Hz steps for X-Axis. This can be set directly.
frequency_y = 0
Used for Set Both PWM Channels Command only
Sets the Frequency for the channel in 1Hz steps for Y-Axis. This can be set directly.
duty_cycle_x = 0
Used for Set Both PWM Channels Command only
Sets the Duty Cycle 0-100% for X-Axis. This can be set directly.
duty_cycle_y = 0
Used for Set Both PWM Channels Command only
Sets the Duty Cycle 0-100% for Y-Axis. This can be set directly.
axis = 'X'

Sets which Axis is to be set - X or Y, if UA then this doesn’t matter as it will do both X and Y. This can be set directly.

set_channel(frequency=None, duty_cycle=None)

*Available Firmware V5.3 upwards* This Command sets the Frequency and Pulse Width for the desired channel. It then also starts it.

Parameters
  • frequency – frequency for the channel in 1Hz steps, 0000000-1000000 - default 0 or self.frequency

  • duty_cycle – duty cycle 0-100%. The last 2 digits are decimal places. So 08050 would be 80.5% - default 0 or self.duty_cycle

Returns

the command to send to the serial port

Return type

str

Command

Byte 1

Byte 2-3

Byte 4-5

Byte 6-12 | Byte 13-17 | Byte 18 |

I

00

UX

0000000 | 00000 | * |


Command breakdown

Byte

Setting

Description

Byte 1

I=Instant Command B=Buffer Command

Sets command to either Instant or Buffer.

Byte 2-3

0-99

Optional Command ID

Byte 4-5

UX = Set X-Axis UY = Set Y-Axis

Sets which Axis is to be set

Byte 6-12

0000000-1000000

Sets the Frequency for the channel in 1Hz steps

Byte 13-17

00000

Sets the Duty Cycle 0-100%

Byte 18

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command and also when it has completed a command. If the Command sent ID number was set for bytes 2-3, then this will be returned in the reply. These can be turned off if needed.

X Set
Received
X Set
Received
X Set
Received
X Set
Received

RI00UX*

RI00UY*

CI00UX*

CI00UY*

set_frequency(frequency)

Set the PWM frequency

Parameters

frequency – frequency for the channel in 1Hz steps, 0000000-1000000 - default 0

Returns

the command to send to the serial port

Return type

str

set_duty_cycle(duty_cycle)

Set the PWM duty cycle

Parameters

duty_cycle – duty cycle 0-100%. The last 2 digits are decimal places. So 08050 would be 80.5% - default 0

Returns

the command to send to the serial port

Return type

str

set_both_channels(frequencyx=None, frequencyy=None, duty_cyclex=None, duty_cycley=None)

*Available Firmware V5.3 upwards* This Command sets the Frequency and Pulse Width for both channels at the same time. It then also starts both together.

Parameters
  • frequencyx – frequency for the X channel in 1Hz steps, 0000000-1000000 - default 0 or self.frequency_x

  • frequencyy – frequency for the Y channel in 1Hz steps, 0000000-1000000 - default 0 or self.frequency_y

  • duty_cyclex – duty cycle for X channel 0-100%. The last 2 digits are decimal places. So 08050 would be 80.5% - default 0 or self.duty_cycle_x

  • duty_cycley – duty cycle for Y channel 0-100%. The last 2 digits are decimal places. So 08050 would be 80.5% - default 0 or self.duty_cycle_x

Returns

the command to send to the serial port

Return type

str

Command

Byte 1

Byte 2-3

Byte 4-5

Byte 6-12

Byte 13-17

Byte 18-24

Byte 25-29

Byte 30

I

00

UA

0000000

00000

0000000

00000

*


Command breakdown

Byte

Setting

Description

Byte 1

I=Instant Command B=Buffer Command

Sets command to either Instant or Buffer.

Byte 2-3

0-99

Optional Command ID

Byte 4-5

UA=Set X-Axis and Y-Axis

Sets both X-Axis and Y-Axis settings

Byte 6-12

0000000-1000000

Sets the Frequency for the channel in 1Hz steps for X-Axis

Byte 13-17

00000

Sets the Duty Cycle 0-100% for X-Axis

Byte 18-24

0000000-1000000

Sets the Frequency for the channel in 1Hz steps for Y-Axis

Byte 25-29

00000

Sets the Duty Cycle 0-100% for Y-Axis

Byte 30

*

End of Command


Reply

The PTHAT will send back a reply when it receives a command and also when it has completed a command. If the Command sent ID number was set for bytes 2-3, then this will be returned in the reply. These can be turned off if needed.

Set both PWM channels
Received
Set both PWM channels
Completed

RI00UA*

CI00UA*

reset()

Call reset on the parent class and then reset all the variables