Esempio n. 1
0
def main(args):
    readConfig(vars(args))
    if args.debug:
        level = logging.DEBUG
    else:
        level = logging.INFO

    logstream = sys.stderr
    try:
        if args.logMain:
            logstream = open(args.logMain, 'w')
    except:
        pass

    logging.basicConfig(level=level, stream=logstream)
    logging.debug(args)

    ser = rs485.RS485(args.port, args.baudrate, timeout=0.2, writeTimeout=0.2)
    bus = Bus(ser)

    script = None
    try:
        if args.script:
            script = open(args.script)
    except Exception as e:
        logging.warning("Unable to open script file (%s)" % str(e))
    master = Master(bus, script)
    master.loop()
    return 0
Esempio n. 2
0
def main(args):
  if args.debug:
    level = logging.DEBUG
  else:
    level = logging.INFO
  logging.basicConfig(level = level)
  logging.debug(args)

  ser = rs485.RS485(args.port, args.baudrate, timeout = 0.2, writeTimeout = 0.24)
  crc = CRC(8, CRC_POLYNOMIAL, CRC_INITIAL)
  bus = Bus(ser, crc)

  if args.echo:
      logging.info("Echo...")
      for i in range(args.repeat):
          if args.node: addrlist = [args.node]
          else: addrlist = bus.getAddresses()
          for addr in addrlist:
            success = bus.echo(addr)
            if success == None:
                logging.error("Unknown Node")
                sys.exit(1)
            if success:
                logging.info("%s: SUCCESS" % addr)
            else:
                logging.warning("%s: FAILED" % addr)
            time.sleep(0.1)

  if args.get:
      logging.info("Getting parameter %d" % args.get)
      for i in range(args.repeat):
          params = bus.getParameter(args.node, args.get)
          if params == None:
              logging.error("No response")
          else:
              logging.info("Got %s" % prettyFormat(params, "hex"))
          time.sleep(0.1)

  if args.set:
      paramsIn = [int(x) for x in args.values.split(',')]
      logging.info("Setting parameter %d" % args.set)
      for i in range(args.repeat):
          params = bus.getParameter(args.node, args.set, bytearray(paramsIn))
          if params == None:
              logging.error("No response")
          else:
              logging.info("Got %s" % prettyFormat(params, "hex"))
          time.sleep(0.1)
          
  if args.reboot:
      logging.info("Rebooting...")
      bus.reboot(args.node)
Esempio n. 3
0
def main(args):
    rpi = RPi()

    if args.reset:
        rpi.resetNetwork()

    while True:
        for cmd in args.command:
            if cmd == 'reset':
                rpi.resetNetwork()
            if cmd == 'wait':
                pause()
            if cmd == 'pause':
                time.sleep(1)
            if cmd == 'open':
                print "opening door"
                rpi.setDoors(True)
            if cmd == 'close':
                print "closing door"
                rpi.setDoors(False)
            if cmd == 'snake':
                rpi.setSnake(True)
            if cmd == 'uart':
                ser = rs485.RS485(args.port,
                                  args.baudrate,
                                  timeout=0.2,
                                  writeTimeout=0.2)
                while True:
                    ser.write([0xAA])
                    time.sleep(0.020)
            time.sleep(1)

        if not args.loop:
            break

    return
Esempio n. 4
0
################################################################################
# Modbus communications via serial line.
#
# Created: 2019-03-21
# Author: L. Marsicano
################################################################################

import rs485
from modbus import modbus
import streams

try:
    device = rs485.RS485(100000)
    # Wait for the serial port to open. This may not be necessary
    sleep(10000)
    master = modbus.ModbusSerial(1, serial_device=device)

    result = master.write_register(5, 745)
    print("Written discrete register: ", result)

    result = master.write_multiple_registers(2, 4, [55, 555, 123, 42])
    print("Written ", result, " registers")

    discrete = master.read_discrete(2, 4)
    print("Discrete inputs values: ", discrete)

    holding = master.read_holding(3, 2)
    print("Holding registers values: ", holding)

    master.close()
    print("Closed.")
Esempio n. 5
0
                    metavar='NEWPASSWORD')
parser.add_argument('-d',
                    '--debug',
                    help='Debug',
                    action='store_true',
                    default=False)

args = parser.parse_args(sys.argv[1:])
readConfig(vars(args))

if args.debug: level = logging.DEBUG
else: level = logging.INFO
logging.basicConfig(level=level)

#ser = serial.Serial(args.DEV, args.baudrate, timeout = 0.5, write_timeout = 0.5, rtscts = False)
ser = rs485.RS485(args.port, args.baudrate, timeout=0.5, writeTimeout=0.5)
tsb = TSB(ser)

if args.connect != None:
    bus = Bus(ser)

    if args.read or args.write:
        logging.info("Rebooting...")
        bus.reboot(args.connect)
        time.sleep(0.25)

    logging.info("Connecting...")
    if not tsb.connect(args.connect):
        logging.error("Connect failed")
        sys.exit(1)
    else: