ISP.py 935 B

123456789101112131415161718192021222324252627282930313233
  1. import serial
  2. import time,sys
  3. import array
  4. SERIAL_PORT = '/dev/ttyUSB0'
  5. ser = serial.Serial(SERIAL_PORT, baudrate = 115200 , timeout = 1)
  6. arr=[]
  7. j=0
  8. i=0
  9. commandarray = [0x7F]
  10. print(commandarray)
  11. ser.write(array.array('B', commandarray).tostring())
  12. rcv = ser.read(1)
  13. print (hex(ord(rcv)))
  14. if (rcv =='y'):
  15. commandarray = [0x31,0xCE]
  16. print(commandarray)
  17. ser.write(array.array('B', commandarray).tostring())
  18. rcv = ser.read(1)
  19. print (hex(ord(rcv)))
  20. if (rcv =='y'):
  21. commandarray = [0x08,0x00,0x00,0x00,0x08]
  22. print(commandarray)
  23. ser.write(array.array('B', commandarray).tostring())
  24. rcv = ser.read(1)
  25. print (hex(ord(rcv)))
  26. if (rcv =='y'):
  27. commandarray = [0x03,0x01,0x02,0x02,0x04,(0x02^0x04)]
  28. print(commandarray)
  29. ser.write(array.array('B', commandarray).tostring())
  30. rcv = ser.read(1)
  31. print (hex(ord(rcv)))