Raspberry PI USB to RS232 adapter Receiving Only Ctrl Chars

1k views Asked by At

I'm using a USB to RS232 cable for get communication with a pure rs232 device. With pyserial lib a got this code running in loopback tx -> rx cable pins.

Setting the port:

def __init__ (self, baudrate,timeout,parity,stopbits,bytesize):
    try:
        #self.s = serial.Serial(port="'/dev/ttyUSB0'",baudrate=baudrate,timeout=timeout,parity=parity,stopbits=stopbits,bytesize=bytesize)
        #self.s = serial.Serial("/dev/ttyUSB0",9600)
        self.s=serial.Serial(
            "/dev/ttyUSB0",
            baudrate=9600,
            parity=serial.PARITY_NONE,
            stopbits=serial.STOPBITS_ONE,
            bytesize=serial.EIGHTBITS,
            writeTimeout = 0,
            timeout = 10,
            rtscts=False,
            dsrdtr=False,
            xonxoff=False)
    except:
        print ("Can't open Serial Port")
        traceback.print_exc(file=sys.stdout)

Writing and reading from it:

def write(self,data):
    if self.s.isOpen():
        try:
            self.s.write(data)      
            self.s.flush()
        except:
            traceback.print_exc(file=sys.stdout)
            print "Error on writing"
    else:
        print "Port is closed"

def read(self):
    receivedData=[]
    if self.s.isOpen():
        try:
            while self.s.inWaiting()> 0:
                receivedData.append(self.s.read(1))
            return receivedData

        except:
            traceback.print_exc(file=sys.stdout) 
            print "Error on Reading"
    else:
        print "Port is closed"
        traceback.print_exc(file=sys.stdout) 

I sent 'Carlos'.

And received ['\x03', '\x01', '\x12', '\x0c', '\x0f', '\x13']

It is hex representation of ^C^a^r^l^o^s

I need to know why it is converting chars to control chars?

2

There are 2 answers

0
Carlos Augusto Silva On BEST ANSWER

After a lot of attempts without any idea about how fix this problem, I bought new cable USB to RS232, it is based on Prolific PL2303 Chipset and it is working properly right now.

3
John La Rooy On

This is what you would expect if the sending end is using only 5 bits.

First check the settings on the sending device.
If possible, verify the bits are being send with an oscilloscope or logic analyser.
Perhaps the dongle is broken.
Maybe some part of the system has a poor power supply and the final 3 bits are not being detected properly.