2

Hello everybody and thank you for all the answers that you give me to solve this problems.

Someone said me: This code print a word that I choose in the screen, but How to send or print an ASCII character by the usb-serial port?

import serial

port =serial.Serial(
    "/dev/ttyUSB0",
    baudrate=57600,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS,
    writeTimeout = 0,
    timeout = 10,
    rtscts=False,
    dsrdtr=False,
    xonxoff=False)

data=bytes([0x0c,0x80,0x09,0x00,0xf0,0xce,0x61,0x9d,0x01,0x00,0x01,0x00,0x00,0x00]) 

print(port.isOpen()) 
print("Port opened...") 
port.write(data) 
print("Data sent")

while True:
    print("inside while")
    response=port.read(8)
    print(response)
    print ("Data Received")
    break

This code is of hsantana8

I appreciate of the help that you can give.

2

You shoule be able to send any ASCII Sequence by writing

port.write('Hello World\n')

instead of

port.write(data)

the \n is a newline character which is often used as a statement terminator. Depending on your device on the other end, you may also have to use \r\n, \r or similar.

Also see this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.