mirror of
https://github.com/controllerzz/carbus_lib.git
synced 2026-06-28 22:01:07 +03:00
v0.1.7 add remote server, agent, client
This commit is contained in:
@@ -11,7 +11,7 @@ async def main(is_debug=False):
|
||||
nominal_bitrate=500_000,
|
||||
)
|
||||
|
||||
await dev.set_terminator(channel=1, enabled=True)
|
||||
await dev.ensure_terminator(channel=1, enabled=True)
|
||||
|
||||
sender = PeriodicCanSender(dev)
|
||||
|
||||
@@ -33,7 +33,7 @@ async def main(is_debug=False):
|
||||
channel=1,
|
||||
can_id=0x123,
|
||||
data=b"\x01\x02\x03\x04\x05\x06\x07\x08",
|
||||
period_s=0.1,
|
||||
period_s=0.05,
|
||||
)
|
||||
|
||||
try:
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import asyncio
|
||||
|
||||
from carbus_async import CarBusDevice, PeriodicCanSender, open_remote_device
|
||||
|
||||
|
||||
async def main(is_debug=False):
|
||||
dev = await open_remote_device("84.54.37.149", 9000, serial=5957, password="1234")
|
||||
|
||||
await dev.open_can_channel(
|
||||
channel=1,
|
||||
nominal_bitrate=500_000,
|
||||
)
|
||||
|
||||
await dev.ensure_terminator(channel=1, enabled=True)
|
||||
|
||||
sender = PeriodicCanSender(dev)
|
||||
|
||||
def mod(tick, data):
|
||||
b = bytearray(data)
|
||||
b[0] = tick & 0xFF
|
||||
return bytes(b)
|
||||
|
||||
sender.add(
|
||||
"cnt",
|
||||
channel=1,
|
||||
can_id=0x100,
|
||||
data=b"\x00" * 8,
|
||||
period_s=0.5,
|
||||
modify=mod)
|
||||
|
||||
sender.add(
|
||||
"heartbeat",
|
||||
channel=1,
|
||||
can_id=0x123,
|
||||
data=b"\x01\x02\x03\x04\x05\x06\x07\x08",
|
||||
period_s=0.05,
|
||||
)
|
||||
|
||||
try:
|
||||
await asyncio.Event().wait()
|
||||
finally:
|
||||
await sender.stop_all()
|
||||
await dev.close()
|
||||
|
||||
return
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
@@ -16,7 +16,7 @@ async def main(is_debug=False):
|
||||
)
|
||||
logging.getLogger("carbus_async.wire").setLevel(logging.DEBUG)
|
||||
|
||||
dev = await open_remote_device("127.0.0.1", 9000, serial=5957, password="1234")
|
||||
dev = await open_remote_device("84.54.37.149", 9000, serial=5957, password="1234")
|
||||
|
||||
print(f"Devise SN: {await dev.get_serial()}")
|
||||
|
||||
@@ -36,4 +36,4 @@ async def main(is_debug=False):
|
||||
await dev.close()
|
||||
|
||||
|
||||
asyncio.run(main(is_debug=True))
|
||||
asyncio.run(main())
|
||||
|
||||
Reference in New Issue
Block a user