loglevel = logging.INFO fh = logging.FileHandler(filename=LOGFILE, mode='w') fh.setLevel(logging.DEBUG) # All log messages go to the log file sh = logging.StreamHandler() sh.setLevel(loglevel) # Some or all log messages go to the console # noinspection PyArgumentList logging.basicConfig(handlers=[fh, sh], level=logging.DEBUG, format='%(levelname)s:%(name)s %(created)14.3f - %(message)s') from pasd import transport from pasd import smartbox tlogger = logging.getLogger('T') conn = transport.Connection(hostname=None, devicename='COM5', multidrop=False, logger=tlogger, baudrate=19200) slogger = logging.getLogger('SB:%d' % 1) s = smartbox.SMARTbox(conn=conn, modbus_address=1, logger=slogger) print('Polling SMARTbox as "s" on address %d.' % 1) s.poll_data() # print('Configuring SMARTbox as "s" on address %d.' % 1) # s.configure() # s.poll_data() # print(s) # System registers # # CRC registers. CRC32 is computed for all registers from ADDRESS to COMMAND, or 10003 - 10125. # If a command does not write to all registers the CRC is still calculated as if all the registers are initialised with 0 # The CRC is calculated lower byte then upper byte
time.sleep(0.05) tries += 1 sock.close() if sentbytes < msize: print( "Tried %d times, but sent only %d bytes out of %d to Carbon" % (tries, sentbytes, msize)) except: print("Exception in socket transfer to Carbon on port 2004") traceback.print_exc() if __name__ == '__main__': tlogger = logging.getLogger('T') tlogger.setLevel(logging.INFO) conn = transport.Connection(hostname=HOSTNAME, port=5000, logger=tlogger) flogger = logging.getLogger('FNDH:%d' % FNDH_ADDRESS) f = fndh.FNDH(conn=conn, modbus_address=FNDH_ADDRESS, logger=flogger) print('Polling FNDH as "f" on address %d.' % FNDH_ADDRESS) f.poll_data() print('Configuring all-off on FNDH as "f" on address %d.' % FNDH_ADDRESS) f.configure_all_off() print('Final configuring FNDH as "f" on address %d.' % FNDH_ADDRESS) f.configure_final() f.poll_data() for sadd in SMARTBOX_ADDRESSES: slogger = logging.getLogger('SB:%d' % sadd) s = smartbox.SMARTbox(conn=conn, modbus_address=sadd, logger=slogger) print('Polling SMARTbox as "s" on address %d.' % sadd)
level=logging.DEBUG, format='%(levelname)s:%(name)s %(created)14.3f - %(message)s') from pasd import transport from pasd import station tlogger = logging.getLogger('T') if loglevel == logging.DEBUG: print( 'Setting transport log level to info, DEBUG is very spammy. All other logging is at DEBUG level.' ) tlogger.setLevel(logging.INFO) while True: conn = transport.Connection(hostname=args.host, multidrop=False, logger=tlogger) slogger = logging.getLogger('ST') s = station.Station(conn=conn, station_id=1, do_full_startup=False, logger=slogger) print( 'Starting up entire station as "s" - FNDH on address 101, SMARTboxes on addresses 1-24.' ) s.fieldtest_startup() s.poll_data() result = main_loop(s, toggleports=args.toggle)
logging.basicConfig( handlers=[fh, sh], level=logging.DEBUG, format='%(levelname)s:%(name)s %(created)14.3f - %(message)s') from pasd import transport from pasd import fndh from pasd import fncc from pasd import smartbox from pasd import station from sid import mccs tlogger = logging.getLogger('T') conn = transport.Connection(hostname=args.host, devicename=args.device, port=int(args.portnum), baudrate=19200, multidrop=False, logger=tlogger) if args.task.upper() == 'SMARTBOX': if args.address is None: args.address = 1 slogger = logging.getLogger('SB:%d' % int(args.address)) s = smartbox.SMARTbox(conn=conn, modbus_address=int(args.address), logger=slogger) print('Polling SMARTbox as "s" on address %d.' % int(args.address)) s.poll_data() print('Configuring SMARTbox as "s" on address %d.' % int(args.address)) s.configure() s.poll_data()