Beispiel #1
0
    def receieve_packet(self):
        """
        Receieve packe from CFA635 serial interface.
        Parse it into the appropriate structure
        """
        output = Packet()
        while output.retry_count < 15 and output.cmd == None:
            output.cmd = self.serial.read(1)
            time.sleep(0.02)
            output.increment_retry()

        if output.cmd == None or output.cmd == "":
            output.set_error("Unable to receive message type part")
            return output

        output.len = ord(self.serial.read(1))
        if output.len == None or output.len == "":
            output.set_error("Unable to receive message length part")
            return output

        output.data = self.serial.read(output.len)
        if output.len != len(output.data):
            output.set_error("Length doens't match data")
            return output

        output.crc = self.serial.read(2)

        if output.crc == None or len(output.crc) < 2:
            output.set_error("Didn't get entire CRC")

        return output
Beispiel #2
0
    def receieve_packet (self):
        """
        Receieve packe from CFA635 serial interface.
        Parse it into the appropriate structure
        """
        output = Packet()
        while output.retry_count < 15 and output.cmd == None:
            output.cmd = self.serial.read(1)
            time.sleep(0.02)
            output.increment_retry()

        if output.cmd == None or output.cmd == "" :
            output.set_error("Unable to receive message type part")
            return output

        output.len = ord(self.serial.read(1))
        if output.len == None  or output.len == ""  :
            output.set_error("Unable to receive message length part")
            return output

        output.data = self.serial.read( output.len )
        if output.len != len(output.data):
            output.set_error("Length doens't match data")
            return output

        output.crc = self.serial.read(2)

        if output.crc == None or len(output.crc) < 2    :
            output.set_error("Didn't get entire CRC")

        return output
Beispiel #3
0
 def clear_screen(self):
     """ #6 (0x06): Clear LCD Screen
     """
     packet = Packet()
     packet.cmd = "\x06"
     packet.len = 0
     self.dev.send_packet(packet)
Beispiel #4
0
 def ping(self, payload):
     """ #0 (0x00): Ping Command
     """
     packet = Packet()
     packet.cmd = "\x00"
     if payload == None:
         packet.len = 0
     else:
         packet.len = len(payload)
         packet.data = payload
     reply = self.dev.send_packet(packet)
     if reply.len != packet.len:
         raise Exception("Packet lengths don't match")
     if reply.len > 0:
         if reply.data != packet.data:
             raise Exception("Packet payload dosn't match")
Beispiel #5
0
 def reboot(self):
     """ #5 (0x05): Reboot XES635BK-xxx-KU
     """
     packet = Packet()
     packet.cmd = "\x05"
     packet.len = 3
     packet.data = (chr(8) + chr(18) + chr(99))
     self.dev.send_packet(packet)
Beispiel #6
0
 def get_firmware_version(self):
     """ #1 (0x01): Get Hardware & Firmware Version
     """
     packet = Packet()
     packet.cmd = "\x01"
     packet.len = 0
     reply = self.dev.send_packet(packet)
     return reply.data
Beispiel #7
0
 def set_cursor_position(self, col, row):
     """ #11 (0x0B): Set LCD Cursor Position
     """
     packet = Packet()
     packet.cmd = "\x0B"
     packet.len = 2
     packet.data = (chr(col) + chr(row))
     self.dev.send_packet(packet)
Beispiel #8
0
 def read_keypad(self):
     """ #24 (0x18): Read Keypad, Polled Mode
     """
     packet = Packet()
     packet.cmd = "\x18"
     packet.len = 0
     reply = self.dev.send_packet(packet)
     return (reply.data[0], reply.data[1], reply.data[2])
Beispiel #9
0
 def set_key_reporting (self, press, release):
     """ #23 (0x17): Configure Key Reporting
     """
     packet = Packet()
     packet.cmd = "\x17"
     packet.len = 2
     packet.data = chr(press) + chr(release)
     self.dev.send_packet(packet)
Beispiel #10
0
 def set_contrast(self, contrast):
     """ #13 (0x0D): Set LCD Contrast
     """
     packet = Packet()
     packet.cmd = "\x0D"
     packet.len = 1
     packet.data = chr(contrast)
     self.dev.send_packet(packet)
Beispiel #11
0
 def set_cursor_style(self, style):
     """ #12 (0x0C): Set LCD Cursor Style
     """
     packet = Packet()
     packet.cmd = "\x0C"
     packet.len = 1
     packet.data = chr(style)
     self.dev.send_packet(packet)
Beispiel #12
0
 def get_cg_data(self, index):
     """ #10 (0x0A): Read 8 Bytes of LCD Memory
     """
     packet = Packet()
     packet.cmd = "\x0A"
     packet.len = 1
     packet.data = chr(index)
     reply = self.dev.send_packet(packet)
     return (reply.data[0], reply.data[1:9])
Beispiel #13
0
 def set_gpio(self, pin, value):
     """
     #34 (0x22): Set GPO Pin
     """
     packet = Packet()
     packet.cmd = "\x22"
     packet.len = 2
     packet.data = chr(pin) + chr(value)
     self.dev.send_packet(packet)
Beispiel #14
0
 def set_backlight(self, backlight):
     """ #14 (0x0E): Set LCD & Keypad Backlight
     """
     packet = Packet()
     packet.cmd = "\x0E"
     packet.len = 1
     packet.data = chr(backlight)
     self.backlight_current = backlight
     self.dev.send_packet(packet)
Beispiel #15
0
 def write_user_flash(self, data):
     """ #2 (0x02): Write User Flash Area
     """
     packet = Packet()
     packet.cmd = "\x02"
     packet.data = data
     packet.len = len(data)
     if packet.len != 16:
         raise Exception("Flash Write must be exacty 16 bytes")
     self.dev.send_packet(packet)
Beispiel #16
0
    def set_cg_data(self, index, data):
        """ #9 (0x09): Set LCD Special Character Data
        """
        if len(data) != 8:
            raise Exception("Data should be 8 bytes")

        packet = Packet()
        packet.cmd = "\x09"
        packet.len = 9
        packet.data = (chr(index) + data)
        self.dev.send_packet(packet)
Beispiel #17
0
 def set_text( self, row, col, text):
     """
     #31 (0x1F): Send Data to LCD
     """
     if len(text) > ( 21 - col):
         raise Exception("Text runs over end.")
     packet = Packet()
     packet.cmd = "\x1F"
     packet.data = chr(col) + chr(row)
     packet.data += text
     packet.len = len(packet.data)
     self.dev.send_packet(packet)