Reference
Handle VLCB formatting
It generates the appropriate strings which can be sent to CBUS / VLCB
Attributes:
| Name | Type | Description |
|---|---|---|
can_id |
The Can ID for your software (default = 60) |
Source code in src/pyvlcb/__init__.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 | |
__init__(can_id=60)
Inits VLCB with a can_id
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
can_id
|
Optional[int]
|
The can_id for the software (default = 60) |
60
|
Source code in src/pyvlcb/__init__.py
44 45 46 47 48 49 50 51 | |
accessory_command(node_id, ev_id, state)
Create an accessory command
Uses appropriate Accessory On / Off command Defaulting to short, but using long if > 0xffff
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id
|
int
|
Node ID to query |
required |
ev_id
|
int
|
Event ID |
required |
state
|
Union[str, bool]
|
State to change to can be "on" or "off" / True or False |
required |
Returns:
| Name | Type | Description |
|---|---|---|
String |
str
|
A string for the request |
Source code in src/pyvlcb/__init__.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | |
accessory_long_command(node_id, ev_id, state)
Create an accessory long command
Uses ACON (90) or ACOF (91)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id
|
int
|
Node ID to query |
required |
ev_id
|
int
|
Event ID |
required |
state
|
Union[str, bool]
|
State to change to can be "on" or "off" / True or False |
required |
Returns:
| Name | Type | Description |
|---|---|---|
String |
str
|
A string for the request |
Source code in src/pyvlcb/__init__.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
accessory_short_command(node_id, ev_id, state)
Create an accessory short command
Uses ASON (98) or ASOF (99)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id
|
int
|
Node ID to query |
required |
ev_id
|
int
|
Event ID |
required |
state
|
Union[str, bool]
|
State to change to can be "on" or "off" / True or False |
required |
Returns:
| Name | Type | Description |
|---|---|---|
String |
str
|
A string for the request |
Source code in src/pyvlcb/__init__.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
allocate_loco(loco_id, long=True)
Create an allocate loco request
Uses RLOC (40)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
loco_id
|
int
|
Loco ID (long or short number) |
required |
long
|
Optional[bool]
|
Long loco ID (True) or short loco ID (False) |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
String |
str
|
A string for the request |
Source code in src/pyvlcb/__init__.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | |
discover()
Create a discovery string
Uses op-code QNN (0D)
Returns:
| Name | Type | Description |
|---|---|---|
String |
str
|
A string for the request |
Source code in src/pyvlcb/__init__.py
173 174 175 176 177 178 179 180 181 182 | |
discover_evn(node_id)
Create a discover number of events for a node
Uses op-code RQEVN (58)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id
|
int
|
Node ID to query |
required |
Returns:
| Name | Type | Description |
|---|---|---|
String |
str
|
A string for the request |
Source code in src/pyvlcb/__init__.py
185 186 187 188 189 190 191 192 193 194 195 196 | |
discover_nerd(node_id)
Create a discover stored events for a node
Uses op-code NERD (57)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id
|
int
|
Node ID to query |
required |
Returns:
| Name | Type | Description |
|---|---|---|
String |
str
|
A string for the request |
Source code in src/pyvlcb/__init__.py
213 214 215 216 217 218 219 220 221 222 223 224 | |
discover_nevn(node_id)
Create a discover number of events available for a node
Uses op-code NNEVN (56)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id
|
int
|
Node ID to query |
required |
Returns:
| Name | Type | Description |
|---|---|---|
String |
str
|
A string for the request |
Source code in src/pyvlcb/__init__.py
199 200 201 202 203 204 205 206 207 208 209 210 | |
keep_alive(session_id)
Create an keep alive request
For any loco allocated send a keep alive at least every 4 seconds Uses DKEEP (23)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
int
|
Session ID |
required |
Returns:
| Name | Type | Description |
|---|---|---|
String |
str
|
A string for the request |
Source code in src/pyvlcb/__init__.py
389 390 391 392 393 394 395 396 397 398 399 400 401 | |
loco_set_dfun(session_id, byte1, byte2)
Create a set function request
Uses DFUN (60)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
int
|
Session ID |
required |
byte1
|
bytes
|
Function group. 1 = F1 to F4, 2 = F5 to F8, 3 = F9 to F12, 4 = F13 to 19, 5 = F20 to F28 |
required |
byte2
|
bytes
|
1 bit per function 1=on, 0=off. LSB to right eg 1 = 0001, 2 = 0010 |
required |
Returns:
| Name | Type | Description |
|---|---|---|
String |
str
|
A string for the request |
Source code in src/pyvlcb/__init__.py
456 457 458 459 460 461 462 463 464 465 466 467 468 469 | |
loco_set_function(session_id, function_num, function_list)
Create a set function request using the function list Sends the entire group of functions where the function_num resides This is an alternative to loco_set_dfun as this calculates the bytes this method can only be used for functions 0 to 27
Uses DFUN (60)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
int
|
Session ID |
required |
byte1
|
Function number |
required | |
byte2
|
List of current function statuses |
required |
Returns:
| Name | Type | Description |
|---|---|---|
String |
str
|
A string for the request |
Raises:
| Type | Description |
|---|---|
ValueError
|
Typically raised from f_to_bytes |
Source code in src/pyvlcb/__init__.py
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 | |
loco_speed_dir(session_id, speed, direction)
Set loco speed and direction based on separate arguments
Same as loco_speeddir but this takes 2 arguments, whereas loco_speeddir needs a combined value Maximum call this once every 32 milliseconds
Uses DSPD (47)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
int
|
Session ID |
required |
speed
|
int
|
0 to 127 (1 is increased to 2 to avoid emergency stop) |
required |
direction
|
int
|
1 = forward, 0 = reverse |
required |
Returns:
| Name | Type | Description |
|---|---|---|
String |
str
|
A string for the request |
Source code in src/pyvlcb/__init__.py
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | |
loco_speeddir(session_id, speeddir)
Set loco speed and direction
Maximum call this once every 32 milliseconds Needs combined speed and direction value. If speed is set to 1 then that is considered an emergency stop
Uses DSPD (47)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
int
|
Session ID |
required |
speeddir
|
int
|
Unsigned 8 bit number. MSB is direction, 7 bits for speed |
required |
Returns:
| Name | Type | Description |
|---|---|---|
String |
str
|
A string for the request |
Source code in src/pyvlcb/__init__.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 | |
loco_stop_all()
Create an emergency stop all locos
Uses op-code RESTP (0A)
Returns:
| Name | Type | Description |
|---|---|---|
String |
str
|
A string for the request |
Source code in src/pyvlcb/__init__.py
228 229 230 231 232 233 234 235 236 | |
log_entry(input_string)
Parse a log entry and return as a list of string values
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_string
|
string
|
String consisting of of num, date, direction, message as a single string |
required |
Returns (list[str]): List of strings
Source code in src/pyvlcb/__init__.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
make_header(majpri=2, minpri=None, can_id=None, opcode=None)
Create a CBUS/VLCB header
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
byte1
|
byte
|
Most significant byte |
required |
byte2
|
byte
|
Least significant byte |
required |
Returns:
| Name | Type | Description |
|---|---|---|
String |
str
|
A hex representation of the number |
Source code in src/pyvlcb/__init__.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
parse_input(input_bytes)
Parse a raw CBUS packet as an input bytestring
Take a bytestring (or string) from the CBUS and extract the details
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_types
|
bytestring
|
Input raw bytestring (or string) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
VLCBFormat |
VLCBFormat
|
parsed data in VLCBFormat |
Raises:
| Type | Description |
|---|---|
ValueError
|
If invalid data string |
Source code in src/pyvlcb/__init__.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
release_loco(session_id)
Create a release loco request
Uses KLOC (21)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
int
|
Session number |
required |
Returns:
| Name | Type | Description |
|---|---|---|
String |
str
|
A string for the request |
Source code in src/pyvlcb/__init__.py
330 331 332 333 334 335 336 337 338 339 340 341 | |
share_loco(loco_id, long=True)
Create an share loco request
Takes the loco and other connectons to the loco can remain. Uses GLOC (61)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
loco_id
|
int
|
Loco ID (long or short number) |
required |
long
|
Optional[bool]
|
Long loco ID (True) or short loco ID (False) |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
String |
str
|
A string for the request |
Source code in src/pyvlcb/__init__.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 | |
steal_loco(loco_id, long=True)
Create an steal loco request
Takes the loco and other connectons to the loco should be terminated.
Uses GLOC (60)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
loco_id
|
int
|
Loco ID (long or short number) |
required |
long
|
Optional[bool]
|
Long loco ID (True) or short loco ID (False) |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
String |
str
|
A string for the request |
Source code in src/pyvlcb/__init__.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 | |
Handle USB serial communication to CANUSB4
Uses pyserial to communicate over USB.
Attributes:
| Name | Type | Description |
|---|---|---|
port |
The usb port eg. /dev/ttyACM0 (RPi) |
Source code in src/pyvlcb/canusb.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
__init__(port, baud=115200, timeout=0.01, exclusive=True)
Inits CanUSB4 with a USB port
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
port
|
str
|
USB port eg. /dev/ttyACM0 (RPi) |
required |
baud
|
Optional[int]
|
Baud rate in bytes |
115200
|
timeout
|
Optional[float]
|
How long to wait for a serial timeout (seconds) |
0.01
|
Raises:
| Type | Description |
|---|---|
DeviceConnectionError
|
If the port cannot be opened or is already in use. |
InvalidConfigurationError
|
If the port name is empty or invalid. |
Source code in src/pyvlcb/canusb.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
connect(port=None, baud=None, timeout=None, exclusive=None)
Inits CanUSB4 with a USB port
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
port
|
Optional[str]
|
USB port eg. /dev/ttyACM0 (RPi) |
None
|
baud
|
Optional[int]
|
Baud rate in bytes |
None
|
timeout
|
Optional[float]
|
How long to wait for a serial timeout (seconds) |
None
|
Raises:
| Type | Description |
|---|---|
DeviceConnectionError
|
If the port cannot be opened or is already in use. |
InvalidConfigurationError
|
If the port name is empty or invalid. |
Source code in src/pyvlcb/canusb.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
read_data()
Read data from CanUSB4
Returns:
| Name | Type | Description |
|---|---|---|
List |
List[str]
|
List of strings for all data read |
Raises:
| Type | Description |
|---|---|
DeviceConnectionError
|
Error receiving data - possible connection list |
Source code in src/pyvlcb/canusb.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
send_data(data)
Send data to serial
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Union[str, bytes]
|
Data to send, normally from a VLCB method |
required |
Raises:
| Type | Description |
|---|---|
InvalidConfigurationError
|
If string contains invalid characters |
TypeError
|
If data passed is not a string or a bytestring |
DeviceConnectionError
|
Error sending data - possible connection lost |
Source code in src/pyvlcb/canusb.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
Handles a single VLCB packet
Attributes:
| Name | Type | Description |
|---|---|---|
priority |
CAN priority |
|
can_id |
CAN ID |
|
data |
Remaining data as a hex str |
Source code in src/pyvlcb/vlcbformat.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
__init__(priority, can_id, data)
Inits VLCBformat
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
priority
|
int
|
CAN priority |
required |
can_id
|
int
|
CAN ID |
required |
data
|
str
|
Remaining data as a hex string |
required |
Source code in src/pyvlcb/vlcbformat.py
25 26 27 28 29 30 31 32 33 34 35 36 | |
format_data()
Returns the opcode associated with the data string
Returns:
| Name | Type | Description |
|---|---|---|
OpcodeData |
OpcodeData
|
Dict from the VLCBOpcode |
Raises:
| Type | Description |
|---|---|
ValueError
|
If opcode not found |
Source code in src/pyvlcb/vlcbformat.py
65 66 67 68 69 70 71 72 73 74 | |
get_data()
Returns the opcode associated with the data string as a dict
Returns:
| Name | Type | Description |
|---|---|---|
OpcodeData |
OpcodeData
|
Dict from the VLCBOpcode |
Raises:
| Type | Description |
|---|---|
ValueError
|
If opcode not found |
Source code in src/pyvlcb/vlcbformat.py
54 55 56 57 58 59 60 61 62 63 | |
get_function_list()
Where packet contains Fn1, Fn2, Fn3 (eg. PLOC) returns
Only valid with certain VLCBFormat packets associated with Locos. If packet is does not contain the 3 byte values (which may be formatted differently) then raises a InvalidFunctionError
Returns:
| Type | Description |
|---|---|
List[int]
|
List of function values as 0 or 1 for each function as off and on |
Raises:
| Type | Description |
|---|---|
InvalidFunctionError
|
If Function Bytes are not in the packet |
Source code in src/pyvlcb/vlcbformat.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
get_loco_id()
Converts AddrHigh and AddrLow into a loco_id
Only valid with certain VLCBFormat packets associated with Locos. If packet is does not contain the AddrHigh & AddrLow values (which may be formatted differently) then raises a InvalidLocoError
Returns:
| Name | Type | Description |
|---|---|---|
loco_id |
int
|
Loco number |
Raises:
| Type | Description |
|---|---|
InvalidLocoError
|
If AddrHigh / AddrLow are not in the packet |
Source code in src/pyvlcb/vlcbformat.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
opcode()
Returns the opcode associated with the data string
Returns:
| Type | Description |
|---|---|
|
Dictionary of the opcode data |
Raises:
| Type | Description |
|---|---|
ValueError
|
If opcode not found |
Source code in src/pyvlcb/vlcbformat.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
List of opcodes and other related data
Includes format information and user friendly strings
Attributes:
| Name | Type | Description |
|---|---|---|
opcodes |
Dict of opcodes indexed by opcode number as a hex string |
|
field_formats |
Dict of data type and number of characters for each field |
|
accessory_codes |
Dict of accessory on and off codes |
Source code in src/pyvlcb/vlcbformat.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 | |
opcode_extract(opcode_string)
staticmethod
Shortens op code by removing extra characters
Returns:
| Name | Type | Description |
|---|---|---|
String |
str
|
shortened opcode string |
Raises:
| Type | Description |
|---|---|
ValueError
|
If string does not contain at least 2 characters |
Source code in src/pyvlcb/vlcbformat.py
459 460 461 462 463 464 465 466 467 468 469 470 471 472 | |
opcode_mnemonic(opcode)
staticmethod
Get mnemonic from opcode
Returns:
| Name | Type | Description |
|---|---|---|
String |
Opcode mnemonic |
Raises:
| Type | Description |
|---|---|
ValueError
|
If opcode not found |
Source code in src/pyvlcb/vlcbformat.py
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 | |
opcode_priority(opcode)
staticmethod
Get priority from opcode
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
priority value |
Raises:
| Type | Description |
|---|---|
ValueError
|
If opcode not found |
Source code in src/pyvlcb/vlcbformat.py
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 | |
opcode_title(opcode)
staticmethod
Get title from opcode
Returns:
| Name | Type | Description |
|---|---|---|
String |
str
|
Opcode Title |
Raises:
| Type | Description |
|---|---|
ValueError
|
If opcode not found |
Source code in src/pyvlcb/vlcbformat.py
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | |
parse_data(data)
staticmethod
Returns the data associated with the data string as a dict
Returns:
| Name | Type | Description |
|---|---|---|
OpcodeData |
OpcodeData
|
Dict in OpcodeData format |
Raises:
| Type | Description |
|---|---|
ValueError
|
If opcode not found |
Source code in src/pyvlcb/vlcbformat.py
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 | |
Utils for use by other parts of the library
bytes_to_addr(byte1, byte2)
Convert 2 byte values into an address id sring
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
byte1
|
bytes
|
Most significant byte |
required |
byte2
|
bytes
|
Least significant byte |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Int |
int
|
The address id value |
Source code in src/pyvlcb/utils.py
128 129 130 131 132 133 134 135 136 137 138 139 140 | |
bytes_to_functions(fn1, fn2, fn3)
Sets the value of the functions from a PLOC message Only returns values for F0 to F12 (others not included in PLOC) Provides as a list for inclusion in menus etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn1
|
bytes
|
Function byte F0 to F4 - bit 5 = dir lighting (F0), bit 6 = direction, bit 7 = res, bit 8 = 0 |
required |
fn2
|
bytes
|
Function byte F5 to F8 - bit 5 upwards reserved |
required |
fn3
|
bytes
|
Function byte F9 to F12 |
required |
Returns:
| Type | Description |
|---|---|
List[int]
|
List of function values as 0 or 1 for each function as off and on |
Source code in src/pyvlcb/utils.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
bytes_to_hexstr(byte1, byte2)
Convert 2 bytes to a hex string
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
byte1
|
bytes
|
Most significant byte |
required |
byte2
|
bytes
|
Least significant byte |
required |
Returns:
| Name | Type | Description |
|---|---|---|
String |
str
|
A hex representation of the number |
Source code in src/pyvlcb/utils.py
143 144 145 146 147 148 149 150 151 152 153 | |
dict_to_string(dictionary)
Convert a dict to a string without {} or quotes
Source code in src/pyvlcb/utils.py
43 44 45 46 47 48 49 50 | |
f_to_bytes(f_num, function_status)
Convert a Fnumber (Loco function ID) to bytes as string representation
Can be used to create correct format for loco_set_dfun Limited to range 0 to 28 - which is max for DFUN Higher would need to use DFNON/DFOFF
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f_num
|
int
|
Function number |
required |
function_status
|
List[int]
|
List with value of all functions (must be updated before calling) |
required |
Returns:
| Type | Description |
|---|---|
Tuple[str, str]
|
Tuple of two x 2-characer strings representing the bytes |
Raises: ValueError
Source code in src/pyvlcb/utils.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
num_to_1hexstr(num)
Convert number to a byte
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num
|
int
|
Number to convert |
required |
Returns:
| Name | Type | Description |
|---|---|---|
String |
str
|
A hex representation of the number (2 chars) |
Source code in src/pyvlcb/utils.py
6 7 8 9 10 11 12 13 14 15 | |
num_to_2hexstr(num)
Convert number to 2 bytes
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num
|
int
|
Number to convert |
required |
Returns:
| Name | Type | Description |
|---|---|---|
String |
str
|
A hex representation of the number (4 chars) |
Source code in src/pyvlcb/utils.py
18 19 20 21 22 23 24 25 26 27 | |
num_to_4hexstr(num)
Convert number to 4 bytes
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num
|
int
|
Number to convert |
required |
Returns:
| Name | Type | Description |
|---|---|---|
String |
str
|
A hex representation of the number (8 chars) |
Source code in src/pyvlcb/utils.py
30 31 32 33 34 35 36 37 38 39 | |