def unlink(self): """ close the link to the data logger """ pakbus.send(self.link, pakbus.pkt_bye_cmd(self.l_id, self.c_id)) self.link.close()
# Data logger PakBus Node Id NodeId = str2int(cf.get('pakbus', 'node_id')) # My PakBus Node Id MyNodeId = str2int(cf.get('pakbus', 'my_node_id')) # Open socket s = pakbus.open_socket(cf.get('pakbus', 'host'), cf.getint('pakbus', 'port'), cf.getint('pakbus', 'timeout')) # check if remote node is up msg = pakbus.ping_node(s, NodeId, MyNodeId) if not msg: raise Warning('no reply from PakBus node 0x%.3x' % NodeId) # # Main program # # Upload directory data FileData, Response = pakbus.fileupload(s, NodeId, MyNodeId, '.DIR') # List files in directory filedir = pakbus.parse_filedir(FileData) for file in filedir['files']: print file # say good bye pakbus.send(s, pakbus.pkt_bye_cmd(NodeId, MyNodeId)) # close socket s.close()
NodeId = str2int(cf.get('pakbus', 'node_id')) # My PakBus Node Id MyNodeId = str2int(cf.get('pakbus', 'my_node_id')) # Open socket s = pakbus.open_socket(cf.get('pakbus', 'host'), cf.getint('pakbus', 'port'), cf.getint('pakbus', 'timeout')) # check if remote node is up msg = pakbus.ping_node(s, NodeId, MyNodeId) if not msg: raise Warning('no reply from PakBus node 0x%.3x' % NodeId) # # Main program # # Upload directory data FileData, Response = pakbus.fileupload(s, NodeId, MyNodeId, '.DIR') # List files in directory filedir = pakbus.parse_filedir(FileData) for file in filedir['files']: print file # say good bye pakbus.send(s, pakbus.pkt_bye_cmd(NodeId, MyNodeId)) # close socket s.close()
# infinite loop to constantly collect data every minute while True: time.sleep(time_gap-0.865349040031) count = 0 while count < 4: data = pakbus.collect_data(s, NodeId, MyNodeId, tabledef, 'Table', CollectMode = 0x07, P1 = start_time, P2 = start_time+sample_gap) start_time += sample_gap count += 1 #always check that most recent input is 15 sec before next input print '\n' # query data start = client.now() - 2000000 print client.singleQuery(start, client.now(), BattV) ''' # say good bye for i in range(len(device_list)): if device_list[i] not in failed_nodes_list: pkt = pakbus.pkt_bye_cmd(pakbus_address_list[i], MyNodeId) pakbus.send(s, pkt) # close socket s.close()
s = pakbus.open_socket(cf.get('pakbus', 'host'), cf.getint('pakbus', 'port'), cf.getint('pakbus', 'timeout')) # check if remote node is up msg = pakbus.ping_node(s, NodeId, MyNodeId) if not msg: raise Warning('no reply from PakBus node 0x%.3x' % NodeId) # # Main program # # Get table definition structure FileData, RespCode = pakbus.fileupload(s, NodeId, MyNodeId, FileName = '.TDF') if FileData: tabledef = pakbus.parse_tabledef(FileData) for tableno in range(1, len(tabledef) + 1): print 'Table %d: %s' % (tableno, tabledef[tableno - 1]['Header']['TableName']) print 'Table signature: 0x%X' % tabledef[tableno - 1]['Signature'] print 'Header:', tabledef[tableno - 1]['Header'] for fieldno in range(1, len(tabledef[tableno - 1]['Fields']) + 1): print 'Field %d:' % (fieldno), tabledef[tableno - 1]['Fields'][fieldno - 1] print # say good bye pkt = pakbus.pkt_bye_cmd(NodeId, MyNodeId) pakbus.send(s, pkt) # close socket s.close()