Python: Read data via serial port from Velleman k8090 [solved] -


i have velleman k8090 relay board trying read data. can write board fine, whenever output read data, strange characters diamond or upside-down question mark. here part of code:

import serial com_port = 'com4' class velleman8090:     def __init__(self, port=com_port):         self.port = port         self.baud_rate = 19200         self.data_bits = 8         self.parity = 'n'         self.stop_bits = 1         self.flow_control = 'n'      def open_device(self):         self.talk = serial.serial(self.port, self.baud_rate, self.data_bits, self.parity, self.stop_bits)      def firmware_version(self):         data = packet(0x71, 0x00, 0x00, 0x00)         self.talk.write(data)         print self.talk.read()      def close_device(self):         self.talk.close()  def chksum(cmd,msk,p1,p2):     return (((~(0x04 + cmd + msk + p1 + p2)) + 0x01) & 0xff)  def packet(cmd,msk,p1,p2):     return str(bytearray([0x04, cmd, msk, p1, p2, chksum(cmd, msk, p1, p2), 0x0f]))  def main():     vm8090 = velleman8090()     vm8090.open_device()             vm8090.firmware_version()     vm8090.close_device() 

why getting these strange characters? documentation states should return year , week.

edit: after searching , troubleshooting, pretty sure has python code or data types , not hardware. this forum contains example in c reads board. got example read board sure has python code , not hardware itself.

after effort, found issue. python encoding issue. output data being encoded strange characters getting. 1 line of code needed output expecting:

 output = self.talk.read(7)  output = output.encode('hex')  #converts strange characters hex  print output 

hopefully others in future.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -