Skip to content

Commit

Permalink
Handle SerialException for Daktronic Consoles (#3)
Browse files Browse the repository at this point in the history
* Handle SerialException for Daktronic Consoles

* Documentation Update

* v1.1.1 Bump

* Markdown Table formattinf
  • Loading branch information
FlantasticDan authored Sep 14, 2021
1 parent 613c233 commit 9e77f7f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if __name__ == '__main__':
basketball = Basketball('COM1')
game_state = basketball.export()
```
*Call to sport class must be protected by an `if __name__ == '__main__'` because the serial connection is read in a seperate process*
*Calls to sport class must be protected by an `if __name__ == '__main__'` because the serial connection is read in a seperate process*

### Connecting a Console
Consoles are connected with via a Serial to USB cable.
Expand All @@ -33,7 +33,26 @@ Consoles are connected with via a Serial to USB cable.
**Colorado Time Systems System 6** - Tap into the 1/4" Scoreboard Out plug and connect the tip to pin 2 of a Serial DB9 connector and the shoe to pin 5.

### API
Sport classes take a serial port string as an argument and expose an `export` method that returns the current game state.
Sport classes take a serial port string as an argument and expose an `export` method that returns the current game state. All sport classes also feature an `on_update` method that is designed to be reimplemented. It is called everytime the state of the game changes, depending on the settings of the console, this can work out to be 10 times per second or faster. `on_update` must take a single variable, a Python dictionary that corresponds to the game state values described below for each sport.
```python
from consoles.sports import Football

def do_something(game_state):
# Do something useful with the parse score console information
# For example:
home = game_state['home_score']
visitor = game_state['visitor_score']
if home > visitor:
print(f'The Home Team leads {home} to {visitor}.')
elif visitor > home:
print(f'The Visiting Team leads {visitor} to {home}.')
else:
print(f'The teams are tied at {home}')

if __name__ == '__main__':
football = Football('COM1')
football.on_update = do_something
```

#### :basketball: Basketball
| Key | Type | Description |
Expand Down Expand Up @@ -76,3 +95,5 @@ Sport classes take a serial port string as an argument and expose an `export` me
| `clock` | str | Main Clock Time |
| `shot` | str | Shot Clock Time |
| `period` | str | Game Period |

*Water Polo is supported on both Daktronics and Colorado Time Systems consoles: for Daktronics call `WaterPoloDaktronics`, for Colorado Time Systems call `WaterPolo`*
11 changes: 9 additions & 2 deletions consoles/daktronics.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Tuple
import serial
from serial import PARITY_NONE
from serial.serialutil import SerialException
from multiprocessing.connection import Connection

from . import SerialConnection
Expand Down Expand Up @@ -37,7 +38,10 @@ def update(self, send_pipe: Connection, connection: serial.Serial) -> None:
# Filter out 'SYNC IDLE' transmissions
control_character = 0
while control_character != b'\x16':
control_character = connection.read()
try:
control_character = connection.read()
except SerialException:
continue
message = ''
last_character = b''
# Real Time Data Messages end with a 'END TRANSMISSION BLOCK'
Expand All @@ -48,5 +52,8 @@ def update(self, send_pipe: Connection, connection: serial.Serial) -> None:
message += chr(dec)
else:
pass
last_character = connection.read()
try:
last_character = connection.read()
except SerialException:
continue
self.parse(message)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="scorebox-consoles",
version="1.1.0",
version="1.1.1",
author="Daniel Flanagan",
description="Python interface for scoreboard consoles manufactured by Daktronics and Colorado Time Systems",
long_description=long_description,
Expand Down

0 comments on commit 9e77f7f

Please sign in to comment.