def agilent4uhv(): """ AGILENT 4UHV """ logger.debug("AGILENT 4UHV") if (GPIO.input(PIN_FTDI_PRU) == FTDI and GPIO.input(PIN_RS232_RS485) == RS485 and PRUserial485_address() == 21 and os.path.exists(PORT)): baud = 38400 ser = Serial(port=PORT, baudrate=baud, timeout=0.6) devices = [] for addr in range(0, 32): ser.reset_input_buffer() ser.reset_output_buffer() pl = "" pl += "\x02" pl += chr(addr + 128) pl += "\x38" pl += "\x31" pl += "\x30" pl += "\x30" pl += "\x03" ser.write(Agilent4UHV_CRC(pl).encode("latin-1")) res = ser.read(15).decode("latin-1") if len(res) != 0: devices.append(addr) ser.close() name = "Agilent 4UHV" if len(devices): persist_info(Type.AGILENT4UHV, name, baud, AGILENT4UHV, "AGILENT4UHV connected {}".format(devices))
def no_tty(): """ NO /dev/ttyUSB0 """ logger.debug('No /dev/ttyUSB0') if not os.path.exists(PORT) and PRUserial485_address() == 21: persist_info(Type.UNDEFINED, 115200, NOTTY)
def spixconv(): """ SPIxCONV """ logger.debug('SPIxCONV') if not SPIxCONV: return subprocess.call('config-pin P9_17 spi_cs', shell=True) # CS subprocess.call('config-pin P9_21 spi', shell=True) # DO subprocess.call('config-pin P9_18 spi', shell=True) # DI subprocess.call('config-pin P9_22 spi_sclk', shell=True) # CLK subprocess.call('config-pin P8_37 gpio', shell=True) # BUSY subprocess.call('config-pin P9_24 gpio', shell=True) # LDAC / CNVST subprocess.call('config-pin P9_26 gpio', shell=True) # RS for addr in range(0, 255): if flash.ID_read(addr) == 4: spi_addr = 8 if flash.address_read( addr) == 0 else flash.address_read(addr) logger.info('{}'.format('Addr code', addr, 'Selection Board ID', selection.board_ID(addr), 'Flash address', flash.address_read(addr), 'SPI Addr', spi_addr)) persist_info(Type.SPIXCONV, spi_addr, SPIXCONV, 'SPIXCONV connected {}'.format(spi_addr))
def counting_pru(): """ CountingPRU """ logger.debug('Counting PRU') if PRUserial485_address() != 21 and not os.path.isfile(PORT): persist_info(Type.COUNTING_PRU, 0, COUNTING_PRU)
def agilent4uhv(): """ AGILENT 4UHV """ logger.debug('AGILENT 4UHV') if GPIO.input(PIN_FTDI_PRU) == FTDI and GPIO.input( PIN_RS232_RS485) == RS485 and PRUserial485_address() == 21: baud = 38400 ser = Serial(port=PORT, baudrate=baud, timeout=.6) devices = [] for addr in range(0, 32): ser.reset_input_buffer() ser.reset_output_buffer() pl = "" pl += "\x02" pl += chr(addr + 128) pl += "\x38" pl += "\x31" pl += "\x30" pl += "\x30" pl += "\x03" ser.write(Agilent4UHV_CRC(pl)) res = ser.read(15) if len(res) != 0: devices.append(addr) ser.close() if len(devices): persist_info(Type.AGILENT4UHV, baud, AGILENT4UHV, 'AGILENT4UHV connected {}'.format(devices))
def power_supply_pru(): """ PRU Power Supply """ logger.debug("PRU Power Supply") ps_model_names = { 0: "Empty", 1: "FBP", 2: "FBP_DCLINK", 3: "FAC_ACDC", 4: "FAC_DCDC", 5: "FAC_2S_ACDC", 6: "FAC_2S_DCDC", 7: "FAC_2P4S_ACDC", 8: "FAC_2P4S_DCDC", 9: "FAP", 10: "FAP_4P", 11: "FAC_DCDC_EMA", 12: "FAP_2P2S_Master", 13: "FAP_2P2S_Slave", 31: "UNDEFINED", } if GPIO.input(PIN_FTDI_PRU) == PRU and GPIO.input( PIN_RS232_RS485) == RS485 and PRUserial485_address() == 21: os.system("/root/pru-serial485/src/overlay.sh") baud = 6 PRUserial485_open(baud, b"M") devices = [] ps_model = [] ps_names = [] for ps_addr in range(1, 25): PRUserial485_write( BSMPChecksum(chr(ps_addr) + "\x10\x00\x01\x00").encode("latin-1"), 100) res = PRUserial485_read() if len(res) == 7 and res[1] == 17: devices.append(ps_addr) ps_model = ps_model_names[res[5] % 32] # PS model: res[5] (bits 4..0) ps_name = getPSnames(ps_addr).replace(" ", "") if not ps_name in ps_names: ps_names.append(ps_name) name = "Power Supply" time.sleep(0.1) # Save info persist_info( Type.POWER_SUPPLY, name, 6000000, PRU_POWER_SUPPLY, "PS model {}. Connected: {}. Names: {}".format( ps_model, devices, ps_names), )
def counting_pru(): """ CountingPRU """ logger.debug("Counting PRU") if PRUserial485_address() != 21 and not os.path.exists(PORT): counters = CountingPRU_addr() os.system("/root/counting-pru/src/DTO_CountingPRU.sh") name = "Counting PRU" persist_info( Type.COUNTING_PRU, name, 0, COUNTING_PRU, "Connected: [{}]. Auto Configuration: {}".format( counters.addr(), counters.autoConfig_Available()), )
def power_supply_pru(): """ PRU Power Supply """ logger.debug('PRU Power Supply') ps_model_names = { 0: "Empty", 1: "FBP", 2: "FBP_DCLINK", 3: "FAC_ACDC", 4: "FAC_DCDC", 5: "FAC_2S_ACDC", 6: "FAC_2S_DCDC", 7: "FAC_2P4S_ACDC", 8: "FAC_2P4S_DCDC", 9: "FAP", 10: "FAP_4P", 11: "FAC_DCDC_EMA", 12: "FAP_2P2S_Master", 13: "FAP_2P2S_Slave", 31: "UNDEFINED" } if GPIO.input(PIN_FTDI_PRU) == PRU and GPIO.input( PIN_RS232_RS485) == RS485 and PRUserial485_address() == 21: os.system("/root/pru-serial485/src/overlay.sh") baud = 6 PRUserial485_open(baud, 'M') devices = [] ps_model = [] for ps_addr in range(1, 32): PRUserial485_write( [i for i in BSMPChecksum(chr(ps_addr) + "\x10\x00\x01\x00")], 100) res = PRUserial485_read() if len(res) == 7 and res[1] == "\x11": devices.append(ps_addr) ps_model = ps_model_names[ord(res[5]) % 32] # PS model: res[5] (bits 4..0) time.sleep(0.1) PRUserial485_close() persist_info(Type.POWER_SUPPLY, 6000000, PRU_POWER_SUPPLY, 'PS model {}. Connected: {}'.format(ps_model, devices))
def mbtemp(): """ MBTemp """ logger.debug('MBTemp') if GPIO.input(PIN_FTDI_PRU) == FTDI and GPIO.input( PIN_RS232_RS485) == RS485 and PRUserial485_address() == 21: baud = 115200 ser = Serial(PORT, baud, timeout=TIMEOUT) devices = [] for mbt_addr in range(1, 32): ser.write(BSMPChecksum(chr(mbt_addr) + "\x10\x00\x01\x00")) res = ser.read(10) if len(res) == 7 and res[1] == "\x11": devices.append(mbt_addr) ser.close() if len(devices): persist_info(Type.MBTEMP, baud, MBTEMP, 'MBTemps connected {}'.format(devices))
def mks9376b(): """ MKS 937B """ logger.debug('MKS 937B') if GPIO.input(PIN_FTDI_PRU) == FTDI and GPIO.input( PIN_RS232_RS485) == RS485 and PRUserial485_address() == 21: baud = 115200 ser = Serial(port=PORT, baudrate=baud, timeout=0.05) devices = [] for mks_addr in range(1, 255): msgm = '\@{0:03d}'.format(mks_addr) + "PR1?;FF" ser.reset_input_buffer() ser.reset_output_buffer() ser.write(msgm) res = ser.read(20) if len(res) != 0: devices.append(mks_addr) ser.close() if len(devices): persist_info(Type.MKS937B, baud, MKS937B, 'MKS937Bs connected {}'.format(devices))
def thermo_probe(): """ Thermo probes """ logger.debug('Thermo probes') if GPIO.input(PIN_FTDI_PRU) == FTDI and GPIO.input( PIN_RS232_RS485) == RS485 and PRUserial485_address() == 21: baud = 19200 ser = Serial(port=PORT, baudrate=baud, bytesize=SEVENBITS, parity=PARITY_EVEN, stopbits=STOPBITS_TWO, timeout=TIMEOUT) msg = thermoIncluirChecksum("\x07" + "01RM1") ser.reset_input_buffer() ser.reset_output_buffer() ser.write(msg.encode('utf-8')) res = ser.read(50) if len(res) != 0: persist_info(Type.SERIAL_THERMO, baud, SERIAL_THERMO)
def mbtemp(): """ MBTemp """ logger.info("MBTemp") if (GPIO.input(PIN_FTDI_PRU) == FTDI and GPIO.input(PIN_RS232_RS485) == RS485 and PRUserial485_address() == 21 and os.path.exists(PORT)): baud = 115200 ser = Serial(PORT, baud, timeout=TIMEOUT) devices = [] for mbt_addr in range(1, 32): ser.write( BSMPChecksum(chr(mbt_addr) + "\x10\x00\x01\x00").encode("latin-1")) res = ser.read(10).decode("latin-1") if len(res) == 7 and res[1] == "\x11": devices.append(mbt_addr) ser.close() name = "MBTemp" if len(devices): persist_info(Type.MBTEMP, name, baud, MBTEMP, "MBTemps connected {}".format(devices))
def mks9376b(): """ MKS 937B """ logger.debug("MKS 937B") if (GPIO.input(PIN_FTDI_PRU) == FTDI and GPIO.input(PIN_RS232_RS485) == RS485 and PRUserial485_address() == 21 and os.path.exists(PORT)): baud = 115200 ser = Serial(port=PORT, baudrate=baud, timeout=0.05) devices = [] for mks_addr in range(1, 255): msgm = "\@{0:03d}".format(mks_addr) + "PR1?;FF" ser.reset_input_buffer() ser.reset_output_buffer() ser.write(msgm.encode("latin-1")) res = ser.read(20).decode("latin-1") if len(res) != 0: devices.append(mks_addr) ser.close() name = "MKS" if len(devices): persist_info(Type.MKS937B, name, baud, MKS937B, "MKS937Bs connected {}".format(devices))
def reset(): """ Reset device.json content. """ persist_info(0, 0, " ", "RESET", "Searching for connected equipments.")
def spixconv(): """ SPIxCONV """ logger.info("SPIxCONV") if not SPIxCONV: return subprocess.call("config-pin P9_17 spi_cs", shell=True) # CS subprocess.call("config-pin P9_21 spi", shell=True) # DO subprocess.call("config-pin P9_18 spi", shell=True) # DI subprocess.call("config-pin P9_22 spi_sclk", shell=True) # CLK subprocess.call("config-pin P8_37 gpio", shell=True) # BUSY subprocess.call("config-pin P9_24 gpio", shell=True) # LDAC / CNVST subprocess.call("config-pin P9_26 gpio", shell=True) # RS # Should always be run (with or without flash driver), in order to discover connected boards for addr in range(0, 255): if flash.ID_read(addr) == 4: spi_addr = 8 if flash.address_read( addr) == 0 else flash.address_read(addr) # Starts checking for a flash memory find_devices = check_devices() name = '' if (find_devices.find('sda') == -1 and find_devices.find('sdb') == -1): continue #exit() else: devices = pendrive() result = devices.find('/mnt/USB') if (result == -1): mount_pendrive() pendrive_files = read_pendrive() if (pendrive_files.find('AutoConfig.xlsx') == -1 and pendrive_files.find('AutoConfig.txt') == -1): print("No files detected") if (pendrive_files.find('AutoConfig.xlsx') == -1 and pendrive_files.find('AutoConfig.txt') != -1): file = open('/mnt/USB/AutoConfig.txt') lines = file.readlines() bbb = lines[0].split("\n") name = bbb[0] logger.info( "Addr code: {}\nSelection Board ID: {}\nFlash address: {}\n Name {}\nSPI address: {}" .format( addr, selection.board_ID(addr), flash.address_read(addr), name, spi_addr, )) persist_info(Type.SPIXCONV, name, spi_addr, SPIXCONV, "SPIXCONV connected {}".format(spi_addr))
def reset(): """ Reset device.json content. """ persist_info(0, 0, 'RESET', 'Searching for connected equipments.')