Skip to content
module

pylnlib.Message

Classes
class

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.

Parameters
  • data (bytearray) the bytes of the message
Raises
  • 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)
Methods
  • 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.</>
method

hexdata()

Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.

Returns (list[str])

a list of lowercase hexadecimal number with leading zeros.

method

updateChecksum()

Calculate the checksum of the data and store it in the last byte.

staticmethod

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.

Parameters
  • opcode (byte) the opcode
  • nextbyte (byte) the total number of bytes in the message if the opcode indicates this is a variable length message.
Returns (_type_)

description

staticmethod

from_data(data)

A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.

Parameters
  • data (bytearray) the bytes of the message
Returns (Message)

a subclass of Message

Todo

not all possible opcodes/message types are implemented yet.

staticmethod

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.

Parameters
  • msg (bytes) the data
Returns (byte)

the checksum over all the bytes

staticmethod

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).

Parameters
  • d0 (byte) first byte of the sensor address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

class

pylnlib.Message.Unknown(data)

An Unknown message simply holds the data bytes.

Parameters
  • data (bytearray) the bytes of the message
Methods
  • 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.</>
method

hexdata()

Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.

Returns (list[str])

a list of lowercase hexadecimal number with leading zeros.

method

updateChecksum()

Calculate the checksum of the data and store it in the last byte.

staticmethod

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.

Parameters
  • opcode (byte) the opcode
  • nextbyte (byte) the total number of bytes in the message if the opcode indicates this is a variable length message.
Returns (_type_)

description

staticmethod

from_data(data)

A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.

Parameters
  • data (bytearray) the bytes of the message
Returns (Message)

a subclass of Message

Todo

not all possible opcodes/message types are implemented yet.

staticmethod

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.

Parameters
  • msg (bytes) the data
Returns (byte)

the checksum over all the bytes

staticmethod

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).

Parameters
  • d0 (byte) first byte of the sensor address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

class

pylnlib.Message.PowerOn(data=None)

A PowerOn message represents a global track power on message.

Parameters
  • data (bytes, optional) raw message data. Defaults to None.
Methods
  • 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.</>
method

hexdata()

Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.

Returns (list[str])

a list of lowercase hexadecimal number with leading zeros.

method

updateChecksum()

Calculate the checksum of the data and store it in the last byte.

staticmethod

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.

Parameters
  • opcode (byte) the opcode
  • nextbyte (byte) the total number of bytes in the message if the opcode indicates this is a variable length message.
Returns (_type_)

description

staticmethod

from_data(data)

A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.

Parameters
  • data (bytearray) the bytes of the message
Returns (Message)

a subclass of Message

Todo

not all possible opcodes/message types are implemented yet.

staticmethod

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.

Parameters
  • msg (bytes) the data
Returns (byte)

the checksum over all the bytes

staticmethod

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).

Parameters
  • d0 (byte) first byte of the sensor address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

class

pylnlib.Message.PowerOff(data=None)

A PowerOff message represents a global track power off message.

Parameters
  • data (bytes, optional) raw message data. Defaults to None.
Methods
  • 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.</>
method

hexdata()

Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.

Returns (list[str])

a list of lowercase hexadecimal number with leading zeros.

method

updateChecksum()

Calculate the checksum of the data and store it in the last byte.

staticmethod

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.

Parameters
  • opcode (byte) the opcode
  • nextbyte (byte) the total number of bytes in the message if the opcode indicates this is a variable length message.
Returns (_type_)

description

staticmethod

from_data(data)

A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.

Parameters
  • data (bytearray) the bytes of the message
Returns (Message)

a subclass of Message

Todo

not all possible opcodes/message types are implemented yet.

staticmethod

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.

Parameters
  • msg (bytes) the data
Returns (byte)

the checksum over all the bytes

staticmethod

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).

Parameters
  • d0 (byte) first byte of the sensor address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

class

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.

Parameters
  • 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.
Raises
  • ValueError if data is specified at the same time as one of the other arguments.
Methods
  • 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.</>
method

hexdata()

Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.

Returns (list[str])

a list of lowercase hexadecimal number with leading zeros.

method

updateChecksum()

Calculate the checksum of the data and store it in the last byte.

staticmethod

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.

Parameters
  • opcode (byte) the opcode
  • nextbyte (byte) the total number of bytes in the message if the opcode indicates this is a variable length message.
Returns (_type_)

description

staticmethod

from_data(data)

A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.

Parameters
  • data (bytearray) the bytes of the message
Returns (Message)

a subclass of Message

Todo

not all possible opcodes/message types are implemented yet.

staticmethod

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.

Parameters
  • msg (bytes) the data
Returns (byte)

the checksum over all the bytes

staticmethod

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).

Parameters
  • d0 (byte) first byte of the sensor address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

class

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.

Parameters
  • 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.
Raises
  • ValueError if data is specified at the same time as one of the other arguments.
Methods
  • 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.</>
method

hexdata()

Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.

Returns (list[str])

a list of lowercase hexadecimal number with leading zeros.

method

updateChecksum()

Calculate the checksum of the data and store it in the last byte.

staticmethod

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.

Parameters
  • opcode (byte) the opcode
  • nextbyte (byte) the total number of bytes in the message if the opcode indicates this is a variable length message.
Returns (_type_)

description

staticmethod

from_data(data)

A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.

Parameters
  • data (bytearray) the bytes of the message
Returns (Message)

a subclass of Message

Todo

not all possible opcodes/message types are implemented yet.

staticmethod

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.

Parameters
  • msg (bytes) the data
Returns (byte)

the checksum over all the bytes

staticmethod

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).

Parameters
  • d0 (byte) first byte of the sensor address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

class

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.

Parameters
  • 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.
Raises
  • ValueError if data is specified at the same time as one of the other arguments.
Methods
  • 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.</>
method

hexdata()

Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.

Returns (list[str])

a list of lowercase hexadecimal number with leading zeros.

method

updateChecksum()

Calculate the checksum of the data and store it in the last byte.

staticmethod

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.

Parameters
  • opcode (byte) the opcode
  • nextbyte (byte) the total number of bytes in the message if the opcode indicates this is a variable length message.
Returns (_type_)

description

staticmethod

from_data(data)

A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.

Parameters
  • data (bytearray) the bytes of the message
Returns (Message)

a subclass of Message

Todo

not all possible opcodes/message types are implemented yet.

staticmethod

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.

Parameters
  • msg (bytes) the data
Returns (byte)

the checksum over all the bytes

staticmethod

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).

Parameters
  • d0 (byte) first byte of the sensor address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

class

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.

Parameters
  • data (optional) the bytes of the message
Raises
  • 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.
Methods
  • 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.</>
method

hexdata()

Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.

Returns (list[str])

a list of lowercase hexadecimal number with leading zeros.

method

updateChecksum()

Calculate the checksum of the data and store it in the last byte.

staticmethod

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.

Parameters
  • opcode (byte) the opcode
  • nextbyte (byte) the total number of bytes in the message if the opcode indicates this is a variable length message.
Returns (_type_)

description

staticmethod

from_data(data)

A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.

Parameters
  • data (bytearray) the bytes of the message
Returns (Message)

a subclass of Message

Todo

not all possible opcodes/message types are implemented yet.

staticmethod

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.

Parameters
  • msg (bytes) the data
Returns (byte)

the checksum over all the bytes

staticmethod

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).

Parameters
  • d0 (byte) first byte of the sensor address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

class

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.

Parameters
  • data (bytearray(4) either 4 bytes of raw data or the switch address
  • 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.
Methods
  • 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.</>
method

hexdata()

Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.

Returns (list[str])

a list of lowercase hexadecimal number with leading zeros.

method

updateChecksum()

Calculate the checksum of the data and store it in the last byte.

staticmethod

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.

Parameters
  • opcode (byte) the opcode
  • nextbyte (byte) the total number of bytes in the message if the opcode indicates this is a variable length message.
Returns (_type_)

description

staticmethod

from_data(data)

A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.

Parameters
  • data (bytearray) the bytes of the message
Returns (Message)

a subclass of Message

Todo

not all possible opcodes/message types are implemented yet.

staticmethod

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.

Parameters
  • msg (bytes) the data
Returns (byte)

the checksum over all the bytes

staticmethod

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).

Parameters
  • d0 (byte) first byte of the sensor address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

class

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.

Parameters
  • 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.
Methods
  • 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.</>
method

hexdata()

Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.

Returns (list[str])

a list of lowercase hexadecimal number with leading zeros.

method

updateChecksum()

Calculate the checksum of the data and store it in the last byte.

staticmethod

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.

Parameters
  • opcode (byte) the opcode
  • nextbyte (byte) the total number of bytes in the message if the opcode indicates this is a variable length message.
Returns (_type_)

description

staticmethod

from_data(data)

A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.

Parameters
  • data (bytearray) the bytes of the message
Returns (Message)

a subclass of Message

Todo

not all possible opcodes/message types are implemented yet.

staticmethod

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.

Parameters
  • msg (bytes) the data
Returns (byte)

the checksum over all the bytes

staticmethod

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).

Parameters
  • d0 (byte) first byte of the sensor address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

class

pylnlib.Message.RequestSwitchState(id)

A RequestSwitchState message represents a request for a switch status update.

Methods
  • 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.</>
method

hexdata()

Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.

Returns (list[str])

a list of lowercase hexadecimal number with leading zeros.

method

updateChecksum()

Calculate the checksum of the data and store it in the last byte.

staticmethod

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.

Parameters
  • opcode (byte) the opcode
  • nextbyte (byte) the total number of bytes in the message if the opcode indicates this is a variable length message.
Returns (_type_)

description

staticmethod

from_data(data)

A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.

Parameters
  • data (bytearray) the bytes of the message
Returns (Message)

a subclass of Message

Todo

not all possible opcodes/message types are implemented yet.

staticmethod

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.

Parameters
  • msg (bytes) the data
Returns (byte)

the checksum over all the bytes

staticmethod

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).

Parameters
  • d0 (byte) first byte of the sensor address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

class

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.

Parameters
  • id (bytearray(4) either 4 bytes of raw data or the switch address
  • level (bool, optional) if a sensor address is given, this should hold True or False. Defaults to None.
Methods
  • 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.</>
method

hexdata()

Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.

Returns (list[str])

a list of lowercase hexadecimal number with leading zeros.

method

updateChecksum()

Calculate the checksum of the data and store it in the last byte.

staticmethod

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.

Parameters
  • opcode (byte) the opcode
  • nextbyte (byte) the total number of bytes in the message if the opcode indicates this is a variable length message.
Returns (_type_)

description

staticmethod

from_data(data)

A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.

Parameters
  • data (bytearray) the bytes of the message
Returns (Message)

a subclass of Message

Todo

not all possible opcodes/message types are implemented yet.

staticmethod

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.

Parameters
  • msg (bytes) the data
Returns (byte)

the checksum over all the bytes

staticmethod

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).

Parameters
  • d0 (byte) first byte of the sensor address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

class

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.

Parameters
  • data (bytearray) the bytes of the message
Raises
  • 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)
Methods
  • 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.</>
method

hexdata()

Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.

Returns (list[str])

a list of lowercase hexadecimal number with leading zeros.

method

updateChecksum()

Calculate the checksum of the data and store it in the last byte.

staticmethod

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.

Parameters
  • opcode (byte) the opcode
  • nextbyte (byte) the total number of bytes in the message if the opcode indicates this is a variable length message.
Returns (_type_)

description

staticmethod

from_data(data)

A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.

Parameters
  • data (bytearray) the bytes of the message
Returns (Message)

a subclass of Message

Todo

not all possible opcodes/message types are implemented yet.

staticmethod

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.

Parameters
  • msg (bytes) the data
Returns (byte)

the checksum over all the bytes

staticmethod

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).

Parameters
  • d0 (byte) first byte of the sensor address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

class

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.

Raises
  • 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)
Methods
  • 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.</>
method

hexdata()

Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.

Returns (list[str])

a list of lowercase hexadecimal number with leading zeros.

method

updateChecksum()

Calculate the checksum of the data and store it in the last byte.

staticmethod

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.

Parameters
  • opcode (byte) the opcode
  • nextbyte (byte) the total number of bytes in the message if the opcode indicates this is a variable length message.
Returns (_type_)

description

staticmethod

from_data(data)

A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.

Parameters
  • data (bytearray) the bytes of the message
Returns (Message)

a subclass of Message

Todo

not all possible opcodes/message types are implemented yet.

staticmethod

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.

Parameters
  • msg (bytes) the data
Returns (byte)

the checksum over all the bytes

staticmethod

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).

Parameters
  • d0 (byte) first byte of the sensor address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

class

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.

Parameters
  • data (bytearray) the bytes of the message
Raises
  • 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)
Methods
  • 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.</>
method

hexdata()

Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.

Returns (list[str])

a list of lowercase hexadecimal number with leading zeros.

method

updateChecksum()

Calculate the checksum of the data and store it in the last byte.

staticmethod

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.

Parameters
  • opcode (byte) the opcode
  • nextbyte (byte) the total number of bytes in the message if the opcode indicates this is a variable length message.
Returns (_type_)

description

staticmethod

from_data(data)

A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.

Parameters
  • data (bytearray) the bytes of the message
Returns (Message)

a subclass of Message

Todo

not all possible opcodes/message types are implemented yet.

staticmethod

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.

Parameters
  • msg (bytes) the data
Returns (byte)

the checksum over all the bytes

staticmethod

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).

Parameters
  • d0 (byte) first byte of the sensor address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

class

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.

Raises
  • 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)
Methods
  • 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.</>
method

hexdata()

Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.

Returns (list[str])

a list of lowercase hexadecimal number with leading zeros.

method

updateChecksum()

Calculate the checksum of the data and store it in the last byte.

staticmethod

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.

Parameters
  • opcode (byte) the opcode
  • nextbyte (byte) the total number of bytes in the message if the opcode indicates this is a variable length message.
Returns (_type_)

description

staticmethod

from_data(data)

A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.

Parameters
  • data (bytearray) the bytes of the message
Returns (Message)

a subclass of Message

Todo

not all possible opcodes/message types are implemented yet.

staticmethod

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.

Parameters
  • msg (bytes) the data
Returns (byte)

the checksum over all the bytes

staticmethod

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).

Parameters
  • d0 (byte) first byte of the sensor address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

class

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.

Parameters
  • data (bytearray) the bytes of the message
Raises
  • 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)
Methods
  • 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.</>
method

hexdata()

Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.

Returns (list[str])

a list of lowercase hexadecimal number with leading zeros.

method

updateChecksum()

Calculate the checksum of the data and store it in the last byte.

staticmethod

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.

Parameters
  • opcode (byte) the opcode
  • nextbyte (byte) the total number of bytes in the message if the opcode indicates this is a variable length message.
Returns (_type_)

description

staticmethod

from_data(data)

A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.

Parameters
  • data (bytearray) the bytes of the message
Returns (Message)

a subclass of Message

Todo

not all possible opcodes/message types are implemented yet.

staticmethod

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.

Parameters
  • msg (bytes) the data
Returns (byte)

the checksum over all the bytes

staticmethod

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).

Parameters
  • d0 (byte) first byte of the sensor address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

class

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.

Raises
  • 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)
Methods
  • 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.</>
method

hexdata()

Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.

Returns (list[str])

a list of lowercase hexadecimal number with leading zeros.

method

updateChecksum()

Calculate the checksum of the data and store it in the last byte.

staticmethod

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.

Parameters
  • opcode (byte) the opcode
  • nextbyte (byte) the total number of bytes in the message if the opcode indicates this is a variable length message.
Returns (_type_)

description

staticmethod

from_data(data)

A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.

Parameters
  • data (bytearray) the bytes of the message
Returns (Message)

a subclass of Message

Todo

not all possible opcodes/message types are implemented yet.

staticmethod

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.

Parameters
  • msg (bytes) the data
Returns (byte)

the checksum over all the bytes

staticmethod

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).

Parameters
  • d0 (byte) first byte of the sensor address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

class

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.

Parameters
  • data (bytearray) the bytes of the message
Raises
  • 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)
Methods
  • 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.</>
method

hexdata()

Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.

Returns (list[str])

a list of lowercase hexadecimal number with leading zeros.

method

updateChecksum()

Calculate the checksum of the data and store it in the last byte.

staticmethod

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.

Parameters
  • opcode (byte) the opcode
  • nextbyte (byte) the total number of bytes in the message if the opcode indicates this is a variable length message.
Returns (_type_)

description

staticmethod

from_data(data)

A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.

Parameters
  • data (bytearray) the bytes of the message
Returns (Message)

a subclass of Message

Todo

not all possible opcodes/message types are implemented yet.

staticmethod

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.

Parameters
  • msg (bytes) the data
Returns (byte)

the checksum over all the bytes

staticmethod

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).

Parameters
  • d0 (byte) first byte of the sensor address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

class

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.

Raises
  • 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)
Methods
  • 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.</>
method

hexdata()

Return the message data as a list of numbers formatted as hexadecimals with 2 digits and without 0x prefix.

Returns (list[str])

a list of lowercase hexadecimal number with leading zeros.

method

updateChecksum()

Calculate the checksum of the data and store it in the last byte.

staticmethod

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.

Parameters
  • opcode (byte) the opcode
  • nextbyte (byte) the total number of bytes in the message if the opcode indicates this is a variable length message.
Returns (_type_)

description

staticmethod

from_data(data)

A factory method that returns a specific subclass of a Message based on the opcode, or an instance of Unknown.

Parameters
  • data (bytearray) the bytes of the message
Returns (Message)

a subclass of Message

Todo

not all possible opcodes/message types are implemented yet.

staticmethod

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.

Parameters
  • msg (bytes) the data
Returns (byte)

the checksum over all the bytes

staticmethod

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).

Parameters
  • d0 (byte) first byte of the sensor address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.

staticmethod

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).

Parameters
  • d0 (byte) first byte of the switch address
  • d1 (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.