Message
— Initialize a Loconet message from a byte array.</>Unknown
— An Unknown message simply holds the data bytes.</>PowerOn
— A PowerOn message represents a global track power on message.</>PowerOff
— A PowerOff message represents a global track power off message.</>FunctionGroup1
— A FunctionGroup1 message represents a slot function status change.</>FunctionGroupSound
— A FunctionGroupSound message represents a slot function status change.</>FunctionGroup2
— A FunctionGroup2 message represents a slot function status change.</>FunctionGroup3
— A FunctionGroup3 message represents a slot function status change.</>RequestSwitchFunction
— A RequestSwitchFunction message represents a request for a switch status change.</>SwitchState
— A SwitchState message represents a switch status.</>RequestSwitchState
— A RequestSwitchState message represents a request for a switch status update.</>SensorState
— A SensorState message represents a sensor's status.</>LongAcknowledge
— Initialize a Loconet message from a byte array.</>RequestSlotData
— Initialize a Loconet message from a byte array.</>SlotDataReturn
— Initialize a Loconet message from a byte array.</>WriteSlotData
— Initialize a Loconet message from a byte array.</>SlotSpeed
— Initialize a Loconet message from a byte array.</>RequestLocAddress
— Initialize a Loconet message from a byte array.</>MoveSlots
— Initialize a Loconet message from a byte array.</>CaptureTimeStamp
— Initialize a Loconet message from a byte array.</>
pylnlib.Message.
Message
(
data
)
Initialize a Loconet message from a byte array.
Represents a basic LocoNet message. Several subclasses are provided to implemented actual messages.
The 'opcode' (message type) is determined from byte 0, The length of the data (incl. the checksum) is determined by bits in the first byte and the second byte (if it is a variable byte message) The checksum is the last byte in the data. If the last byte in the data is 0, no check is done, so you can create a message from scratch and calculate the checksum later.
data
(bytearray) — the bytes of the message
ValueError
— If the length of the byte array does not match the encoded length, a ValueError is raised.ValueError
— If the calculated checksum doesn match the last byte of the byte array, a ValueError is raised (unless the last data byte is 0)
checksum
(
msg
)
(byte) — Calculate the checksum over the message.</>from_data
(
data
)
(Message) — A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.</>hexdata
(
)
(list[str]) — Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.</>length
(
opcode
,nextbyte
)
(_type_) — Determine the length of a LocoNet message based on its opcode and next byte.</>sensoraddress
(
d0
,d1
)
— Return a 12-bit sensor address from the data.</>slotaddress
(
d0
,d1
)
— Return an 11-bit slot address from the data.</>switchaddress
(
d0
,d1
)
— Return an 11-bit switch address from the data.</>updateChecksum
(
)
— Calculate the checksum of the data and store it in the last byte.</>
hexdata
(
)
Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.
a list of lowercase hexadecimal number with leading zeros.
updateChecksum
(
)
Calculate the checksum of the data and store it in the last byte.
length
(
opcode
, nextbyte
)
Determine the length of a LocoNet message based on its opcode and next byte.
The length is inclusive the opcode and the final checksum.
opcode
(byte) — the opcodenextbyte
(byte) — the total number of bytes in the message if the opcode indicates this is a variable length message.
description
from_data
(
data
)
A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.
data
(bytearray) — the bytes of the message
a subclass of Message
Todo
not all possible opcodes/message types are implemented yet.
checksum
(
msg
)
Calculate the checksum over the message.
The checksum is calculated over all bytes.
This method does NOT overwrite the checksum byte, but simply returns it.
msg
(bytes) — the data
the checksum over all the bytes
sensoraddress
(
d0
, d1
)
Return a 12-bit sensor address from the data.
Sensors start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the sensor addressd1
(byte) — second byte of the sensor address
Note
sensor addresses are 12 bits running from 11 (most significant) to 0 (least significant) bits 11 - 8 and bit 0 are encoded in byte d1, bits 7 - 1 in byte d0.
switchaddress
(
d0
, d1
)
Return an 11-bit switch address from the data.
Switches start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
switch addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
slotaddress
(
d0
, d1
)
Return an 11-bit slot address from the data.
Slots start from zero (but slot 0 is special, as are several others >= 0x70).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
slot addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
Note
all addresses > 111 are considered special and not used for locos.
pylnlib.Message.
Unknown
(
data
)
An Unknown message simply holds the data bytes.
data
(bytearray) — the bytes of the message
checksum
(
msg
)
(byte) — Calculate the checksum over the message.</>from_data
(
data
)
(Message) — A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.</>hexdata
(
)
(list[str]) — Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.</>length
(
opcode
,nextbyte
)
(_type_) — Determine the length of a LocoNet message based on its opcode and next byte.</>sensoraddress
(
d0
,d1
)
— Return a 12-bit sensor address from the data.</>slotaddress
(
d0
,d1
)
— Return an 11-bit slot address from the data.</>switchaddress
(
d0
,d1
)
— Return an 11-bit switch address from the data.</>updateChecksum
(
)
— Calculate the checksum of the data and store it in the last byte.</>
hexdata
(
)
Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.
a list of lowercase hexadecimal number with leading zeros.
updateChecksum
(
)
Calculate the checksum of the data and store it in the last byte.
length
(
opcode
, nextbyte
)
Determine the length of a LocoNet message based on its opcode and next byte.
The length is inclusive the opcode and the final checksum.
opcode
(byte) — the opcodenextbyte
(byte) — the total number of bytes in the message if the opcode indicates this is a variable length message.
description
from_data
(
data
)
A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.
data
(bytearray) — the bytes of the message
a subclass of Message
Todo
not all possible opcodes/message types are implemented yet.
checksum
(
msg
)
Calculate the checksum over the message.
The checksum is calculated over all bytes.
This method does NOT overwrite the checksum byte, but simply returns it.
msg
(bytes) — the data
the checksum over all the bytes
sensoraddress
(
d0
, d1
)
Return a 12-bit sensor address from the data.
Sensors start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the sensor addressd1
(byte) — second byte of the sensor address
Note
sensor addresses are 12 bits running from 11 (most significant) to 0 (least significant) bits 11 - 8 and bit 0 are encoded in byte d1, bits 7 - 1 in byte d0.
switchaddress
(
d0
, d1
)
Return an 11-bit switch address from the data.
Switches start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
switch addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
slotaddress
(
d0
, d1
)
Return an 11-bit slot address from the data.
Slots start from zero (but slot 0 is special, as are several others >= 0x70).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
slot addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
Note
all addresses > 111 are considered special and not used for locos.
pylnlib.Message.
PowerOn
(
data=None
)
A PowerOn message represents a global track power on message.
data
(bytes, optional) — raw message data. Defaults to None.
checksum
(
msg
)
(byte) — Calculate the checksum over the message.</>from_data
(
data
)
(Message) — A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.</>hexdata
(
)
(list[str]) — Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.</>length
(
opcode
,nextbyte
)
(_type_) — Determine the length of a LocoNet message based on its opcode and next byte.</>sensoraddress
(
d0
,d1
)
— Return a 12-bit sensor address from the data.</>slotaddress
(
d0
,d1
)
— Return an 11-bit slot address from the data.</>switchaddress
(
d0
,d1
)
— Return an 11-bit switch address from the data.</>updateChecksum
(
)
— Calculate the checksum of the data and store it in the last byte.</>
hexdata
(
)
Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.
a list of lowercase hexadecimal number with leading zeros.
updateChecksum
(
)
Calculate the checksum of the data and store it in the last byte.
length
(
opcode
, nextbyte
)
Determine the length of a LocoNet message based on its opcode and next byte.
The length is inclusive the opcode and the final checksum.
opcode
(byte) — the opcodenextbyte
(byte) — the total number of bytes in the message if the opcode indicates this is a variable length message.
description
from_data
(
data
)
A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.
data
(bytearray) — the bytes of the message
a subclass of Message
Todo
not all possible opcodes/message types are implemented yet.
checksum
(
msg
)
Calculate the checksum over the message.
The checksum is calculated over all bytes.
This method does NOT overwrite the checksum byte, but simply returns it.
msg
(bytes) — the data
the checksum over all the bytes
sensoraddress
(
d0
, d1
)
Return a 12-bit sensor address from the data.
Sensors start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the sensor addressd1
(byte) — second byte of the sensor address
Note
sensor addresses are 12 bits running from 11 (most significant) to 0 (least significant) bits 11 - 8 and bit 0 are encoded in byte d1, bits 7 - 1 in byte d0.
switchaddress
(
d0
, d1
)
Return an 11-bit switch address from the data.
Switches start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
switch addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
slotaddress
(
d0
, d1
)
Return an 11-bit slot address from the data.
Slots start from zero (but slot 0 is special, as are several others >= 0x70).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
slot addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
Note
all addresses > 111 are considered special and not used for locos.
pylnlib.Message.
PowerOff
(
data=None
)
A PowerOff message represents a global track power off message.
data
(bytes, optional) — raw message data. Defaults to None.
checksum
(
msg
)
(byte) — Calculate the checksum over the message.</>from_data
(
data
)
(Message) — A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.</>hexdata
(
)
(list[str]) — Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.</>length
(
opcode
,nextbyte
)
(_type_) — Determine the length of a LocoNet message based on its opcode and next byte.</>sensoraddress
(
d0
,d1
)
— Return a 12-bit sensor address from the data.</>slotaddress
(
d0
,d1
)
— Return an 11-bit slot address from the data.</>switchaddress
(
d0
,d1
)
— Return an 11-bit switch address from the data.</>updateChecksum
(
)
— Calculate the checksum of the data and store it in the last byte.</>
hexdata
(
)
Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.
a list of lowercase hexadecimal number with leading zeros.
updateChecksum
(
)
Calculate the checksum of the data and store it in the last byte.
length
(
opcode
, nextbyte
)
Determine the length of a LocoNet message based on its opcode and next byte.
The length is inclusive the opcode and the final checksum.
opcode
(byte) — the opcodenextbyte
(byte) — the total number of bytes in the message if the opcode indicates this is a variable length message.
description
from_data
(
data
)
A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.
data
(bytearray) — the bytes of the message
a subclass of Message
Todo
not all possible opcodes/message types are implemented yet.
checksum
(
msg
)
Calculate the checksum over the message.
The checksum is calculated over all bytes.
This method does NOT overwrite the checksum byte, but simply returns it.
msg
(bytes) — the data
the checksum over all the bytes
sensoraddress
(
d0
, d1
)
Return a 12-bit sensor address from the data.
Sensors start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the sensor addressd1
(byte) — second byte of the sensor address
Note
sensor addresses are 12 bits running from 11 (most significant) to 0 (least significant) bits 11 - 8 and bit 0 are encoded in byte d1, bits 7 - 1 in byte d0.
switchaddress
(
d0
, d1
)
Return an 11-bit switch address from the data.
Switches start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
switch addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
slotaddress
(
d0
, d1
)
Return an 11-bit slot address from the data.
Slots start from zero (but slot 0 is special, as are several others >= 0x70).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
slot addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
Note
all addresses > 111 are considered special and not used for locos.
pylnlib.Message.
FunctionGroup1
(
data=None
, slot=None
, dir=None
, f0=None
, f1=None
, f2=None
, f3=None
, f4=None
)
A FunctionGroup1 message represents a slot function status change.
It holds the status for the direction and functions f0 - f4.
data
(bytes, optional) — raw message data. Defaults to None.slot
(int, optional) — slot number. Defaults to None.dir
(bool, optional) — running direction. Defaults to None.f0
(bool, optional) — function 0 (running lights). Defaults to None.f1
(bool, optional) — function 1 (engine sound). Defaults to None.f2
(bool, optional) — function 2 (whistle). Defaults to None.f3
(bool, optional) — function 3. Defaults to None.f4
(bool, optional) — function 4. Defaults to None.
ValueError
— if data is specified at the same time as one of the other arguments.
checksum
(
msg
)
(byte) — Calculate the checksum over the message.</>from_data
(
data
)
(Message) — A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.</>hexdata
(
)
(list[str]) — Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.</>length
(
opcode
,nextbyte
)
(_type_) — Determine the length of a LocoNet message based on its opcode and next byte.</>sensoraddress
(
d0
,d1
)
— Return a 12-bit sensor address from the data.</>slotaddress
(
d0
,d1
)
— Return an 11-bit slot address from the data.</>switchaddress
(
d0
,d1
)
— Return an 11-bit switch address from the data.</>updateChecksum
(
)
— Calculate the checksum of the data and store it in the last byte.</>
hexdata
(
)
Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.
a list of lowercase hexadecimal number with leading zeros.
updateChecksum
(
)
Calculate the checksum of the data and store it in the last byte.
length
(
opcode
, nextbyte
)
Determine the length of a LocoNet message based on its opcode and next byte.
The length is inclusive the opcode and the final checksum.
opcode
(byte) — the opcodenextbyte
(byte) — the total number of bytes in the message if the opcode indicates this is a variable length message.
description
from_data
(
data
)
A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.
data
(bytearray) — the bytes of the message
a subclass of Message
Todo
not all possible opcodes/message types are implemented yet.
checksum
(
msg
)
Calculate the checksum over the message.
The checksum is calculated over all bytes.
This method does NOT overwrite the checksum byte, but simply returns it.
msg
(bytes) — the data
the checksum over all the bytes
sensoraddress
(
d0
, d1
)
Return a 12-bit sensor address from the data.
Sensors start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the sensor addressd1
(byte) — second byte of the sensor address
Note
sensor addresses are 12 bits running from 11 (most significant) to 0 (least significant) bits 11 - 8 and bit 0 are encoded in byte d1, bits 7 - 1 in byte d0.
switchaddress
(
d0
, d1
)
Return an 11-bit switch address from the data.
Switches start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
switch addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
slotaddress
(
d0
, d1
)
Return an 11-bit slot address from the data.
Slots start from zero (but slot 0 is special, as are several others >= 0x70).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
slot addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
Note
all addresses > 111 are considered special and not used for locos.
pylnlib.Message.
FunctionGroupSound
(
data=None
, slot=None
, f5=None
, f6=None
, f7=None
, f8=None
)
A FunctionGroupSound message represents a slot function status change.
It holds the status for functions f5 - f8.
data
(bytes, optional) — raw message data. Defaults to None.slot
(int, optional) — slot number. Defaults to None.f5
(bool, optional) — function 5. Defaults to None.f6
(bool, optional) — function 6. Defaults to None.f7
(bool, optional) — function 7. Defaults to None.f8
(bool, optional) — function 8. Defaults to None.
ValueError
— if data is specified at the same time as one of the other arguments.
checksum
(
msg
)
(byte) — Calculate the checksum over the message.</>from_data
(
data
)
(Message) — A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.</>hexdata
(
)
(list[str]) — Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.</>length
(
opcode
,nextbyte
)
(_type_) — Determine the length of a LocoNet message based on its opcode and next byte.</>sensoraddress
(
d0
,d1
)
— Return a 12-bit sensor address from the data.</>slotaddress
(
d0
,d1
)
— Return an 11-bit slot address from the data.</>switchaddress
(
d0
,d1
)
— Return an 11-bit switch address from the data.</>updateChecksum
(
)
— Calculate the checksum of the data and store it in the last byte.</>
hexdata
(
)
Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.
a list of lowercase hexadecimal number with leading zeros.
updateChecksum
(
)
Calculate the checksum of the data and store it in the last byte.
length
(
opcode
, nextbyte
)
Determine the length of a LocoNet message based on its opcode and next byte.
The length is inclusive the opcode and the final checksum.
opcode
(byte) — the opcodenextbyte
(byte) — the total number of bytes in the message if the opcode indicates this is a variable length message.
description
from_data
(
data
)
A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.
data
(bytearray) — the bytes of the message
a subclass of Message
Todo
not all possible opcodes/message types are implemented yet.
checksum
(
msg
)
Calculate the checksum over the message.
The checksum is calculated over all bytes.
This method does NOT overwrite the checksum byte, but simply returns it.
msg
(bytes) — the data
the checksum over all the bytes
sensoraddress
(
d0
, d1
)
Return a 12-bit sensor address from the data.
Sensors start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the sensor addressd1
(byte) — second byte of the sensor address
Note
sensor addresses are 12 bits running from 11 (most significant) to 0 (least significant) bits 11 - 8 and bit 0 are encoded in byte d1, bits 7 - 1 in byte d0.
switchaddress
(
d0
, d1
)
Return an 11-bit switch address from the data.
Switches start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
switch addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
slotaddress
(
d0
, d1
)
Return an 11-bit slot address from the data.
Slots start from zero (but slot 0 is special, as are several others >= 0x70).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
slot addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
Note
all addresses > 111 are considered special and not used for locos.
pylnlib.Message.
FunctionGroup2
(
data=None
, slot=None
, f9=None
, f10=None
, f11=None
, f12=None
)
A FunctionGroup2 message represents a slot function status change.
It holds the status for functions f9 - f12.
data
(bytes, optional) — raw message data. Defaults to None.slot
(int, optional) — slot number. Defaults to None.f9
(bool, optional) — function 9. Defaults to None.f10
(bool, optional) — function 10. Defaults to None.f11
(bool, optional) — function 11. Defaults to None.f12
(bool, optional) — function 12. Defaults to None.
ValueError
— if data is specified at the same time as one of the other arguments.
checksum
(
msg
)
(byte) — Calculate the checksum over the message.</>from_data
(
data
)
(Message) — A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.</>hexdata
(
)
(list[str]) — Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.</>length
(
opcode
,nextbyte
)
(_type_) — Determine the length of a LocoNet message based on its opcode and next byte.</>sensoraddress
(
d0
,d1
)
— Return a 12-bit sensor address from the data.</>slotaddress
(
d0
,d1
)
— Return an 11-bit slot address from the data.</>switchaddress
(
d0
,d1
)
— Return an 11-bit switch address from the data.</>updateChecksum
(
)
— Calculate the checksum of the data and store it in the last byte.</>
hexdata
(
)
Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.
a list of lowercase hexadecimal number with leading zeros.
updateChecksum
(
)
Calculate the checksum of the data and store it in the last byte.
length
(
opcode
, nextbyte
)
Determine the length of a LocoNet message based on its opcode and next byte.
The length is inclusive the opcode and the final checksum.
opcode
(byte) — the opcodenextbyte
(byte) — the total number of bytes in the message if the opcode indicates this is a variable length message.
description
from_data
(
data
)
A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.
data
(bytearray) — the bytes of the message
a subclass of Message
Todo
not all possible opcodes/message types are implemented yet.
checksum
(
msg
)
Calculate the checksum over the message.
The checksum is calculated over all bytes.
This method does NOT overwrite the checksum byte, but simply returns it.
msg
(bytes) — the data
the checksum over all the bytes
sensoraddress
(
d0
, d1
)
Return a 12-bit sensor address from the data.
Sensors start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the sensor addressd1
(byte) — second byte of the sensor address
Note
sensor addresses are 12 bits running from 11 (most significant) to 0 (least significant) bits 11 - 8 and bit 0 are encoded in byte d1, bits 7 - 1 in byte d0.
switchaddress
(
d0
, d1
)
Return an 11-bit switch address from the data.
Switches start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
switch addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
slotaddress
(
d0
, d1
)
Return an 11-bit slot address from the data.
Slots start from zero (but slot 0 is special, as are several others >= 0x70).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
slot addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
Note
all addresses > 111 are considered special and not used for locos.
pylnlib.Message.
FunctionGroup3
(
data=None
, slot=None
, **kwargs
)
A FunctionGroup3 message represents a slot function status change.
Depending on the fiegroup, it holds the status for functions f13 - f19, f21 - f27 or f12 + f20 +f28.
Other Parameters: f13 (bool, optional): function 13. Defaults to None. f14 (bool, optional): function 14. Defaults to None. f15 (bool, optional): function 15. Defaults to None. f16 (bool, optional): function 16. Defaults to None. f17 (bool, optional): function 17. Defaults to None. f18 (bool, optional): function 18. Defaults to None. f19 (bool, optional): function 19. Defaults to None. f21 (bool, optional): function 21. Defaults to None. f22 (bool, optional): function 22. Defaults to None. f23 (bool, optional): function 23. Defaults to None. f24 (bool, optional): function 24. Defaults to None. f25 (bool, optional): function 25. Defaults to None. f26 (bool, optional): function 26. Defaults to None. f27 (bool, optional): function 27. Defaults to None. f12 (bool, optional): function 12. Defaults to None. f20 (bool, optional): function 20. Defaults to None. f28 (bool, optional): function 28. Defaults to None.
data
(optional) — the bytes of the message
ValueError
— if data is specified at the same time as one of the other arguments.ValueError
— if an unknown argument is passed.ValueError
— if arguments from different function groups are passed at the same time.
checksum
(
msg
)
(byte) — Calculate the checksum over the message.</>from_data
(
data
)
(Message) — A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.</>hexdata
(
)
(list[str]) — Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.</>length
(
opcode
,nextbyte
)
(_type_) — Determine the length of a LocoNet message based on its opcode and next byte.</>sensoraddress
(
d0
,d1
)
— Return a 12-bit sensor address from the data.</>slotaddress
(
d0
,d1
)
— Return an 11-bit slot address from the data.</>switchaddress
(
d0
,d1
)
— Return an 11-bit switch address from the data.</>updateChecksum
(
)
— Calculate the checksum of the data and store it in the last byte.</>
hexdata
(
)
Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.
a list of lowercase hexadecimal number with leading zeros.
updateChecksum
(
)
Calculate the checksum of the data and store it in the last byte.
length
(
opcode
, nextbyte
)
Determine the length of a LocoNet message based on its opcode and next byte.
The length is inclusive the opcode and the final checksum.
opcode
(byte) — the opcodenextbyte
(byte) — the total number of bytes in the message if the opcode indicates this is a variable length message.
description
from_data
(
data
)
A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.
data
(bytearray) — the bytes of the message
a subclass of Message
Todo
not all possible opcodes/message types are implemented yet.
checksum
(
msg
)
Calculate the checksum over the message.
The checksum is calculated over all bytes.
This method does NOT overwrite the checksum byte, but simply returns it.
msg
(bytes) — the data
the checksum over all the bytes
sensoraddress
(
d0
, d1
)
Return a 12-bit sensor address from the data.
Sensors start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the sensor addressd1
(byte) — second byte of the sensor address
Note
sensor addresses are 12 bits running from 11 (most significant) to 0 (least significant) bits 11 - 8 and bit 0 are encoded in byte d1, bits 7 - 1 in byte d0.
switchaddress
(
d0
, d1
)
Return an 11-bit switch address from the data.
Switches start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
switch addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
slotaddress
(
d0
, d1
)
Return an 11-bit slot address from the data.
Slots start from zero (but slot 0 is special, as are several others >= 0x70).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
slot addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
Note
all addresses > 111 are considered special and not used for locos.
pylnlib.Message.
RequestSwitchFunction
(
data
, thrown=None
, engage=None
)
A RequestSwitchFunction message represents a request for a switch status change.
It holds the info on whether the switch should be closed or thrown, as well as whether the switch motor should be engaged.
data
(bytearray(4) — either 4 bytes of raw data or the switch addressthrown
(bool, optional) — if a switch address is given, this should hold thrown or closed. Defaults to None.engage
(bool, optional) — if a switch address is given, this should signal whether the motor should be engaged . Defaults to None.
checksum
(
msg
)
(byte) — Calculate the checksum over the message.</>from_data
(
data
)
(Message) — A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.</>hexdata
(
)
(list[str]) — Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.</>length
(
opcode
,nextbyte
)
(_type_) — Determine the length of a LocoNet message based on its opcode and next byte.</>sensoraddress
(
d0
,d1
)
— Return a 12-bit sensor address from the data.</>slotaddress
(
d0
,d1
)
— Return an 11-bit slot address from the data.</>switchaddress
(
d0
,d1
)
— Return an 11-bit switch address from the data.</>updateChecksum
(
)
— Calculate the checksum of the data and store it in the last byte.</>
hexdata
(
)
Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.
a list of lowercase hexadecimal number with leading zeros.
updateChecksum
(
)
Calculate the checksum of the data and store it in the last byte.
length
(
opcode
, nextbyte
)
Determine the length of a LocoNet message based on its opcode and next byte.
The length is inclusive the opcode and the final checksum.
opcode
(byte) — the opcodenextbyte
(byte) — the total number of bytes in the message if the opcode indicates this is a variable length message.
description
from_data
(
data
)
A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.
data
(bytearray) — the bytes of the message
a subclass of Message
Todo
not all possible opcodes/message types are implemented yet.
checksum
(
msg
)
Calculate the checksum over the message.
The checksum is calculated over all bytes.
This method does NOT overwrite the checksum byte, but simply returns it.
msg
(bytes) — the data
the checksum over all the bytes
sensoraddress
(
d0
, d1
)
Return a 12-bit sensor address from the data.
Sensors start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the sensor addressd1
(byte) — second byte of the sensor address
Note
sensor addresses are 12 bits running from 11 (most significant) to 0 (least significant) bits 11 - 8 and bit 0 are encoded in byte d1, bits 7 - 1 in byte d0.
switchaddress
(
d0
, d1
)
Return an 11-bit switch address from the data.
Switches start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
switch addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
slotaddress
(
d0
, d1
)
Return an 11-bit slot address from the data.
Slots start from zero (but slot 0 is special, as are several others >= 0x70).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
slot addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
Note
all addresses > 111 are considered special and not used for locos.
pylnlib.Message.
SwitchState
(
id
, thrown=None
, engage=None
)
A SwitchState message represents a switch status.
It holds the info on whether the switch is closed or thrown, as well as whether the switch motor is engaged.
thrown
(bool, optional) — if a switch address is given, this should hold thrown or closed. Defaults to None.engage
(bool, optional) — if a switch address is given, this should signal whether the motor should be engaged . Defaults to None.
checksum
(
msg
)
(byte) — Calculate the checksum over the message.</>from_data
(
data
)
(Message) — A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.</>hexdata
(
)
(list[str]) — Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.</>length
(
opcode
,nextbyte
)
(_type_) — Determine the length of a LocoNet message based on its opcode and next byte.</>sensoraddress
(
d0
,d1
)
— Return a 12-bit sensor address from the data.</>slotaddress
(
d0
,d1
)
— Return an 11-bit slot address from the data.</>switchaddress
(
d0
,d1
)
— Return an 11-bit switch address from the data.</>updateChecksum
(
)
— Calculate the checksum of the data and store it in the last byte.</>
hexdata
(
)
Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.
a list of lowercase hexadecimal number with leading zeros.
updateChecksum
(
)
Calculate the checksum of the data and store it in the last byte.
length
(
opcode
, nextbyte
)
Determine the length of a LocoNet message based on its opcode and next byte.
The length is inclusive the opcode and the final checksum.
opcode
(byte) — the opcodenextbyte
(byte) — the total number of bytes in the message if the opcode indicates this is a variable length message.
description
from_data
(
data
)
A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.
data
(bytearray) — the bytes of the message
a subclass of Message
Todo
not all possible opcodes/message types are implemented yet.
checksum
(
msg
)
Calculate the checksum over the message.
The checksum is calculated over all bytes.
This method does NOT overwrite the checksum byte, but simply returns it.
msg
(bytes) — the data
the checksum over all the bytes
sensoraddress
(
d0
, d1
)
Return a 12-bit sensor address from the data.
Sensors start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the sensor addressd1
(byte) — second byte of the sensor address
Note
sensor addresses are 12 bits running from 11 (most significant) to 0 (least significant) bits 11 - 8 and bit 0 are encoded in byte d1, bits 7 - 1 in byte d0.
switchaddress
(
d0
, d1
)
Return an 11-bit switch address from the data.
Switches start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
switch addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
slotaddress
(
d0
, d1
)
Return an 11-bit slot address from the data.
Slots start from zero (but slot 0 is special, as are several others >= 0x70).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
slot addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
Note
all addresses > 111 are considered special and not used for locos.
pylnlib.Message.
RequestSwitchState
(
id
)
A RequestSwitchState message represents a request for a switch status update.
checksum
(
msg
)
(byte) — Calculate the checksum over the message.</>from_data
(
data
)
(Message) — A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.</>hexdata
(
)
(list[str]) — Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.</>length
(
opcode
,nextbyte
)
(_type_) — Determine the length of a LocoNet message based on its opcode and next byte.</>sensoraddress
(
d0
,d1
)
— Return a 12-bit sensor address from the data.</>slotaddress
(
d0
,d1
)
— Return an 11-bit slot address from the data.</>switchaddress
(
d0
,d1
)
— Return an 11-bit switch address from the data.</>updateChecksum
(
)
— Calculate the checksum of the data and store it in the last byte.</>
hexdata
(
)
Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.
a list of lowercase hexadecimal number with leading zeros.
updateChecksum
(
)
Calculate the checksum of the data and store it in the last byte.
length
(
opcode
, nextbyte
)
Determine the length of a LocoNet message based on its opcode and next byte.
The length is inclusive the opcode and the final checksum.
opcode
(byte) — the opcodenextbyte
(byte) — the total number of bytes in the message if the opcode indicates this is a variable length message.
description
from_data
(
data
)
A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.
data
(bytearray) — the bytes of the message
a subclass of Message
Todo
not all possible opcodes/message types are implemented yet.
checksum
(
msg
)
Calculate the checksum over the message.
The checksum is calculated over all bytes.
This method does NOT overwrite the checksum byte, but simply returns it.
msg
(bytes) — the data
the checksum over all the bytes
sensoraddress
(
d0
, d1
)
Return a 12-bit sensor address from the data.
Sensors start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the sensor addressd1
(byte) — second byte of the sensor address
Note
sensor addresses are 12 bits running from 11 (most significant) to 0 (least significant) bits 11 - 8 and bit 0 are encoded in byte d1, bits 7 - 1 in byte d0.
switchaddress
(
d0
, d1
)
Return an 11-bit switch address from the data.
Switches start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
switch addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
slotaddress
(
d0
, d1
)
Return an 11-bit slot address from the data.
Slots start from zero (but slot 0 is special, as are several others >= 0x70).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
slot addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
Note
all addresses > 111 are considered special and not used for locos.
pylnlib.Message.
SensorState
(
id
, level=None
)
A SensorState message represents a sensor's status.
It holds the info on whether the sensor is on or off.
id
(bytearray(4) — either 4 bytes of raw data or the switch addresslevel
(bool, optional) — if a sensor address is given, this should hold True or False. Defaults to None.
checksum
(
msg
)
(byte) — Calculate the checksum over the message.</>from_data
(
data
)
(Message) — A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.</>hexdata
(
)
(list[str]) — Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.</>length
(
opcode
,nextbyte
)
(_type_) — Determine the length of a LocoNet message based on its opcode and next byte.</>sensoraddress
(
d0
,d1
)
— Return a 12-bit sensor address from the data.</>slotaddress
(
d0
,d1
)
— Return an 11-bit slot address from the data.</>switchaddress
(
d0
,d1
)
— Return an 11-bit switch address from the data.</>updateChecksum
(
)
— Calculate the checksum of the data and store it in the last byte.</>
hexdata
(
)
Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.
a list of lowercase hexadecimal number with leading zeros.
updateChecksum
(
)
Calculate the checksum of the data and store it in the last byte.
length
(
opcode
, nextbyte
)
Determine the length of a LocoNet message based on its opcode and next byte.
The length is inclusive the opcode and the final checksum.
opcode
(byte) — the opcodenextbyte
(byte) — the total number of bytes in the message if the opcode indicates this is a variable length message.
description
from_data
(
data
)
A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.
data
(bytearray) — the bytes of the message
a subclass of Message
Todo
not all possible opcodes/message types are implemented yet.
checksum
(
msg
)
Calculate the checksum over the message.
The checksum is calculated over all bytes.
This method does NOT overwrite the checksum byte, but simply returns it.
msg
(bytes) — the data
the checksum over all the bytes
sensoraddress
(
d0
, d1
)
Return a 12-bit sensor address from the data.
Sensors start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the sensor addressd1
(byte) — second byte of the sensor address
Note
sensor addresses are 12 bits running from 11 (most significant) to 0 (least significant) bits 11 - 8 and bit 0 are encoded in byte d1, bits 7 - 1 in byte d0.
switchaddress
(
d0
, d1
)
Return an 11-bit switch address from the data.
Switches start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
switch addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
slotaddress
(
d0
, d1
)
Return an 11-bit slot address from the data.
Slots start from zero (but slot 0 is special, as are several others >= 0x70).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
slot addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
Note
all addresses > 111 are considered special and not used for locos.
pylnlib.Message.
LongAcknowledge
(
data
)
Initialize a Loconet message from a byte array.
Represents a basic LocoNet message. Several subclasses are provided to implemented actual messages.
The 'opcode' (message type) is determined from byte 0, The length of the data (incl. the checksum) is determined by bits in the first byte and the second byte (if it is a variable byte message) The checksum is the last byte in the data. If the last byte in the data is 0, no check is done, so you can create a message from scratch and calculate the checksum later.
data
(bytearray) — the bytes of the message
ValueError
— If the length of the byte array does not match the encoded length, a ValueError is raised.ValueError
— If the calculated checksum doesn match the last byte of the byte array, a ValueError is raised (unless the last data byte is 0)
checksum
(
msg
)
(byte) — Calculate the checksum over the message.</>from_data
(
data
)
(Message) — A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.</>hexdata
(
)
(list[str]) — Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.</>length
(
opcode
,nextbyte
)
(_type_) — Determine the length of a LocoNet message based on its opcode and next byte.</>sensoraddress
(
d0
,d1
)
— Return a 12-bit sensor address from the data.</>slotaddress
(
d0
,d1
)
— Return an 11-bit slot address from the data.</>switchaddress
(
d0
,d1
)
— Return an 11-bit switch address from the data.</>updateChecksum
(
)
— Calculate the checksum of the data and store it in the last byte.</>
hexdata
(
)
Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.
a list of lowercase hexadecimal number with leading zeros.
updateChecksum
(
)
Calculate the checksum of the data and store it in the last byte.
length
(
opcode
, nextbyte
)
Determine the length of a LocoNet message based on its opcode and next byte.
The length is inclusive the opcode and the final checksum.
opcode
(byte) — the opcodenextbyte
(byte) — the total number of bytes in the message if the opcode indicates this is a variable length message.
description
from_data
(
data
)
A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.
data
(bytearray) — the bytes of the message
a subclass of Message
Todo
not all possible opcodes/message types are implemented yet.
checksum
(
msg
)
Calculate the checksum over the message.
The checksum is calculated over all bytes.
This method does NOT overwrite the checksum byte, but simply returns it.
msg
(bytes) — the data
the checksum over all the bytes
sensoraddress
(
d0
, d1
)
Return a 12-bit sensor address from the data.
Sensors start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the sensor addressd1
(byte) — second byte of the sensor address
Note
sensor addresses are 12 bits running from 11 (most significant) to 0 (least significant) bits 11 - 8 and bit 0 are encoded in byte d1, bits 7 - 1 in byte d0.
switchaddress
(
d0
, d1
)
Return an 11-bit switch address from the data.
Switches start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
switch addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
slotaddress
(
d0
, d1
)
Return an 11-bit slot address from the data.
Slots start from zero (but slot 0 is special, as are several others >= 0x70).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
slot addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
Note
all addresses > 111 are considered special and not used for locos.
pylnlib.Message.
RequestSlotData
(
slot
)
Initialize a Loconet message from a byte array.
Represents a basic LocoNet message. Several subclasses are provided to implemented actual messages.
The 'opcode' (message type) is determined from byte 0, The length of the data (incl. the checksum) is determined by bits in the first byte and the second byte (if it is a variable byte message) The checksum is the last byte in the data. If the last byte in the data is 0, no check is done, so you can create a message from scratch and calculate the checksum later.
ValueError
— If the length of the byte array does not match the encoded length, a ValueError is raised.ValueError
— If the calculated checksum doesn match the last byte of the byte array, a ValueError is raised (unless the last data byte is 0)
checksum
(
msg
)
(byte) — Calculate the checksum over the message.</>from_data
(
data
)
(Message) — A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.</>hexdata
(
)
(list[str]) — Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.</>length
(
opcode
,nextbyte
)
(_type_) — Determine the length of a LocoNet message based on its opcode and next byte.</>sensoraddress
(
d0
,d1
)
— Return a 12-bit sensor address from the data.</>slotaddress
(
d0
,d1
)
— Return an 11-bit slot address from the data.</>switchaddress
(
d0
,d1
)
— Return an 11-bit switch address from the data.</>updateChecksum
(
)
— Calculate the checksum of the data and store it in the last byte.</>
hexdata
(
)
Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.
a list of lowercase hexadecimal number with leading zeros.
updateChecksum
(
)
Calculate the checksum of the data and store it in the last byte.
length
(
opcode
, nextbyte
)
Determine the length of a LocoNet message based on its opcode and next byte.
The length is inclusive the opcode and the final checksum.
opcode
(byte) — the opcodenextbyte
(byte) — the total number of bytes in the message if the opcode indicates this is a variable length message.
description
from_data
(
data
)
A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.
data
(bytearray) — the bytes of the message
a subclass of Message
Todo
not all possible opcodes/message types are implemented yet.
checksum
(
msg
)
Calculate the checksum over the message.
The checksum is calculated over all bytes.
This method does NOT overwrite the checksum byte, but simply returns it.
msg
(bytes) — the data
the checksum over all the bytes
sensoraddress
(
d0
, d1
)
Return a 12-bit sensor address from the data.
Sensors start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the sensor addressd1
(byte) — second byte of the sensor address
Note
sensor addresses are 12 bits running from 11 (most significant) to 0 (least significant) bits 11 - 8 and bit 0 are encoded in byte d1, bits 7 - 1 in byte d0.
switchaddress
(
d0
, d1
)
Return an 11-bit switch address from the data.
Switches start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
switch addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
slotaddress
(
d0
, d1
)
Return an 11-bit slot address from the data.
Slots start from zero (but slot 0 is special, as are several others >= 0x70).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
slot addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
Note
all addresses > 111 are considered special and not used for locos.
pylnlib.Message.
SlotDataReturn
(
data
)
Initialize a Loconet message from a byte array.
Represents a basic LocoNet message. Several subclasses are provided to implemented actual messages.
The 'opcode' (message type) is determined from byte 0, The length of the data (incl. the checksum) is determined by bits in the first byte and the second byte (if it is a variable byte message) The checksum is the last byte in the data. If the last byte in the data is 0, no check is done, so you can create a message from scratch and calculate the checksum later.
data
(bytearray) — the bytes of the message
ValueError
— If the length of the byte array does not match the encoded length, a ValueError is raised.ValueError
— If the calculated checksum doesn match the last byte of the byte array, a ValueError is raised (unless the last data byte is 0)
checksum
(
msg
)
(byte) — Calculate the checksum over the message.</>from_data
(
data
)
(Message) — A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.</>hexdata
(
)
(list[str]) — Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.</>length
(
opcode
,nextbyte
)
(_type_) — Determine the length of a LocoNet message based on its opcode and next byte.</>sensoraddress
(
d0
,d1
)
— Return a 12-bit sensor address from the data.</>slotaddress
(
d0
,d1
)
— Return an 11-bit slot address from the data.</>switchaddress
(
d0
,d1
)
— Return an 11-bit switch address from the data.</>updateChecksum
(
)
— Calculate the checksum of the data and store it in the last byte.</>
hexdata
(
)
Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.
a list of lowercase hexadecimal number with leading zeros.
updateChecksum
(
)
Calculate the checksum of the data and store it in the last byte.
length
(
opcode
, nextbyte
)
Determine the length of a LocoNet message based on its opcode and next byte.
The length is inclusive the opcode and the final checksum.
opcode
(byte) — the opcodenextbyte
(byte) — the total number of bytes in the message if the opcode indicates this is a variable length message.
description
from_data
(
data
)
A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.
data
(bytearray) — the bytes of the message
a subclass of Message
Todo
not all possible opcodes/message types are implemented yet.
checksum
(
msg
)
Calculate the checksum over the message.
The checksum is calculated over all bytes.
This method does NOT overwrite the checksum byte, but simply returns it.
msg
(bytes) — the data
the checksum over all the bytes
sensoraddress
(
d0
, d1
)
Return a 12-bit sensor address from the data.
Sensors start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the sensor addressd1
(byte) — second byte of the sensor address
Note
sensor addresses are 12 bits running from 11 (most significant) to 0 (least significant) bits 11 - 8 and bit 0 are encoded in byte d1, bits 7 - 1 in byte d0.
switchaddress
(
d0
, d1
)
Return an 11-bit switch address from the data.
Switches start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
switch addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
slotaddress
(
d0
, d1
)
Return an 11-bit slot address from the data.
Slots start from zero (but slot 0 is special, as are several others >= 0x70).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
slot addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
Note
all addresses > 111 are considered special and not used for locos.
pylnlib.Message.
WriteSlotData
(
slot
)
Initialize a Loconet message from a byte array.
Represents a basic LocoNet message. Several subclasses are provided to implemented actual messages.
The 'opcode' (message type) is determined from byte 0, The length of the data (incl. the checksum) is determined by bits in the first byte and the second byte (if it is a variable byte message) The checksum is the last byte in the data. If the last byte in the data is 0, no check is done, so you can create a message from scratch and calculate the checksum later.
ValueError
— If the length of the byte array does not match the encoded length, a ValueError is raised.ValueError
— If the calculated checksum doesn match the last byte of the byte array, a ValueError is raised (unless the last data byte is 0)
checksum
(
msg
)
(byte) — Calculate the checksum over the message.</>from_data
(
data
)
(Message) — A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.</>hexdata
(
)
(list[str]) — Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.</>length
(
opcode
,nextbyte
)
(_type_) — Determine the length of a LocoNet message based on its opcode and next byte.</>sensoraddress
(
d0
,d1
)
— Return a 12-bit sensor address from the data.</>slotaddress
(
d0
,d1
)
— Return an 11-bit slot address from the data.</>switchaddress
(
d0
,d1
)
— Return an 11-bit switch address from the data.</>updateChecksum
(
)
— Calculate the checksum of the data and store it in the last byte.</>
hexdata
(
)
Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.
a list of lowercase hexadecimal number with leading zeros.
updateChecksum
(
)
Calculate the checksum of the data and store it in the last byte.
length
(
opcode
, nextbyte
)
Determine the length of a LocoNet message based on its opcode and next byte.
The length is inclusive the opcode and the final checksum.
opcode
(byte) — the opcodenextbyte
(byte) — the total number of bytes in the message if the opcode indicates this is a variable length message.
description
from_data
(
data
)
A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.
data
(bytearray) — the bytes of the message
a subclass of Message
Todo
not all possible opcodes/message types are implemented yet.
checksum
(
msg
)
Calculate the checksum over the message.
The checksum is calculated over all bytes.
This method does NOT overwrite the checksum byte, but simply returns it.
msg
(bytes) — the data
the checksum over all the bytes
sensoraddress
(
d0
, d1
)
Return a 12-bit sensor address from the data.
Sensors start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the sensor addressd1
(byte) — second byte of the sensor address
Note
sensor addresses are 12 bits running from 11 (most significant) to 0 (least significant) bits 11 - 8 and bit 0 are encoded in byte d1, bits 7 - 1 in byte d0.
switchaddress
(
d0
, d1
)
Return an 11-bit switch address from the data.
Switches start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
switch addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
slotaddress
(
d0
, d1
)
Return an 11-bit slot address from the data.
Slots start from zero (but slot 0 is special, as are several others >= 0x70).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
slot addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
Note
all addresses > 111 are considered special and not used for locos.
pylnlib.Message.
SlotSpeed
(
data=None
, slot=None
, speed=None
)
Initialize a Loconet message from a byte array.
Represents a basic LocoNet message. Several subclasses are provided to implemented actual messages.
The 'opcode' (message type) is determined from byte 0, The length of the data (incl. the checksum) is determined by bits in the first byte and the second byte (if it is a variable byte message) The checksum is the last byte in the data. If the last byte in the data is 0, no check is done, so you can create a message from scratch and calculate the checksum later.
data
(bytearray) — the bytes of the message
ValueError
— If the length of the byte array does not match the encoded length, a ValueError is raised.ValueError
— If the calculated checksum doesn match the last byte of the byte array, a ValueError is raised (unless the last data byte is 0)
checksum
(
msg
)
(byte) — Calculate the checksum over the message.</>from_data
(
data
)
(Message) — A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.</>hexdata
(
)
(list[str]) — Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.</>length
(
opcode
,nextbyte
)
(_type_) — Determine the length of a LocoNet message based on its opcode and next byte.</>sensoraddress
(
d0
,d1
)
— Return a 12-bit sensor address from the data.</>slotaddress
(
d0
,d1
)
— Return an 11-bit slot address from the data.</>switchaddress
(
d0
,d1
)
— Return an 11-bit switch address from the data.</>updateChecksum
(
)
— Calculate the checksum of the data and store it in the last byte.</>
hexdata
(
)
Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.
a list of lowercase hexadecimal number with leading zeros.
updateChecksum
(
)
Calculate the checksum of the data and store it in the last byte.
length
(
opcode
, nextbyte
)
Determine the length of a LocoNet message based on its opcode and next byte.
The length is inclusive the opcode and the final checksum.
opcode
(byte) — the opcodenextbyte
(byte) — the total number of bytes in the message if the opcode indicates this is a variable length message.
description
from_data
(
data
)
A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.
data
(bytearray) — the bytes of the message
a subclass of Message
Todo
not all possible opcodes/message types are implemented yet.
checksum
(
msg
)
Calculate the checksum over the message.
The checksum is calculated over all bytes.
This method does NOT overwrite the checksum byte, but simply returns it.
msg
(bytes) — the data
the checksum over all the bytes
sensoraddress
(
d0
, d1
)
Return a 12-bit sensor address from the data.
Sensors start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the sensor addressd1
(byte) — second byte of the sensor address
Note
sensor addresses are 12 bits running from 11 (most significant) to 0 (least significant) bits 11 - 8 and bit 0 are encoded in byte d1, bits 7 - 1 in byte d0.
switchaddress
(
d0
, d1
)
Return an 11-bit switch address from the data.
Switches start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
switch addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
slotaddress
(
d0
, d1
)
Return an 11-bit slot address from the data.
Slots start from zero (but slot 0 is special, as are several others >= 0x70).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
slot addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
Note
all addresses > 111 are considered special and not used for locos.
pylnlib.Message.
RequestLocAddress
(
address
)
Initialize a Loconet message from a byte array.
Represents a basic LocoNet message. Several subclasses are provided to implemented actual messages.
The 'opcode' (message type) is determined from byte 0, The length of the data (incl. the checksum) is determined by bits in the first byte and the second byte (if it is a variable byte message) The checksum is the last byte in the data. If the last byte in the data is 0, no check is done, so you can create a message from scratch and calculate the checksum later.
ValueError
— If the length of the byte array does not match the encoded length, a ValueError is raised.ValueError
— If the calculated checksum doesn match the last byte of the byte array, a ValueError is raised (unless the last data byte is 0)
checksum
(
msg
)
(byte) — Calculate the checksum over the message.</>from_data
(
data
)
(Message) — A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.</>hexdata
(
)
(list[str]) — Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.</>length
(
opcode
,nextbyte
)
(_type_) — Determine the length of a LocoNet message based on its opcode and next byte.</>sensoraddress
(
d0
,d1
)
— Return a 12-bit sensor address from the data.</>slotaddress
(
d0
,d1
)
— Return an 11-bit slot address from the data.</>switchaddress
(
d0
,d1
)
— Return an 11-bit switch address from the data.</>updateChecksum
(
)
— Calculate the checksum of the data and store it in the last byte.</>
hexdata
(
)
Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.
a list of lowercase hexadecimal number with leading zeros.
updateChecksum
(
)
Calculate the checksum of the data and store it in the last byte.
length
(
opcode
, nextbyte
)
Determine the length of a LocoNet message based on its opcode and next byte.
The length is inclusive the opcode and the final checksum.
opcode
(byte) — the opcodenextbyte
(byte) — the total number of bytes in the message if the opcode indicates this is a variable length message.
description
from_data
(
data
)
A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.
data
(bytearray) — the bytes of the message
a subclass of Message
Todo
not all possible opcodes/message types are implemented yet.
checksum
(
msg
)
Calculate the checksum over the message.
The checksum is calculated over all bytes.
This method does NOT overwrite the checksum byte, but simply returns it.
msg
(bytes) — the data
the checksum over all the bytes
sensoraddress
(
d0
, d1
)
Return a 12-bit sensor address from the data.
Sensors start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the sensor addressd1
(byte) — second byte of the sensor address
Note
sensor addresses are 12 bits running from 11 (most significant) to 0 (least significant) bits 11 - 8 and bit 0 are encoded in byte d1, bits 7 - 1 in byte d0.
switchaddress
(
d0
, d1
)
Return an 11-bit switch address from the data.
Switches start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
switch addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
slotaddress
(
d0
, d1
)
Return an 11-bit slot address from the data.
Slots start from zero (but slot 0 is special, as are several others >= 0x70).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
slot addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
Note
all addresses > 111 are considered special and not used for locos.
pylnlib.Message.
MoveSlots
(
data=None
, src=None
, dst=None
)
Initialize a Loconet message from a byte array.
Represents a basic LocoNet message. Several subclasses are provided to implemented actual messages.
The 'opcode' (message type) is determined from byte 0, The length of the data (incl. the checksum) is determined by bits in the first byte and the second byte (if it is a variable byte message) The checksum is the last byte in the data. If the last byte in the data is 0, no check is done, so you can create a message from scratch and calculate the checksum later.
data
(bytearray) — the bytes of the message
ValueError
— If the length of the byte array does not match the encoded length, a ValueError is raised.ValueError
— If the calculated checksum doesn match the last byte of the byte array, a ValueError is raised (unless the last data byte is 0)
checksum
(
msg
)
(byte) — Calculate the checksum over the message.</>from_data
(
data
)
(Message) — A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.</>hexdata
(
)
(list[str]) — Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.</>length
(
opcode
,nextbyte
)
(_type_) — Determine the length of a LocoNet message based on its opcode and next byte.</>sensoraddress
(
d0
,d1
)
— Return a 12-bit sensor address from the data.</>slotaddress
(
d0
,d1
)
— Return an 11-bit slot address from the data.</>switchaddress
(
d0
,d1
)
— Return an 11-bit switch address from the data.</>updateChecksum
(
)
— Calculate the checksum of the data and store it in the last byte.</>
hexdata
(
)
Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.
a list of lowercase hexadecimal number with leading zeros.
updateChecksum
(
)
Calculate the checksum of the data and store it in the last byte.
length
(
opcode
, nextbyte
)
Determine the length of a LocoNet message based on its opcode and next byte.
The length is inclusive the opcode and the final checksum.
opcode
(byte) — the opcodenextbyte
(byte) — the total number of bytes in the message if the opcode indicates this is a variable length message.
description
from_data
(
data
)
A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.
data
(bytearray) — the bytes of the message
a subclass of Message
Todo
not all possible opcodes/message types are implemented yet.
checksum
(
msg
)
Calculate the checksum over the message.
The checksum is calculated over all bytes.
This method does NOT overwrite the checksum byte, but simply returns it.
msg
(bytes) — the data
the checksum over all the bytes
sensoraddress
(
d0
, d1
)
Return a 12-bit sensor address from the data.
Sensors start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the sensor addressd1
(byte) — second byte of the sensor address
Note
sensor addresses are 12 bits running from 11 (most significant) to 0 (least significant) bits 11 - 8 and bit 0 are encoded in byte d1, bits 7 - 1 in byte d0.
switchaddress
(
d0
, d1
)
Return an 11-bit switch address from the data.
Switches start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
switch addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
slotaddress
(
d0
, d1
)
Return an 11-bit slot address from the data.
Slots start from zero (but slot 0 is special, as are several others >= 0x70).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
slot addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
Note
all addresses > 111 are considered special and not used for locos.
pylnlib.Message.
CaptureTimeStamp
(
t
)
Initialize a Loconet message from a byte array.
Represents a basic LocoNet message. Several subclasses are provided to implemented actual messages.
The 'opcode' (message type) is determined from byte 0, The length of the data (incl. the checksum) is determined by bits in the first byte and the second byte (if it is a variable byte message) The checksum is the last byte in the data. If the last byte in the data is 0, no check is done, so you can create a message from scratch and calculate the checksum later.
ValueError
— If the length of the byte array does not match the encoded length, a ValueError is raised.ValueError
— If the calculated checksum doesn match the last byte of the byte array, a ValueError is raised (unless the last data byte is 0)
checksum
(
msg
)
(byte) — Calculate the checksum over the message.</>from_data
(
data
)
(Message) — A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.</>hexdata
(
)
(list[str]) — Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.</>length
(
opcode
,nextbyte
)
(_type_) — Determine the length of a LocoNet message based on its opcode and next byte.</>sensoraddress
(
d0
,d1
)
— Return a 12-bit sensor address from the data.</>slotaddress
(
d0
,d1
)
— Return an 11-bit slot address from the data.</>switchaddress
(
d0
,d1
)
— Return an 11-bit switch address from the data.</>updateChecksum
(
)
— Calculate the checksum of the data and store it in the last byte.</>
hexdata
(
)
Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.
a list of lowercase hexadecimal number with leading zeros.
updateChecksum
(
)
Calculate the checksum of the data and store it in the last byte.
length
(
opcode
, nextbyte
)
Determine the length of a LocoNet message based on its opcode and next byte.
The length is inclusive the opcode and the final checksum.
opcode
(byte) — the opcodenextbyte
(byte) — the total number of bytes in the message if the opcode indicates this is a variable length message.
description
from_data
(
data
)
A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.
data
(bytearray) — the bytes of the message
a subclass of Message
Todo
not all possible opcodes/message types are implemented yet.
checksum
(
msg
)
Calculate the checksum over the message.
The checksum is calculated over all bytes.
This method does NOT overwrite the checksum byte, but simply returns it.
msg
(bytes) — the data
the checksum over all the bytes
sensoraddress
(
d0
, d1
)
Return a 12-bit sensor address from the data.
Sensors start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the sensor addressd1
(byte) — second byte of the sensor address
Note
sensor addresses are 12 bits running from 11 (most significant) to 0 (least significant) bits 11 - 8 and bit 0 are encoded in byte d1, bits 7 - 1 in byte d0.
switchaddress
(
d0
, d1
)
Return an 11-bit switch address from the data.
Switches start from zero (but may typically displayed with an added offset of 1).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
switch addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
slotaddress
(
d0
, d1
)
Return an 11-bit slot address from the data.
Slots start from zero (but slot 0 is special, as are several others >= 0x70).
d0
(byte) — first byte of the switch addressd1
(byte) — second byte of the switch address
Note
slot addresses are 11 bits running from 10 (most significant) to 0 (least significant) bits 10 - 7 are encoded in byte d1, bits 6 - 0 in byte d0.
Note
all addresses > 111 are considered special and not used for locos.