https://github.com/jsonfm/serialio
https://github.com/jsonfm/serialio
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/jsonfm/serialio
- Owner: jsonfm
- License: mit
- Created: 2021-12-24T22:21:00.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-12-25T15:38:17.000Z (over 4 years ago)
- Last Synced: 2025-03-25T13:47:02.873Z (over 1 year ago)
- Language: Python
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SerialIO
A serial library based on callbacks and threading.
## Single Serial Device
You could run a single serial device as follows:
```python
from serialio import SerialEmitter
serial = SerialEmitter(port='/dev/cu.usbserial-1460', baudrate='9600', timeout=0.25)
# Do something if the connection status changes
serial.on('connection-status', lambda status: print('serial port is open: ', status))
# Do something if a new data were received
serial.on('data-incoming', lambda data: print('received data: ', data))
# Do something if a change occurs in the serial ports
serial.on('ports-update', lambda ports: print('New devices detected: ', ports))
# Start execution loop
serial.start()
```
The serial device has its own execution loop running on a thread.
## Multiple Serial Devices
Also multiples serial devices cool be manage at the same time:
```python
from serialio import SerialManager
serial = SerialManager(devices=['/dev/cu.usbserial-1460'], baudrate=9600, timeout=0.25)
# Do something if the connection status changes
serial.on('connection-status', lambda device, status: print(f'{device} connection status: {status}'))
# Do something if a new data were received
serial.on('data-incoming', lambda device, data: print(f'{device} has new data: {data}'))
# Start all serial devices listed
serial.startAll()
```
## License
MIT