Commit 03adaace authored by Pierre NARVOR's avatar Pierre NARVOR
Browse files

[driver/python] Added base of serial driver in python

parent 78dbafe4
.*.sw*
build
docs
.*.sw*
__pycache__
*.egg-info
*.pick
*.tif
*.ply
*.pyc
output
import serial
import asyncio
import time
import threading
class SeatracSerial:
def __init__(self, device, baudrate=115200):
self.serial = serial.Serial(device, baudrate)
self.serial.bytesize = serial.EIGHTBITS
self.serial.parity = serial.PARITY_NONE
self.serial.stopbits = serial.STOPBITS_TWO
self.serial.rtscts = False
self.serial.dsrdtr = False
self.serial.timeout = 1e-3
self.running = False
self.thread = None
async def run(self):
self.running = True
while self.running:
part = self.serial.read(1024)
while len(part) > 0:
print(part)
part = self.serial.read(1024)
await asyncio.sleep(0.05)
def start(self, background=False):
self.serial.flush()
if background:
self.thread = threading.Thread(target=lambda : asyncio.run(self.run()))
self.thread.start()
else:
asyncio.run(self.run())
def stop(self):
self.running = False
if self.thread is not None:
self.thread.join()
from .SeatracSerial import SeatracSerial
from setuptools import setup, find_packages
setup(name='seatrac_usbl',
version='0.1',
description='Interface for the Blueprint Seatrac USBL',
author='Pierre Narvor',
author_email='pierre.narvor@ensta-bretagne.fr',
licence='confidential',
packages=find_packages(include=['seatrac_usbl']),
install_requires=[
'numpy',
'matplotlib',
'pyserial',
],
zip_safe=False)
#! /usr/bin/python3
import asyncio
import serial
s = serial.Serial('/dev/narval_usbl', 115200)
s.bytesize = serial.EIGHTBITS
s.parity = serial.PARITY_NONE
s.stopbits = serial.STOPBITS_TWO
s.rtscts = False
s.dsrdtr = False
s.timeout = 1e-1
s.flush()
readSize = 1024
async def read_until():
part = s.read(256)
while len(part) > 0:
print(part)
part = s.read(256)
await asyncio.sleep(0.01)
async def start():
await asyncio.gather(read_until())
asyncio.run(start())
#! /usr/bin/python3
from seatrac_usbl import SeatracSerial
serial = SeatracSerial('/dev/narval_usbl')
serial.start(background=True)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment