fetbox¶
Serial control of PlateFlo FETbox hardware controllers.
- class plateflo.fetbox.FETbox(port: str, baud: int = 115200)¶
FETbox serial control.
- Parameters
port (str) – Serial port name (e.g. ‘COM3’).
baud (int, default=115200) – Serial baud rate (e.g. 9600).
- Returns
- Return type
FETbox object
- mod_ser¶
Backend PySerial serial object
- Type
Serial
- port¶
Serial port name
- Type
str
- id¶
Module ID number
- Type
int
- pin_table¶
Analog pin name to pin number mapping.
- Type
dict
- Raises
ValueError – provided serial port is not connected to a FETbox device.
- analog_read(pin: str) int ¶
Read analog pin value directly from Arduino.
- Parameters
pin (str {'A0','A1','A2','A3','A4','A5','A6','A7'}) – Arduino analog pin name.
- Returns
10-bit analog pin reading (0-1023). None if query error.
- Return type
int or None
- analog_write(pin: int, pwm: int) bool ¶
Arduino analog write function. Sets PWM value of pin. Arduino Nano PWM pins are 3,5,6,9,10,11. NB: only pin 11 is unrouted to MOSFET gates.
- Parameters
pin (int {3,5,6,9,10,11}) – PWM-capable Arduino pin number.
pwm (int {0-255}) – 8-bit PWM output value.
- Returns
Command success/fail
- Return type
bool
- digital_read(pin) int ¶
Read digital pin value directly from Arduino.
- Parameters
pin (int {0-13} or str {'A0','A1','A2','A3','A4','A5'}) – Arduino digital pin number (int) OR Arduino analog pin name (str)
- Returns
Pin reading: 1 == HIGH, 0 == LOW, None if error
- Return type
int or None
- digital_write(pin, val: int) bool ¶
Arduino digitalWrite functionality. Sets pin HIGH (1) or LOW (0).
- Parameters
pin (int {0-13} or,) – str {‘A0’-‘A5} Arduino digital pin number [0-13] or analog pin name [A0-A5] A6/A7 cannot are analog read only.
val (int {0,1}) – Output pin state. 1 (digital HIGH) or 0 (digital LOW)
- Returns
Command success/failure
- Return type
bool
- disable_chan(chan: int) bool ¶
Set channel (int 1-5) output to LOW.
- Parameters
chan (int) – MOSFET output channel number [1-5]
- Returns
Command success/failure
- Return type
bool
- enable_chan(chan: int) bool ¶
Set channel (int 1-5) output to HIGH.
- Parameters
chan (int {1-5}) – MOSFET output channel number [1-5]
- Returns
Command success/failure
- Return type
bool
- heartbeat() bool ¶
Ping FETbox, used to confirm active/responsive connection.
- Returns
Heartbeat found / ping acknowledged
- Return type
bool
- hit_hold_chan(chan: int, duty: float = 0.5) bool ¶
Hit-and-hold for efficient solenoid operation. Sets output HIGH for short period then reduces effective output voltage via PWM.
- Parameters
chan (int {1-5}) – MOSFET output channel number [1-5]
duty (float {0.0-1.0}, default=0.5) – Fraction of max PWM outpuyt after initial ‘hit’ delay.
- Returns
Command success/failure
- Return type
bool
- kill()¶
Kill any threads and close the FETbox serial port
- pwm_chan(chan: int, pwm: int) bool ¶
Set given FETbox output channel PWM value.
- Parameters
chan (int {1-5}) – MOSFET output channel number [1-5]
pwm (int {0-255}) – 8-bit PWM value.
- Returns
Command success/failure
- Return type
bool
- query_ID() int ¶
Get the FETbox’s unique ID, as defined in firmware.
- Returns
FETbox’s interntal ID [0-9]
- Return type
int
- send_cmd(cmd: str, attempts: int = 3) bool ¶
Send arbitrary command strings. Expect pass/fail-type response from FETbox. Will retry a set number of times if the command fails to execute successfully.
Used internally for all FETbox commands.
- Parameters
cmd (str) – Command string, format varies depending on command.
attempts (int, default=3) – Maximum number of retry attempts before command failure.
- Returns
Command success/failure
- Return type
bool
- send_query(cmd: str, attempts: int = 3) str ¶
Send arbitrary query string. Expects a LF-terminated response. Will retry a set number of times if the query fails to yield a parsable response.
Used internally for all FETbox queries.
- Parameters
cmd (str) – Query string
attempts (int) – Maximum number of retry attempts before query failure.
- Returns
Query response string.
- Return type
str
- plateflo.fetbox.auto_connect_fetbox(baud: int = 115200) Dict[int, plateflo.fetbox.FETbox] ¶
Automatically connect to FETbox(es).
- Parameters
baud (int, default=115200) – Serial baud rate.
- Returns
FETbox objects keyed by respective ID
- Return type
dict[int, FETbox]
- Raises
ConnectionError – No connected FETbox detected Non-unique FETbox device IDs detected
- plateflo.fetbox.scan_for_fetbox(baud: int = 115200) List[Dict[str, int]] ¶
Scans serial ports for any connected PlateFlo FETbox controllers.
- Parameters
baud (int, default=115200) – Serial baud rate.
- Returns
One dict per FETbox containing port (str) and id (int). Empty if none detected.
- Return type
list[dict[str, int]]