diff --git a/pypozyx/lib.py b/pypozyx/lib.py index 9b8a576..fbb8bb9 100755 --- a/pypozyx/lib.py +++ b/pypozyx/lib.py @@ -766,8 +766,8 @@ def setUpdateInterval(self, ms, remote_id=None): """ if not dataCheck(ms): ms = SingleRegister(ms, size=2) - assert ms[0] > 100 and ms[ - 0] <= 600000, 'setUpdateInterval: ms not 100 10 and ms[ + 0] <= 600000, 'setUpdateInterval: ms not 10" | awk \'{ print $2 }\' | awk -F "/" \'{ print $1 }\'').read().strip() + return ip_wlan0 + def list_serial_ports(): """Prints the open serial ports line per line""" ports = comports() @@ -66,14 +80,28 @@ class PozyxSerial(PozyxLib): >>> pozyx = PozyxSerial(serial.tools.list_ports.comports()[0]) """ + # builds a list of all pozyx devices used in one script + instances = [] + ## \addtogroup core # @{ - def __init__(self, port, baudrate=115200, timeout=0.1, write_timeout=0.1, print_output=False, debug_trace=False): + def __init__(self, port=9001, baudrate=115200, timeout=0.1, write_timeout=0.1, print_output=False, debug_trace=False, tcp=False, ip=get_wlan0_ip()): """Initializes the PozyxSerial object. See above for details.""" + self.__class__.instances.append(weakref.proxy(self)) self.print_output = print_output + self.baudrate = baudrate + self.ip = ip + self.port = port + self.url = "socket://" + self.ip + ":" + self.port + # threading lock for the serial exchange + self.rlock = threading.RLock() try: - self.ser = Serial(port, baudrate, timeout=timeout, - write_timeout=write_timeout) + # adding TCP support + if tcp == True: + self.ser = serial_for_url(url=self.url, baudrate=self.baudrate, ) + else: + self.ser = Serial(port, baudrate, timeout=timeout, + write_timeout=write_timeout) except: print( "Couldn't connect with Pozyx, wrong/busy serial port, or pySerial not installed.") @@ -144,8 +172,14 @@ def serialExchange(self, s): Serial message the Pozyx returns, stripped from 'D,' at its start and NL+CR at the end. """ + self.rlock.acquire() self.ser.write(s.encode()) + self.rlock.release() + + self.rlock.aqcuire() response = self.ser.readline().decode() + self.rlock.release() + if self.print_output: print('The response to %s is %s.' % (s.strip(), response.strip())) if len(response) == 0: