示例#1
0
    def digitalRead(self, pin):
        log.info('digitalRead {}'.format(pin))

        params = {'pin': pin}
        ret = self._sess.get(self._root + '/digitalRead',
                             params=params,
                             timeout=self._timeout)
        ret.raise_for_status()
        assert ret.text in ['0', '1'], ret.text
        return int(ret.text)
示例#2
0
    def digitalWrite(self, pin, value):
        log.info('digitalWrite {} {}'.format(pin, value))

        # HIGH, LOW
        data = {'pin': pin, 'value': value}
        ret = self._sess.post(self._root + '/digitalWrite',
                              data=data,
                              timeout=self._timeout)
        ret.raise_for_status()
        assert ret.text == 'OK', ret.text
示例#3
0
    def pinMode(self, pin, mode):
        # INPUT, INPUT_PULLUP, OUTPUT
        log.info('set pinMode {} {}'.format(pin, mode))

        data = {'pin': pin, 'mode': mode}
        ret = self._sess.post(self._root + '/pinMode',
                              data=data,
                              timeout=self._timeout)
        ret.raise_for_status()
        assert ret.text == 'OK', ret.text
示例#4
0
 def i2c_ask(self, address, message, response_len):
     hexstring = hex2str(message)  # 01FA0002
     log.info('i2c > ' + hexstring + ', wait ' + str(response_len) +
              ' bytes')
     ret = self.i2c('ask',
                    address=address,
                    hexstring=hexstring,
                    response=response_len)
     log.info('i2c < ' + ret.text)
     return str2hex(ret.text)
示例#5
0
 def delay(self, msec):
     log.info('delay {} msec'.format(msec))
     time.sleep(msec / 1000.0)
示例#6
0
 def ping(self):
     log.info('ping')
     ret = self._sess.get(self._root + '/ping', timeout=self._timeout)
     ret.raise_for_status()
     assert ret.text == 'pong'
示例#7
0
 def version(self):
     log.info('version')
     ret = self._sess.get(self._root + '/version', timeout=self._timeout)
     ret.raise_for_status()
     assert ret.text
示例#8
0
 def __init__(self, host, port=80, **kwargs):
     self._root = 'http://' + host + ':' + str(port)
     self._sess = Session()
     self._timeout = kwargs.get('timeout', 3.0)
     log.info('Testing: {}:{}'.format(host, port))