def __init__(self, template, template_directory, args, timeout=5): self.timeout = timeout databank = slave_db.SlaveBase(template) # Constructor: initializes the server settings modbus.Server.__init__(self, databank if databank else modbus.Databank()) # not sure how this class remember slave configuration across instance creation, i guess there are some # well hidden away class variables somewhere. self.remove_all_slaves() self._configure_slaves(template)
def __init__(self, template, template_directory, args, timeout=5): self.timeout = timeout self.delay = None self.mode = None databank = slave_db.SlaveBase(template) # Constructor: initializes the server settings modbus.Server.__init__(self, databank if databank else modbus.Databank()) # retrieve mode of connection and turnaround delay from the template self._get_mode_and_delay(template) # not sure how this class remember slave configuration across # instance creation, i guess there are some # well hidden away class variables somewhere. self.remove_all_slaves() self._configure_slaves(template)
def __init__(self, template, log_queue, databank=slave_db.SlaveBase(), timeout=5): self.log_queue = log_queue self.timeout = timeout """Constructor: initializes the server settings""" modbus.Server.__init__(self, databank if databank else modbus.Databank()) #not sure how this class remember slave configuration across instance creation, i guess there are some #well hidden away class variables somewhere. self.remove_all_slaves() #parse slave configuration dom = etree.parse(template) slaves = dom.xpath('//conpot_template/slaves/*') template_name = dom.xpath('//conpot_template/@name')[0] for s in slaves: id = int(s.attrib['id']) slave = self.add_slave(id) logger.debug('Added slave with id {0}.'.format(id)) for b in s.xpath('./blocks/*'): name = b.attrib['name'] type = eval('mdef.' + b.xpath('./type/text()')[0]) start_addr = int(b.xpath('./starting_address/text()')[0]) size = int(b.xpath('./size/text()')[0]) slave.add_block(name, type, start_addr, size) logger.debug( 'Added block {0} to slave {1}. (type={2}, start={3}, size={4})' .format(name, id, type, start_addr, size)) for v in b.xpath('./values/*'): addr = int(v.xpath('./address/text()')[0]) value = eval(v.xpath('./content/text()')[0]) slave.set_values(name, addr, value) logger.debug('Setting value at addr {0} to {1}.'.format( addr, v.xpath('./content/text()')[0])) logger.info('Conpot modbus initialized using the {0} template.'.format( template_name))