async def test_id(args): try: serial_port = args["port"] if serial_port is None: serial_port = '/dev/ttyUSB0' baud_rate = 115200 reader, writer = await asyncio.wait_for( serial_asyncio.open_serial_connection(url=serial_port, baudrate=baud_rate), 1) test = avalon.Transport(reader=reader, writer=writer) test.start_reader_task() test.transaction_channel_read( 0x10, channel_number=0, burst_length=4, transaction=avalon.AvalonBus.READ_NON_INCREMENTING) pkt = await test.rx_pktQueue.get() if len(pkt) is 4: print("Array length {} 0x{:04x}".format( len(pkt), int.from_bytes(pkt, byteorder='little'))) else: print("Error") test.close() writer.close() test = None return True, "" except Exception as local_ex: return False, str(local_ex)
async def start(args): try: serial_port = args["port"] if serial_port is None: serial_port = '/dev/ttyUSB0' baud_rate = args["baud"] if baud_rate: baud_rate = int(baud_rate) else: baud_rate = 115200 reader, writer = await asyncio.wait_for( serial_asyncio.open_serial_connection(url=serial_port, baudrate=baud_rate), 1) test = avalon.Transport(reader=reader, writer=writer) test.start_reader_task() led_value = 0xFFFFFF | (0x1F << 24) data = bytearray() x_bytes = led_value.to_bytes(int(math.ceil(led_value.bit_length() / 8)), byteorder='little') data.extend(x_bytes) test.transaction_channel_write(0, data, transaction=avalon.AvalonBus.LOOP_BACK, length=0x5A) await asyncio.sleep(1) test.close() test = None return True, "" except Exception as local_ex: return False, str(local_ex)
async def start(args): try: serial_port = args["port"] if serial_port is None: serial_port = '/dev/ttyUSB0' baud_rate = args["baud"] if baud_rate: baud_rate = int(baud_rate) else: baud_rate = 115200 reader, writer = await asyncio.wait_for( serial_asyncio.open_serial_connection(url=serial_port, baudrate=baud_rate), 1) test = avalon.Transport(reader=reader, writer=writer) test.start_reader_task() data = bytearray() test.transaction_channel_write(0, data, transaction=avalon.AvalonBus.LOOP_BACK, length=0x5A) await asyncio.sleep(1) test.close() test = None return True, "" except Exception as local_ex: return False, str(local_ex)
async def led_test(args): try: serial_port = args["port"] if serial_port is None: serial_port = '/dev/ttyUSB0' baud_rate = 115200 reader, writer = await asyncio.wait_for( serial_asyncio.open_serial_connection(url=serial_port, baudrate=baud_rate), 1) test = avalon.Transport(reader=reader, writer=writer) test.start_reader_task() led_value = 0x01 data = bytearray(4) for i in range(0, 0x100): data[0] = i logging.debug("length of data {}".format(len(data))) test.transaction_channel_write( 0x0, channel_number=0, data_buffer=data, transaction=avalon.AvalonBus.WRITE_NON_INCREMENTING) pkt = await test.rx_pktQueue.get() test.close() test = None return True, "" except Exception as local_ex: return False, str(local_ex)
async def test_pwm(args): try: serial_port = args["port"] if serial_port is None: serial_port = '/dev/ttyUSB0' baud_rate = args["baud"] if baud_rate: baud_rate = int(baud_rate) else: baud_rate = 115200 reader, writer = await asyncio.wait_for( serial_asyncio.open_serial_connection(url=serial_port, baudrate=baud_rate), 1) test = avalon.Transport(reader=reader, writer=writer) test.start_reader_task() for x in range(1, 10000): await asyncio.sleep(.250) test.close() writer.close() test = None return True, "" except Exception as local_ex: return False, str(local_ex)
async def test_id(args): try: serial_port = args["port"] if serial_port is None: serial_port = '/dev/ttyUSB0' baud_rate = args["baud"] if baud_rate: baud_rate = int(baud_rate) else: baud_rate = 115200 reader, writer = await asyncio.wait_for( serial_asyncio.open_serial_connection(url=serial_port, baudrate=baud_rate), 1) test = avalon.Transport(reader=reader, writer=writer) test.start_reader_task() test.transaction_channel_read( 0x60, channel_number=0, burst_length=4, transaction=avalon.AvalonBus.READ_NON_INCREMENTING) await asyncio.sleep(1) test.close() writer.close() test = None return True, "" except Exception as local_ex: return False, str(local_ex)
async def pwm_id(args): try: serial_port = args["port"] if serial_port is None: serial_port = '/dev/ttyUSB0' baud_rate = 115200 reader, writer = await asyncio.wait_for( serial_asyncio.open_serial_connection(url=serial_port, baudrate=baud_rate), 1) test = avalon.Transport(reader=reader, writer=writer) test.start_reader_task() for i in range(0, 10): test.transaction_channel_read( 0x20, channel_number=0, burst_length=4 * 6, transaction=avalon.AvalonBus.READ_INCREMENTING) pkt = await test.rx_pktQueue.get() pwm_1 = int.from_bytes(pkt[0:4], byteorder='little', signed=False) pwm_2 = int.from_bytes(pkt[4:8], byteorder='little', signed=False) pwm_3 = int.from_bytes(pkt[8:12], byteorder='little', signed=False) pwm_4 = int.from_bytes(pkt[12:16], byteorder='little', signed=False) pwm_5 = int.from_bytes(pkt[16:20], byteorder='little', signed=False) pwm_6 = int.from_bytes(pkt[20:], byteorder='little', signed=False) print( "pwm_1 0x{:08x} 0x{:08x} 0x{:08x} 0x{:08x} 0x{:08x} 0x{:08x}" .format(pwm_1, pwm_2, pwm_3, pwm_4, pwm_5, pwm_6), end='\r', flush=True) await asyncio.sleep(.1) test.close() writer.close() test = None return True, "" except Exception as local_ex: return False, str(local_ex)
async def test_led(args, loop): try: serial_port = args["port"] if serial_port is None: serial_port = '/dev/ttyUSB0' baud_rate = args["baud"] if baud_rate: baud_rate = int(baud_rate) else: baud_rate = 115200 reader, writer = await asyncio.wait_for( serial_asyncio.open_serial_connection(url=serial_port, baudrate=baud_rate), 1) test = avalon.Transport(reader=reader, writer=writer) test.start_reader_task() """ for z in range (0, 10): for x in range (0, 8): data = bytearray() led_value = (1 << x) x_bytes= led_value.to_bytes(4, byteorder='little') data.extend(x_bytes) test.transaction_channel_write(0, channel_number=0, data_buffer=data, transaction=avalon.AvalonBus.WRITE_NON_INCREMENTING) await asyncio.sleep(.01) """ data = bytearray() test.transaction_channel_read( 0x60, channel_number=0, transaction=avalon.AvalonBus.READ_INCREMENTING) await asyncio.sleep(1) led_value = 0x00 x_bytes = led_value.to_bytes(4, byteorder='little') data.extend(x_bytes) test.transaction_channel_write( 0x050, channel_number=0, data_buffer=data, transaction=avalon.AvalonBus.WRITE_NON_INCREMENTING) led_index = 0 for y in range(0, 10000): led_index += 1 if led_index is 8: led_index = 0 for x in range(0, 8): data = bytearray() if x == led_index: led_value = 0xFF00FF00 else: led_value = 0xFF000000 x_bytes = led_value.to_bytes(4, byteorder='little') data.extend(x_bytes) test.transaction_channel_write( 0x0 + (x * 4), channel_number=0, data_buffer=data, transaction=avalon.AvalonBus.WRITE_NON_INCREMENTING) await asyncio.sleep(.1) data = bytearray() led_value = 0x00000000 x_bytes = led_value.to_bytes(4, byteorder='little') data.extend(x_bytes) test.transaction_channel_write( 0x0 + (8 * 4), channel_number=0, data_buffer=data, transaction=avalon.AvalonBus.WRITE_NON_INCREMENTING) await asyncio.sleep(.01) test.close() writer.abort() writer.close() test = None loop.stop() return True, "" except Exception as local_ex: loop.stop() return False, str(local_ex)
async def test_ap102(args): try: serial_port = args["port"] if serial_port is None: serial_port = '/dev/ttyUSB0' baud_rate = args["baud"] if baud_rate: baud_rate = int(baud_rate) else: baud_rate = 115200 reader, writer = await asyncio.wait_for( serial_asyncio.open_serial_connection(url=serial_port, baudrate=baud_rate), 1) test = avalon.Transport(reader=reader, writer=writer) test.start_reader_task() data = bytearray() blue = 0xff green = 0xff red = 0xff high_range = 1 for index in range(0, high_range): for x in range(0, 8): led_value = set_led(0xF, blue=blue, green=green, red=red) x_bytes = led_value.to_bytes(4, byteorder='little') data.extend(x_bytes) test.transaction_channel_write( index, channel_number=0, data_buffer=data, transaction=avalon.AvalonBus.WRITE_INCREMENTING) logging.debug("index: " + str(index) + " " + str(index / 4 - 1)) await asyncio.sleep(.1) data = bytearray() led_enable = 1 x_bytes = led_enable.to_bytes(4, byteorder='little') data.extend(x_bytes) test.transaction_channel_write( 0, channel_number=0, data_buffer=data, transaction=avalon.AvalonBus.WRITE_NON_INCREMENTING) await asyncio.sleep(.250) if index % 2: blue = 0 green = 0 red = 0xff else: blue = 0xff green = 0xff red = 0xff test.close() writer.close() test = None return True, "" except Exception as local_ex: return False, str(local_ex)