def APDS9960_ReadMulti(ser, reg, count): strx = "i2c write 1,0x39," + hex(reg & 0xFF) + "\r\n" usb2io_sendcmd(ser, strx, 1) strx = "i2c read 1,0x39," + str(count) + "\r\n" rrd = usb2io_sendcmd(ser, strx, 1) ba1 = [int(i, 16) for i in rrd.replace('OK,', '').split(',')] return (ba1)
def APDS9960_RdByte(ser, reg): strx = "i2c write 1,0x39," + hex(reg & 0xFF) + "\r\n" usb2io_sendcmd(ser, strx, 1) strx = "i2c read 1,0x39,1\r\n" rrd = usb2io_sendcmd(ser, strx, 1) if (rrd.find("OK,", 0, 3) != -1): bytes_str = rrd[3:] return (True, int(bytes_str, 16)) return (False, 0)
def APDS9960_RdDWord(ser, reg): strx = "i2c write 1,0x39," + hex(reg & 0xFF) + "\r\n" rrd = usb2io_sendcmd(ser, strx, 1) strx = "i2c read 1,0x39,4\r\n" rrd = usb2io_sendcmd(ser, strx, 1) if (rrd.find('FAIL') != -1): return (False, 0) ba1 = [int(i, 16) for i in rrd.replace('OK,', '').split(',')] dwval = (ba1[0] << 24) | (ba1[1] << 16) | (ba1[2] << 8) | ba1[3] return (True, dwval)
def readRegister(self, addr): # first set address if (usb2io_sendcmd( self.ser, "i2c write 1, " + str(AS7265X_ADDR) + ", " + str(addr) + "\r\n", 1) != "OK\r\n"): return False, 0 rrd = usb2io_sendcmd(self.ser, "i2c read 1, " + str(AS7265X_ADDR) + ", 1\r\n", 1) if (rrd.find("OK,", 0, 3) != -1): # parse result bytes_str = rrd[3:] return True, int(bytes_str, 16) return False, 0
print "====================================" print "* AK4954 Config" print "====================================" local_com_port = COM_PORT_ENG # Open serial port print "Open serial port " + local_com_port try: ser = serial.Serial(local_com_port, 115200, timeout=3) print "COM port OK" except: print "Error COM port" sys.exit(0) usb2io_sendcmd(ser, "hello\r\n") print "Configure I2C" usb2io_sendcmd(ser, "i2c configure 0\r\n") print("Configuring 4 pins to spi repeater...") usb2io_sendcmd(ser, "gpio configure 2, 7\r\n") usb2io_sendcmd(ser, "gpio configure 3, 7\r\n") usb2io_sendcmd(ser, "gpio configure 4, 7\r\n") usb2io_sendcmd(ser, "gpio configure 5, 7\r\n") print("Configuring pin 0 as reset") # reset lo usb2io_sendcmd(ser, "gpio configure 0, 1\r\n") usb2io_sendcmd(ser, "gpio configure 0, 2\r\n")
#put data to buffer data = bytearray(data_count) for i in range(0, data_count): data[i] = i + 1 # send to target print("Sending buffer...") if (put_buffer(ser, data) == 0): sys.exit(0) print("RS485 Wreading...") # format: uart wreadbuffer channel, data_count res = usb2io_sendcmd(ser, "rs485 wreadbuffer 4," + str(data_count) + "\r\n") if (res.find("OK") != -1): # parse result bytes_str = res[3:] rx_cnt = int(bytes_str, 10) # print "received = " + str(rx_cnt) (status, data_out) = get_buffer(ser, rx_cnt) if (status == True): print data_out.encode("hex") else: print "Get buffer failed" print "\r\n" else: print "failed."
data[i * 8 + 3] = (sR >> 24) & 0xFF data[i * 8 + 4] = sL & 0xFF data[i * 8 + 5] = (sL >> 8) & 0xFF data[i * 8 + 6] = (sL >> 16) & 0xFF data[i * 8 + 7] = (sL >> 24) & 0xFF # send to target print("Sending buffer...") print("len = " + str(len(data))) if (put_buffer(ser, data) == 0): sys.exit(0) print("Starting...") usb2io_sendcmd(ser, "i2s wreadbuf 1, " + str(data_cnt) + "\r\n") print("Busy...") done = 0 while (done == 0): rrd = ser.readline() if (rrd != ''): print(rrd) else: print('.') if (rrd == 'OK\r\n'): done = 1 # get buffer print("Reading...") (status, data_out) = get_buffer(ser, data_cnt * 4)
print "* I2C writebuffer sync" print "====================================" local_com_port = sys.argv[1] if (len(sys.argv) > 1) else COM_PORT_ENG # Open serial port print "Open serial port " + local_com_port try: ser = serial.Serial(local_com_port, 115200, timeout=3) print "COM port OK" except: print "Error COM port" sys.exit(0) print "Configure pin [0] to WFG mode" usb2io_sendcmd(ser, "gpio configure 2,4\r\n") # Set Ext voltage to 3.3V print "Configure EXT voltage to 3.3V" usb2io_sendcmd(ser, "expv write 3300\r\n") print "Configure WFG" # configure wfg # the configuration should be sent to uC with put_buffer command. See description of "waveform gen configure" for config structure data = bytearray(32 + segment_size * 2) data[0] = sample_rate & 0xFF data[1] = (sample_rate >> 8) & 0xFF data[2] = (sample_rate >> 16) & 0xFF data[3] = (sample_rate >> 24) & 0xFF
print "Open serial port " + local_com_port try: ser = serial.Serial(local_com_port, 115200, timeout=3) print "COM port OK" except: print "Error COM port" sys.exit(0) wro = ser.write("hello\r\n") time.sleep(0.1) rrd = ser.readline() print(rrd) # pin 2..5 - SPI print "Configure pins [2..5] to SPI mode" usb2io_sendcmd(ser, "gpio configure 2,7\r\n") usb2io_sendcmd(ser, "gpio configure 3,7\r\n") usb2io_sendcmd(ser, "gpio configure 4,7\r\n") usb2io_sendcmd(ser, "gpio configure 5,7\r\n") # Set Ext voltage to 3.3V print "Configure EXT voltage to 3.3V" usb2io_sendcmd(ser, "expv write 3300\r\n") #print "Configure SPI: Set 100KHz clock, Polarity low, CS active high, Phase 1st, MSB" usb2io_sendcmd(ser, "spi configure 1,0,0,0,100000,0\r\n") print "Read from SPI device 32 bytes" usb2io_sendcmd(ser, "spi read 1,32\r\n") print "Write to SPI device 2 bytes and read back"
#===================================================== import os import sys import time import serial import select import struct from usb2io import usb2io_sendcmd COM_PORT_ENG = 'COM17' #---- Application --------------------------------------------------------- print "====================================" print "* DCMI camera fpga test *" print "====================================" local_com_port = sys.argv[1] if (len(sys.argv) > 1) else COM_PORT_ENG # Open serial port7 print "Open serial port " + local_com_port try: ser = serial.Serial(local_com_port, 115200, timeout=3) print "COM port OK" except: print "Error COM port" sys.exit(0) usb2io_sendcmd(ser, "fpga camera start 1\r\n") # Close serial port ser.close() raw_input("Press Enter to exit ...")
def writeRegister(self, addr, val): if (usb2io_sendcmd( self.ser, "i2c write 1, " + str(AS7265X_ADDR) + ", " + str(addr) + ", " + str(val) + "\r\n", 1) == "OK\r\n"): return True return False
wro = ser.write(strx) time.sleep(0.02) rrd = ser.readline() # Open serial port print "Open serial port " + local_com_port try: ser = serial.Serial(local_com_port, 115200, timeout=3) print "COM port OK" except: print "Error COM port" sys.exit(0) print "Configure EXT voltage to 3.3V" usb2io_sendcmd(ser, "expv write 3300\r\n") print "Configure PIN" usb2io_sendcmd(ser, "gpio configure 0, 22\r\n", 1) usb2io_sendcmd(ser, "gpio configure 1, 22\r\n", 1) usb2io_sendcmd(ser, "gpio configure 2, 22\r\n", 1) usb2io_sendcmd(ser, "gpio configure 3, 22\r\n", 1) usb2io_sendcmd(ser, "gpio configure 4, 22\r\n", 1) usb2io_sendcmd(ser, "gpio configure 5, 22\r\n", 1) usb2io_sendcmd(ser, "gpio configure 6, 22\r\n", 1) usb2io_sendcmd(ser, "gpio configure 7, 22\r\n", 1) usb2io_sendcmd(ser, "gpio configure 8, 22\r\n", 1) usb2io_sendcmd(ser, "gpio configure 9, 22\r\n", 1) usb2io_sendcmd(ser, "gpio configure 10, 22\r\n", 1) usb2io_sendcmd(ser, "gpio configure 11, 22\r\n", 1)
local_com_port = sys.argv[1] if (len(sys.argv) > 1) else COM_PORT_ENG # Open serial port print "Open serial port " + local_com_port try: ser = serial.Serial(local_com_port, 115200, timeout=3) print "COM port OK" except: print "Error COM port" sys.exit(0) TRX_TIMEOUT = 300 print "Configure pin [0] to WFG mode" usb2io_sendcmd(ser, "gpio configure 0,4\r\n") print ("Configure WFG") # configure wfg # the configuration should be sent to uC with put_buffer command. See description of "waveform gen configure" for config structure data = bytearray(32 + segment_size * 2) data[0] = sample_rate & 0xFF; data[1] = (sample_rate >> 8) & 0xFF; data[2] = (sample_rate >> 16) & 0xFF; data[3] = (sample_rate >> 24) & 0xFF; data[4] = segment_size & 0xFF; data[5] = (segment_size >> 8) & 0xFF;
COM_PORT_ENG = 'COM132' #---- Application --------------------------------------------------------- local_com_port = sys.argv[1] if (len(sys.argv) > 1) else COM_PORT_ENG # Open serial port print("Open serial port " + local_com_port) try: ser = serial.Serial(local_com_port, 115200, timeout=3) print("COM port OK") except: print("Error COM port") sys.exit(0) usb2io_sendcmd(ser, "hello\r\n") # Set MDIO pinmux usb2io_sendcmd(ser, "gpio configure 2, 11\r\n", silent = 1) usb2io_sendcmd(ser, "gpio configure 3, 11\r\n", silent = 1) # Set Ext voltage to 2.5V usb2io_sendcmd(ser, "expv write 2500\r\n", silent = 1) # Reset PHY and start autonegotiation usb2io_sendcmd(ser, "mdio write 1,0,0x9200\r\n", silent = 1) # Close serial port ser.close() print("MDIO test done")
print "* GPIO 6 - PRE" print "* GPIO 7 - Trigger" print "====================================" local_com_port = sys.argv[1] if (len(sys.argv) > 1) else COM_PORT_ENG # Open serial port print "Open serial port " + local_com_port try: ser = serial.Serial(local_com_port, 115200, timeout=3) print "COM port OK" except: print "Error COM port" sys.exit(0) usb2io_sendcmd(ser, "hello\r\n") print("Configuring pins to LTC2500...") if (usb2io_sendcmd(ser, "gpio configure 0, 15\r\n", 1) != "OK\r\n"): print "failed." sys.exit(0) if (usb2io_sendcmd(ser, "gpio configure 1, 15\r\n", 1) != "OK\r\n"): print "failed." sys.exit(0) if (usb2io_sendcmd(ser, "gpio configure 2, 15\r\n", 1) != "OK\r\n"): print "failed." sys.exit(0)
local_com_port = sys.argv[1] if (len(sys.argv) > 1) else COM_PORT_ENG # Open serial port print("Open serial port " + local_com_port) try: ser = serial.Serial(local_com_port, 115200, timeout=3) print("COM port OK") except: print("Error COM port") sys.exit(0) print("Starting step motor cntroller...") # start channel 1 #if usb2io_sendcmd(ser, "stepmotor start 1\r\n") != "OK\r\n": # print "failed." # sys.exit(0) # start channel 2 #if usb2io_sendcmd(ser, "stepmotor start 2\r\n") != "OK\r\n": # print "failed." # sys.exit(0) # start all channels if usb2io_sendcmd(ser, "stepmotor start 0\r\n") != "OK\r\n": print("failed.") sys.exit(0) input("Press Enter to exit...")
AddCommand(buffer, 0xad) #/* master configuration */ AddCommand(buffer, 0x8e) #/* external vcc supply */ AddCommand(buffer, 0xc8) #/* set com scan direction */ AddCommand(buffer, 0xd3) #/* set display offset */ AddCommand(buffer, 0x40) # AddCommand(buffer, 0xd5) #/* set display clock divide/oscillator frequency */ AddCommand(buffer, 0xf0) # AddCommand(buffer, 0xD8) #/*set area color mode off */ AddCommand(buffer, 0x05) # AddCommand(buffer, 0xD9) # AddCommand(buffer, 0xF1) # AddCommand(buffer, 0xda) #/* set com pin configuartion */ AddCommand(buffer, 0x12) # AddCommand(buffer, 0x91) # AddCommand(buffer, 0x3F) # AddCommand(buffer, 0x3F) # AddCommand(buffer, 0x3F) # AddCommand(buffer, 0x3F) # AddCommand(buffer, 0xaf) # /* set display on */ # send buffer to uC SDRAM if (put_buffer(ser, buffer) == 0): sys.exit(0) usb2io_sendcmd(ser, "lcd fpga buffer write " + str(len(buffer) / 2) + "\r\n") ser.close() print "Done" raw_input("Press Enter to exit ...")
print("* GPIO 6 - Tx") print("* GPIO 7 - phy S") print("* GPIO 8 - phy FLT") print("* GPIO 9 - Rx") print("====================================") local_com_port = sys.argv[1] if (len(sys.argv) > 1) else COM_PORT_ENG # Open serial port print("Open serial port " + local_com_port) try: ser = serial.Serial(local_com_port, 115200, timeout=3) print("COM port OK") except: print("Error COM port") sys.exit(0) usb2io_sendcmd(ser, "hello\r\n") print("Configuring 4 gpio pins...") usb2io_sendcmd(ser, "gpio configure 7, 1\r\n") # silent mode OFF usb2io_sendcmd(ser, "gpio configure 8, 0\r\n") # input usb2io_sendcmd(ser, "gpio configure 9, 9\r\n") # FDCAN1 repeater usb2io_sendcmd(ser, "gpio configure 6, 9\r\n") # FDCAN1 repeater print("Configuring CAN bus (1Mbps baudrate, no CAN FD)") usb2io_sendcmd(ser, "fdcan configure 1000000, 0\r\n") # input("Press Enter to exit ...")
import serial import select from usb2io import usb2io_sendcmd COM_PORT_ENG = 'COM17' # port select. 1 - stm32, 2 - fpga port = 1 #---- Application --------------------------------------------------------- print("====================================") print("* I2C scan") print("====================================") local_com_port = sys.argv[1] if (len(sys.argv) > 1) else COM_PORT_ENG # Open serial port print("Open serial port " + local_com_port) try: ser = serial.Serial(local_com_port, 115200, timeout=3) print("COM port OK") except: print("Error COM port") sys.exit(0) print("Scan I2C bus") rrd = usb2io_sendcmd(ser, "i2c scan " + str(port) + "\r\n", 1) print(rrd) # Close serial port ser.close() input("Press Enter to exit ...")
#===================================================== # FDCAN send std message #===================================================== import os import sys import time import serial import select from usb2io import usb2io_sendcmd COM_PORT_ENG = 'COM17' #---- Application --------------------------------------------------------- print "====================================" print "* FDCAN send std message" print "====================================" local_com_port = sys.argv[1] if (len(sys.argv) > 1) else COM_PORT_ENG # Open serial port print "Open serial port " + local_com_port try: ser = serial.Serial(local_com_port, 115200, timeout=3) print "COM port OK" except: print "Error COM port" sys.exit(0) usb2io_sendcmd(ser, "fdcan send std 0x123, 1 , 2, 3, 4, 5, 6, 7, 8\r\n") raw_input("Press Enter to exit ...")
#===================================================== import os import sys import time import serial import select from usb2io import usb2io_sendcmd COM_PORT_ENG = 'COM17' #---- Application --------------------------------------------------------- print("====================================") print("* FDCAN send ext message") print("====================================") local_com_port = sys.argv[1] if (len(sys.argv) > 1) else COM_PORT_ENG # Open serial port print("Open serial port " + local_com_port) try: ser = serial.Serial(local_com_port, 115200, timeout=3) print("COM port OK") except: print("Error COM port") sys.exit(0) usb2io_sendcmd( ser, "fdcan send ext 0x1BAC1234, 10 , 11, 12, 13, 14, 15, 16, 17\r\n") input("Press Enter to exit ...")
print "====================================" local_com_port = sys.argv[1] if (len(sys.argv) > 1) else COM_PORT_ENG # Open serial port print "Open serial port " + local_com_port try: ser = serial.Serial(local_com_port, 115200, timeout=3) print "COM port OK" except: print "Error COM port" sys.exit(0) print("Configuring pins + reset..") if usb2io_sendcmd(ser, "gpio configure 2, 0\r\n") != "OK\r\n": print "failed." sys.exit(0) time.sleep(0.1) if usb2io_sendcmd(ser, "gpio configure 0, 1\r\n") != "OK\r\n": print "failed." sys.exit(0) time.sleep(0.1) if usb2io_sendcmd(ser, "gpio configure 0, 2\r\n") != "OK\r\n": print "failed." sys.exit(0) time.sleep(1) device = AS7265x(ser)
import select from usb2io import usb2io_sendcmd COM_PORT_ENG = 'COM17' #---- Application --------------------------------------------------------- print "====================================" print "* UART1 config" print "* pin connection:" print "* GPIO10 - UART1 Rx" print "* GPIO11 - UART1 Tx" print "* GPIO12 - UART1 RTS" print "* GPIO13 - UART1 CTS" print "====================================" local_com_port = sys.argv[1] if (len(sys.argv) > 1) else COM_PORT_ENG # Open serial port print "Open serial port " + local_com_port try: ser = serial.Serial(local_com_port, 115200, timeout=30) print "COM port OK" except: print "Error COM port" sys.exit(0) print("Reading...") # format: uart read channel, timeout\r\n usb2io_sendcmd(ser, "uart read 1, 1000\r\n") raw_input("Press Enter to exit ...")
print "Error COM port" sys.exit(0) data = bytearray(data_cnt * 8) for i in range(0, data_cnt): sampleR = int(0x40000000 + 0x40000000 * math.sin(2 * 3.14 * i / 44)) sampleL = int(0x40000000 + 0x40000000 * math.sin(2 * 3.14 * i / 11)) #sampleR = 0 #sampleR = 0 data[i * 8] = sampleR & 0xFF data[i * 8 + 1] = (sampleR >> 8) & 0xFF data[i * 8 + 2] = (sampleR >> 16) & 0xFF data[i * 8 + 3] = (sampleR >> 24) & 0xFF data[i * 8 + 4] = sampleL & 0xFF data[i * 8 + 5] = (sampleL >> 8) & 0xFF data[i * 8 + 6] = (sampleL >> 16) & 0xFF data[i * 8 + 7] = (sampleL >> 24) & 0xFF # send to target print("Sending buffer...") print("len = " + str(len(data))) if (put_buffer(ser, data) == 0): sys.exit(0) print("Starting...") usb2io_sendcmd(ser, "i2s writebuffer 1, " + str(data_cnt) + "\r\n") raw_input("Press Enter to exit ...")
print("* DRV8711EVB J2 B- = Blue") print("* DRV8711EVB using motor ACT-Motor 23HS8430, Vsupply = 12V, 5Amax") print("====================================") local_com_port = sys.argv[1] if (len(sys.argv) > 1) else COM_PORT_ENG # Open serial port print("Open serial port " + local_com_port) try: ser = serial.Serial(local_com_port, 115200, timeout=3) print("COM port OK") except: print("Error COM port") sys.exit(0) usb2io_sendcmd(ser, "hello\r\n") print("Configuring 4 pins to step motor controller...") if usb2io_sendcmd(ser, "gpio configure 0, 13\r\n") != "OK\r\n": print("failed.") sys.exit(0) if usb2io_sendcmd(ser, "gpio configure 1, 13\r\n") != "OK\r\n": print("failed.") sys.exit(0) if usb2io_sendcmd(ser, "gpio configure 14, 16\r\n") != "OK\r\n": print("failed.") sys.exit(0)
import serial import select from usb2io import usb2io_sendcmd COM_PORT_ENG = 'COM17' #---- Application --------------------------------------------------------- print("====================================") print("* FDCAN recv signle message") print("====================================") local_com_port = sys.argv[1] if (len(sys.argv) > 1) else COM_PORT_ENG # Open serial port print("Open serial port " + local_com_port) try: ser = serial.Serial(local_com_port, 115200, timeout=3) print("COM port OK") except: print("Error COM port") sys.exit(0) c_time = time.time() * 1000. while (1): rx_out = usb2io_sendcmd(ser, "fdcan recv single\r\n", 1) d_time = (time.time() * 1000.) - c_time c_time = time.time() * 1000. print("[%f] %s " % (d_time, rx_out)) input("Press Enter to exit ...")
import time import serial import select from usb2io import usb2io_sendcmd COM_PORT_ENG = 'COM17' # port select. 1 - stm32, 2 - fpga port = 2 #---- Application --------------------------------------------------------- print "====================================" print "* IIC Reading" print "====================================" local_com_port = COM_PORT_ENG # Open serial port print "Open serial port " + local_com_port try: ser = serial.Serial(local_com_port, 115200, timeout=3) print "COM port OK" except: print "Error COM port" sys.exit(0) usb2io_sendcmd(ser, "i2c write " + str(port) + ", 0x12, 0x04\r\n") usb2io_sendcmd(ser, "i2c read " + str(port) + ", 0x12, 3\r\n") # Close serial port ser.close() raw_input("Press Enter to exit...")
if (not file_path): print "no file selected" sys.exit(0) file_size = os.path.getsize(file_path) print("file size = " + str(file_size)) if (file_size == 0): sys.exit(0) if ((file_size & 0x01) != 0): print "WARNING! File size is odd. " + str( file_size + 1) + " bytes will be sent instead." f = open(file_path, 'rb') if (f == None): print "can not open file." sys.exit(0) data = bytearray(f.read()) f.close() if ((len(data) & 0x01) != 0): data.append(0x5A) if (put_buffer(ser, data) == 0): sys.exit(0) usb2io_sendcmd(ser, "service serial bufsend " + str(len(data) / 2) + "\r\n") raw_input("Press Enter to exit...")
#===================================================== import os import sys import time import serial import select from usb2io import usb2io_sendcmd COM_PORT_ENG = 'COM17' #---- Application --------------------------------------------------------- print ("====================================") print ("* Hello app") print ("====================================") local_com_port = sys.argv[1] if (len(sys.argv) > 1) else COM_PORT_ENG # Open serial port print ("Open serial port " + local_com_port) try: ser = serial.Serial(local_com_port, 115200, timeout=3) print ("COM port OK") except: print ("Error COM port") sys.exit(0) rrd = usb2io_sendcmd(ser, "hello\r\n", 1) print(rrd) input("Press Enter to exit...")