def test_read_word_data(self):
     bytes = [1 << 6, 1 << 7]
     word = bytes[1] << 8 | bytes[0]
     cmd = 27
     self.serial.write(int2byte(bytes[0]) + int2byte(bytes[1]))
     time.sleep(DELAY)
     worddata = self.bus.read_word_data(ADDR, cmd)
     assert word == worddata
     data = self.getdata()
     testcase, cmd2, worddata2 = data.split(b"#")
     assert int(testcase) == READ_WORD_DATA
     assert cmd == int(cmd2)
     worddata2 = [byte2int(i) for i in worddata2]
     assert word == worddata2[1] << 8 | worddata2[0]
 def test_read_word_data(self):
     bytes = [1 << 6, 1 << 7]
     word = bytes[1] << 8 | bytes[0]
     cmd = 27
     self.serial.write(int2byte(bytes[0]) + int2byte(bytes[1]))
     time.sleep(DELAY)
     worddata = self.bus.read_word_data(ADDR, cmd)
     assert word == worddata
     data = self.getdata()
     testcase, cmd2, worddata2 = data.split(b"#")
     assert int(testcase) == READ_WORD_DATA
     assert cmd == int(cmd2)
     worddata2 = [byte2int(i) for i in worddata2]
     assert word == worddata2[1] << 8 | worddata2[0]
 def test_read_byte2(self):
     self.serial.write(int2byte(20))
     time.sleep(DELAY)
     byte = self.bus.read_byte(ADDR)
     'read ', byte
     data = int(self.getdata())
     assert data == READ_BYTE
     assert byte == 20
 def test_read_byte2(self):
     self.serial.write(int2byte(20))
     time.sleep(DELAY)
     byte = self.bus.read_byte(ADDR)
     'read ', byte
     data = int(self.getdata())
     assert data == READ_BYTE
     assert byte == 20
 def setup_method(self, meth):
     if not i2c_features[meth.testcase]:
         pytest.mark.skip("smbus feature not supported")
     self.bus = SMBus(BUS)
     self.serial = Serial(PORT, 9600)
     self.serial.write(RESET)
     time.sleep(DELAY)
     self.serial.write(int2byte(meth.testcase))
     time.sleep(DELAY)
 def setup_method(self, meth):
     if not i2c_features[meth.testcase]:
         py.test.skip("smbus feature not supported")
     self.bus = SMBus(BUS)
     self.serial = Serial(PORT, 9600)
     self.serial.write(RESET)
     time.sleep(DELAY)
     self.serial.write(int2byte(meth.testcase))
     time.sleep(DELAY)
if PY3K:

    def byte2int(x):
        return x
else:

    def byte2int(x):
        return ord(x)


PORT = '/dev/ttyACM0'
ADDR = 0x04
BUS = 1

# Commands
GETDATA = int2byte(254)
RESET = int2byte(255)

# Testcases
WRITE_QUICK = 1
READ_BYTE = 2
WRITE_BYTE = 3
READ_BYTE_DATA = 4
WRITE_BYTE_DATA = 5
READ_WORD_DATA = 6
WRITE_WORD_DATA = 7
PROCESS_CALL = 8
READ_BLOCK_DATA = 9
WRITE_BLOCK_DATA = 10
BLOCK_PROCESS_CALL = 11
READ_I2C_BLOCK_DATA = 12
import py

if PY3K:
    def byte2int(x):
        return x
else:
    def byte2int(x):
        return ord(x)


PORT = '/dev/ttyACM0'
ADDR = 0x04
BUS = 1

# Commands
GETDATA = int2byte(254)
RESET = int2byte(255)

# Testcases
WRITE_QUICK = 1
READ_BYTE = 2
WRITE_BYTE = 3
READ_BYTE_DATA = 4
WRITE_BYTE_DATA = 5
READ_WORD_DATA = 6
WRITE_WORD_DATA = 7
PROCESS_CALL = 8
READ_BLOCK_DATA = 9
WRITE_BLOCK_DATA = 10
BLOCK_PROCESS_CALL = 11
READ_I2C_BLOCK_DATA = 12