3

I am trying to send this command ":01050801FF00F2" over serial in python 2.7 , with no success. The code that i use is :

import serial, sys ,socket
from time import sleep
port = "COM9"
baudRate = 9600
try:
     ser = serial.Serial(port, baudRate, timeout=1)
     if not ser.isOpen():
            ser.open()
except Exception, e:
   print("Error opening com port. Quitting."+str(e))
   sys.exit(0)
print("Opening " + ser.portstr) 

#this is few ways i am trying to send with
c = '01050801FF00F2'
ser.write(c.encode('utf-8'))
sleep(3)
ser.flushInput() #flush input buffer, discarding all its contents
ser.flushOutput()#flush output buffer, aborting current output
                 #and discard all that is in buffer
c = ':01050801FF00F2'
ser.write(c.encode('hex'))

sleep(3)
ser.write(':01050801FF00F2')
8
  • Can you please give add the error log that you are getting.Also have you tried using pyserial Commented Oct 14, 2015 at 13:47
  • i don't get an error , but the message isn't reached its destination so i assuming something is wrong with my code. (i assuming that because in other language (tcl) it's working) . what is pyserial? Commented Oct 14, 2015 at 14:25
  • oh my bad i havent look at the code properly that you are already using pyserial package of python.can you try adding this line at the end - ser.close().Also remove flushOutput because it is closing the connection Commented Oct 14, 2015 at 14:38
  • i used ser.close(). forgot to write it here Commented Oct 14, 2015 at 15:12
  • Also have you tried removing the flushOutput and flushInput lines from code? Commented Oct 15, 2015 at 4:40

2 Answers 2

1

If those are hex values, this should work:

c = '\x01\x05\x08\x01\xFF\x00\xF2'
ser.write(c)
Sign up to request clarification or add additional context in comments.

Comments

0

Have you tried sending the command using bytearray?

Perhaps you could try:

ser.write(b':01050801FF00F2')

or

ser.write(':01050801FF00F2'.encode())

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.