mirror of
https://github.com/meshcore-dev/meshcore_py.git
synced 2026-06-11 11:56:18 +00:00
deal with serial_cx issues
This commit is contained in:
@@ -44,6 +44,8 @@ async def main():
|
|||||||
|
|
||||||
print("Connected to MeshCore device")
|
print("Connected to MeshCore device")
|
||||||
|
|
||||||
|
res = await meshcore.commands.send_device_query()
|
||||||
|
|
||||||
# Get contacts
|
# Get contacts
|
||||||
result = await meshcore.commands.get_contacts()
|
result = await meshcore.commands.get_contacts()
|
||||||
if result.type == EventType.ERROR:
|
if result.type == EventType.ERROR:
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
from meshcore import MeshCore, EventType
|
||||||
from meshcore import MeshCore
|
|
||||||
|
|
||||||
PORT = "/dev/tty.usbserial-583A0069501"
|
PORT = "/dev/tty.usbserial-583A0069501"
|
||||||
BAUDRATE = 115200
|
BAUDRATE = 115200
|
||||||
|
|||||||
@@ -67,10 +67,9 @@ class MeshCore:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def create_serial(cls, port: str, baudrate: int = 115200, debug: bool = False, default_timeout=None,
|
async def create_serial(cls, port: str, baudrate: int = 115200, debug: bool = False, default_timeout=None,
|
||||||
auto_reconnect: bool = False, max_reconnect_attempts: int = 3) -> 'MeshCore':
|
auto_reconnect: bool = False, max_reconnect_attempts: int = 3, cx_dly:float = 0.1) -> 'MeshCore':
|
||||||
"""Create and connect a MeshCore instance using serial connection"""
|
"""Create and connect a MeshCore instance using serial connection"""
|
||||||
connection = SerialConnection(port, baudrate)
|
connection = SerialConnection(port, baudrate, cx_dly=cx_dly)
|
||||||
await asyncio.sleep(0.2) # Time for transport to establish
|
|
||||||
|
|
||||||
mc = cls(connection, debug=debug, default_timeout=default_timeout,
|
mc = cls(connection, debug=debug, default_timeout=default_timeout,
|
||||||
auto_reconnect=auto_reconnect, max_reconnect_attempts=max_reconnect_attempts)
|
auto_reconnect=auto_reconnect, max_reconnect_attempts=max_reconnect_attempts)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import serial_asyncio
|
|||||||
logger = logging.getLogger("meshcore")
|
logger = logging.getLogger("meshcore")
|
||||||
|
|
||||||
class SerialConnection:
|
class SerialConnection:
|
||||||
def __init__(self, port, baudrate):
|
def __init__(self, port, baudrate, cx_dly=0.2):
|
||||||
self.port = port
|
self.port = port
|
||||||
self.baudrate = baudrate
|
self.baudrate = baudrate
|
||||||
self.frame_started = False
|
self.frame_started = False
|
||||||
@@ -18,6 +18,7 @@ class SerialConnection:
|
|||||||
self.header = b""
|
self.header = b""
|
||||||
self.inframe = b""
|
self.inframe = b""
|
||||||
self._disconnect_callback = None
|
self._disconnect_callback = None
|
||||||
|
self.cx_dly = cx_dly
|
||||||
|
|
||||||
class MCSerialClientProtocol(asyncio.Protocol):
|
class MCSerialClientProtocol(asyncio.Protocol):
|
||||||
def __init__(self, cx):
|
def __init__(self, cx):
|
||||||
@@ -52,6 +53,7 @@ class SerialConnection:
|
|||||||
loop, lambda: self.MCSerialClientProtocol(self),
|
loop, lambda: self.MCSerialClientProtocol(self),
|
||||||
self.port, baudrate=self.baudrate)
|
self.port, baudrate=self.baudrate)
|
||||||
|
|
||||||
|
await asyncio.sleep(self.cx_dly) # wait for cx to establish
|
||||||
logger.info("Serial Connection started")
|
logger.info("Serial Connection started")
|
||||||
return self.port
|
return self.port
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user