ydpg
– basic YDPG-01 functions
Constants
Name |
Value |
---|---|
ydpg.USB_DISCONNECTED |
0 |
ydpg.USB_POWERED |
1 |
ydpg.USB_CONNECTED |
2 |
ydpg.USB_COM_PORT |
3 |
Functions
- ydpg.sync()
Flush file system cache to internal flash disc. Force saving of changed Gateway settings (NMEA 2000 address, etc.).
- ydpg.busvoltage()
Can be used to detect the connection to NMEA 2000 network: busvoltage() > 7.
Minimum measurable voltage is 3V, maximum is 16V. Internal capacitor takes up to 10 seconds to self discharge if voltage is less than 7V.
- Returns:
CAN bus voltage.
- Return type:
- ydpg.cputemp()
- Returns:
MCU internal temperature in °C, not correlated to MCU load.
- Return type:
- ydpg.usbvcp()
Returns the virtual COM port parameters set by the PC application. These settings do not affect the actual speed of data exchange through the USB connection, but can be used in the user program to initialize e.g. NMEA 0183 ports to control the speed from the PC.
Parameters are returned in the same order and format as in
pyb.UART.init()
:baudrate
,bits
,parity
,stop
.n0183.deinit() def usb_clbk(state): global uart_rx, uart_tx if state == ydpg.USB_COM_PORT: params = ydpg.usbvcp() uart_rx.init(*params) uart_tx.init(*params) ydpg.usbcallback(usb_clbk)
- ydpg.usbclear()
Clear the transmit buffer of the USB virtual COM port. This function can be called in the USB state callback to remove the Python Gateway welcome message or obsolete data printed by user code.
Classes
- class ydpg.LED(state=LED.OFF, manual=False)
Initializes the Gateway’s LED and starts the periodic flashing of the normal operating signal sequence (see User Manual). The initialization code is usually included in
boot.py
. The sequence consists of five flashes, the user can add the sixth flash to the sequence to indicate the state of the program.#
Color
1
RED if an error is detected on the CAN bus (NMEA 2000), otherwise GREEN.
2
GREEN if data is received from CAN bus, otherwise RED.
3
GREEN when data has been sent to the CAN bus, otherwise RED.
4
GREEN when line feed character (ASCII 10) is received from UART, otherwise RED.
5
GREEN when line feed character has been sent to UART, otherwise RED.
6
User defined, will be absent from the sequence if the user program doesn’t set it’s state.
The
manual()
method can be used to cancel the periodic flashing and allow the user code to take full control of the LED.Constants
Name
Value
LED.OFF
0
LED.RED
1
LED.GREEN
2
Methods
- deinit()
Turn off the LED and deinitialize the object.
- state([state])
Set LED state. In the normal flashing sequence, this method sets the color of the sixth flash in the sequence (see constants). When the manual LED control is used, this method is used to switch the LED off or on and to set it’s color.
- once([state])
Overrides the color of the sixths flash in the normal flash sequence for the next flash sequence only. It can be used to signal the occurrence of an event. This method has no effect when manual LED control is used.
- manual([manual])
Turns on or off manual control of Gateway’s LED.
- off()
In manual LED control mode, the equivalent of
LED.state(LED.OFF)
, otherwise the equivalent ofLED.once(LED.OFF)
.
- red()
In manual LED control mode, the equivalent of
LED.state(LED.RED)
, otherwise the equivalent ofLED.once(LED.RED)
.
- green()
In manual LED control mode, the equivalent of
LED.state(LED.GREEN)
, otherwise the equivalent ofLED.once(LED.GREEN)
.