def readPCF8574_OUT_INV(config): logger.debug('--------------------') logger.debug('Now reading DigitalOut invers') address = int(config["address"],16) busnumber = int(config["bus"]) logger.debug('Busnumber: %s', busnumber) logger.debug('Address: %s', address) bus = smbus.SMBus(busnumber) state = bus.read_byte(address); logger.debug('State dez: %s', state) logger.debug('State bin: %s', bin(state)) for i in range(0,8): port = "in" + str(i) + "-" in_active = config[port + "active"] if in_active == "1": in_name = config[port + "name"] value = 1&(state>>(7-i)) value = 0 if value==1 else 1 try: givenvalue=int(config[port + "givenvalue"]) except: givenvalue=value if value != givenvalue: value = writePCF8574_OUT_INV(config,i,givenvalue) time.sleep(0.1) storagehandler.save("boat." + in_name,value)
def readPCF8574_OUT_INV(config): logger.debug('--------------------') logger.debug('Now reading DigitalOut invers') address = int(config["address"], 16) busnumber = int(config["bus"]) logger.debug('Busnumber: %s', busnumber) logger.debug('Address: %s', address) bus = smbus.SMBus(busnumber) state = bus.read_byte(address) logger.debug('State dez: %s', state) logger.debug('State bin: %s', bin(state)) for i in range(0, 8): port = "in" + str(i) + "-" in_active = config[port + "active"] if in_active == "1": in_name = config[port + "name"] value = 1 & (state >> (7 - i)) value = 0 if value == 1 else 1 try: givenvalue = int(config[port + "givenvalue"]) except: givenvalue = value if value != givenvalue: value = writePCF8574_OUT_INV(config, i, givenvalue) time.sleep(0.1) storagehandler.save("boat." + in_name, value)
def readPCF8574_IN(config): logger.debug('--------------------') logger.debug('Now reading DigitalIn') address = int(config["address"],16) busnumber = int(config["bus"]) bus = smbus.SMBus(busnumber) state = bus.read_byte(address) for i in range(0,8): port = "in" + str(i) + "-" in_active = config[port + "active"] if in_active == "1": in_name = config[port + "name"] value = 1&(state>>i) storagehandler.save("boat." + in_name,value)
def readPCF8574_IN(config): logger.debug('--------------------') logger.debug('Now reading DigitalIn') address = int(config["address"], 16) busnumber = int(config["bus"]) bus = smbus.SMBus(busnumber) state = bus.read_byte(address) for i in range(0, 8): port = "in" + str(i) + "-" in_active = config[port + "active"] if in_active == "1": in_name = config[port + "name"] value = 1 & (state >> i) storagehandler.save("boat." + in_name, value)
def readPCF8574_OUT(config): logger.debug('--------------------') logger.debug('Now reading DigitalOut') address = int(config["address"],16) busnumber = int(config["bus"]) logger.debug('Busnumber: %s', busnumber) logger.debug('Address: %s', address) bus = smbus.SMBus(busnumber) state = bus.read_byte(address); logger.debug('State: %s', state) for i in range(0,8): port = "in" + str(i) + "-" in_active = config[port + "active"] if in_active == "1": in_name = config[port + "name"] value = 1&(state>>7-i) logger.debug('In_Name: %s', in_name) logger.debug('Value: %s', value) storagehandler.save("boat." + in_name,value)
def readPCF8574_OUT(config): logger.debug('--------------------') logger.debug('Now reading DigitalOut') address = int(config["address"], 16) busnumber = int(config["bus"]) logger.debug('Busnumber: %s', busnumber) logger.debug('Address: %s', address) bus = smbus.SMBus(busnumber) state = bus.read_byte(address) logger.debug('State: %s', state) for i in range(0, 8): port = "in" + str(i) + "-" in_active = config[port + "active"] if in_active == "1": in_name = config[port + "name"] value = 1 & (state >> 7 - i) logger.debug('In_Name: %s', in_name) logger.debug('Value: %s', value) storagehandler.save("boat." + in_name, value)
def readLM75(config): logger.debug('--------------------') logger.debug('Now reading LM75') address = int(config["address"],16) busnumber = int(config["bus"]) name = config["name"] bus = smbus.SMBus(busnumber) logger.debug('Busnumber: %s', busnumber) logger.debug('Address: %s', address) logger.debug('Name: %s', name) raw_temp = bus.read_word_data(address, 0) logger.debug('Raw Temp: %s', raw_temp) vorkomma = raw_temp & 0xFF nachkomma = raw_temp >> 15 temp = 0 if (vorkomma & 0x80) != 0x80: temp = vorkomma + nachkomma * 0.5 else: vorkomma = -((~vorkomma & 0xFF) + 1) temp = vorkomma + nachkomma * 0.5 logger.debug('Temperatur: %s', temp) storagehandler.save("boat." + name,temp)
def readPCF8591(config): address = int(config["address"],16) busnumber = int(config["bus"]) bus = smbus.SMBus(busnumber) logger.debug('Now reading HorterAnalogIn') logger.debug('Busnumber: ') logger.debug('Address: ') for i in range(0,4): port = "in"+str(i) + "-" in_active = config[port + "active"] if in_active == "1": in_factor = float(config[port + "factor"]) in_name = config[port + "name"] value = int("0x0" + str(i),16) bus.write_byte(address,value) time.sleep(0.2) bus.read_byte(address) time.sleep(0.2) voltage_raw = bus.read_byte(address) voltage = round(voltage_raw * in_factor,2) storagehandler.save("boat." + in_name,voltage)
def readLM75(config): logger.debug('--------------------') logger.debug('Now reading LM75') address = int(config["address"], 16) busnumber = int(config["bus"]) name = config["name"] bus = smbus.SMBus(busnumber) logger.debug('Busnumber: %s', busnumber) logger.debug('Address: %s', address) logger.debug('Name: %s', name) raw_temp = bus.read_word_data(address, 0) logger.debug('Raw Temp: %s', raw_temp) vorkomma = raw_temp & 0xFF nachkomma = raw_temp >> 15 temp = 0 if (vorkomma & 0x80) != 0x80: temp = vorkomma + nachkomma * 0.5 else: vorkomma = -((~vorkomma & 0xFF) + 1) temp = vorkomma + nachkomma * 0.5 logger.debug('Temperatur: %s', temp) storagehandler.save("boat." + name, temp)
def readPCF8591(config): address = int(config["address"], 16) busnumber = int(config["bus"]) bus = smbus.SMBus(busnumber) logger.debug('Now reading HorterAnalogIn') logger.debug('Busnumber: ') logger.debug('Address: ') for i in range(0, 4): port = "in" + str(i) + "-" in_active = config[port + "active"] if in_active == "1": in_factor = float(config[port + "factor"]) in_name = config[port + "name"] value = int("0x0" + str(i), 16) bus.write_byte(address, value) time.sleep(0.2) bus.read_byte(address) time.sleep(0.2) voltage_raw = bus.read_byte(address) voltage = round(voltage_raw * in_factor, 2) storagehandler.save("boat." + in_name, voltage)
def readHORTER_PIC18F13K22_AD(config): address = int(config["address"], 16) busnumber = int(config["bus"]) bus = smbus.SMBus(busnumber) data = bus.read_i2c_block_data(address, 0, 11) pointer = data[0] raw0 = data[1] + data[2] * 256 raw1 = data[3] + data[4] * 256 raw2 = data[5] + data[6] * 256 raw3 = data[7] + data[8] * 256 raw4 = data[9] + data[10] * 256 if config["in0-active"] == "1": in_factor = float(config["in0-factor"]) in_name = config["in0-name"] voltage = round(raw0 * in_factor, 2) storagehandler.save("boat." + in_name, voltage) if config["in1-active"] == "1": in_factor = float(config["in1-factor"]) in_name = config["in1-name"] voltage = round(raw1 * in_factor, 2) storagehandler.save("boat." + in_name, voltage) if config["in2-active"] == "1": in_factor = float(config["in2-factor"]) in_name = config["in2-name"] voltage = round(raw2 * in_factor, 2) storagehandler.save("boat." + in_name, voltage) if config["in3-active"] == "1": in_factor = float(config["in3-factor"]) in_name = config["in3-name"] voltage = round(raw3 * in_factor, 2) storagehandler.save("boat." + in_name, voltage) if config["in4-active"] == "1": in_factor = float(config["in4-factor"]) in_name = config["in4-name"] voltage = round(raw4 * in_factor, 2) storagehandler.save("boat." + in_name, voltage)