Ejemplo n.º 1
0
def test():
    """Integration testing
  """
    import ftdi_utils
    (options, args) = ftdi_utils.parse_common_args(interface=2)
    loglevel = logging.INFO
    if options.debug:
        loglevel = logging.DEBUG
    logging.basicConfig(level=loglevel,
                        format='%(asctime)s - %(name)s - ' +
                        '%(levelname)s - %(message)s')
    import ftdii2c
    i2c = ftdii2c.Fi2c(options.vendor, options.product, options.interface)
    i2c.open()
    i2c.setclock(100000)

    child = 0x40
    wbuf = [0]
    # try raw transaction to ftdii2c library reading cfg reg 0x399f
    rbuf = i2c.wr_rd(child, wbuf, 2)
    logging.info('001: i2c read of child=0x%02x reg=0x%02x == 0x%02x%02x',
                 child, wbuf[0], rbuf[0], rbuf[1])

    # same read of cfg (0x399f) using ina219 module
    adc = ina219.ina219(i2c, child, 'foo', 0.010)

    adc.calibrate()
    testit('POR  ', adc)
    adc.sleep()
    testit('SLEEP', adc)
    adc.wake()
    testit('WAKE ', adc)
Ejemplo n.º 2
0
def test():
    """Test code.

  (TODO) tbroch: enhance and make Googley & pythonic from a unittest perspective
  """
    (options, args) = ftdi_utils.parse_common_args(interface=2)

    loglevel = logging.INFO
    if options.debug:
        loglevel = logging.DEBUG
    logging.basicConfig(level=loglevel,
                        format='%(asctime)s - %(name)s - ' +
                        '%(levelname)s - %(message)s')
    fobj = Fi2c(options.vendor, options.product, options.interface)
    fobj.open()
    fobj.setclock(100000)

    wbuf = [0]
    child = 0x21
    rbuf = fobj.wr_rd(child, wbuf, 1)
    logging.info('first: i2c read of child=0x%02x reg=0x%02x == 0x%02x', child,
                 wbuf[0], rbuf[0])
    errcnt = 0
    for cnt in range(1000):
        try:
            rbuf = fobj.wr_rd(child, [], 1)
        except:
            errcnt += 1
            logging.error('errs = %d cnt = %d', errcnt, cnt)

    logging.info('last: i2c read of child=0x%02x reg=0x%02x == 0x%02x', child,
                 wbuf[0], rbuf[0])
    fobj.close()
Ejemplo n.º 3
0
def test():
  """Integration testing
  """
  import ftdi_utils
  (options, args) = ftdi_utils.parse_common_args(interface=2)
  loglevel = logging.INFO
  if options.debug:
    loglevel = logging.DEBUG
  logging.basicConfig(level=loglevel,
                      format="%(asctime)s - %(name)s - " + 
                      "%(levelname)s - %(message)s")
  import ftdii2c
  i2c = ftdii2c.Fi2c(options.vendor, options.product, options.interface)
  i2c.open()
  i2c.setclock(100000)

  slv = 0x40
  wbuf = [0]
  # try raw transaction to ftdii2c library reading cfg reg 0x399f
  rbuf = i2c.wr_rd(slv, wbuf, 2)
  logging.info("001: i2c read of slv=0x%02x reg=0x%02x == 0x%02x%02x" %
               (slv, wbuf[0], rbuf[0], rbuf[1]))

  # same read of cfg (0x399f) using ina219 module
  adc = drv.ina219.ina219(i2c, slv, 'foo', 0.010)

  adc.calibrate()
  testit("POR  ", adc)
  adc.sleep()
  testit("SLEEP", adc)
  adc.wake()
  testit("WAKE ", adc)
Ejemplo n.º 4
0
def test():
    (options, args) = ftdi_utils.parse_common_args(interface=3)

    format = '%(asctime)s - %(name)s - %(levelname)s'
    loglevel = logging.INFO
    if options.debug:
        loglevel = logging.DEBUG
        format += ' - %(filename)s:%(lineno)d:%(funcName)s'
    format += ' - %(message)s'
    logging.basicConfig(level=loglevel, format=format)
    logger = logging.getLogger(os.path.basename(sys.argv[0]))
    logger.info('Start')

    fobj = Fuart(options.vendor, options.product, options.interface)
    fobj.run()
    logging.info('%s' % fobj.get_pty())

    # run() is a thread so just busy wait to mimic server
    while True:
        # ours sleeps to eleven!
        time.sleep(11)
Ejemplo n.º 5
0
def test():
  """Test code.

  (TODO) tbroch: enhance and make Googley & pythonic from a unittest
  perspective.
  """
  (options, args) = ftdi_utils.parse_common_args()
  loglevel = logging.INFO
  if options.debug:
    loglevel = logging.DEBUG
  logging.basicConfig(
      level=loglevel,
      format='%(asctime)s - %(name)s - ' + '%(levelname)s - %(message)s')
  for i in range(1, 5):
    fobj = Fgpio(options.vendor, options.product, i)
    fobj.open()
    rd_val = fobj.wr_rd(6, 1, 0)
    logging.debug('rd_val = %d after <6> -> 0', (rd_val))
    if rd_val != 0:
      logging.error('rd_val = %d != 0', (rd_val))

    rd_val = fobj.wr_rd(6, 1, 1)
    logging.debug('rd_val = %d after <6> -> 1', (rd_val))
    if rd_val != 1:
      logging.error('rd_val = %d != 1', (rd_val))

    rd_val = fobj.wr_rd(6, 1, 0)
    logging.debug('rd_val = %d after <6> -> 0', (rd_val))
    if rd_val != 0:
      logging.error('rd_val = %d != 0', (rd_val))

    # release as output
    rd_val = fobj.wr_rd(6, 0, 0)
    logging.debug('rd_val = %d after <6> dir released', (rd_val))
    logging.info('rd_val = %d should match pu/pd', (rd_val))
    fobj.close()