Udo
Posts: 2
Joined: Mon Aug 06, 2012 1:39 pm

USB to Serial

Mon Aug 06, 2012 1:52 pm

I have conncet a Digitus (DA-70156) USB to Serial converter to my Raspberry PI and trying to read serial data from my Solar Power Converter (DC-AC).

All looks ok so far (like on my currently used Ubuntu PC) but I can't see any incoming data.

The Converter is properly detected:

Code: Select all

...
usbcore: registered new interface driver usbserial
USB Serial support registered for generic
usbcore: registered new interface driver usbserial_generic
usbserial: USB Serial Driver core
USB Serial support registered for FTDI USB Serial Device
ftdi_sio 1-1.3:1.0: FTDI USB Serial Device converter detected
usb 1-1.3: Detected FT232RL
usb 1-1.3: Number of endpoints 2
usb 1-1.3: Endpoint 1 MaxPacketSize 64
usb 1-1.3: Endpoint 2 MaxPacketSize 64
usb 1-1.3: Setting MaxPacketSize 64
usb 1-1.3: FTDI USB Serial Device converter now attached to ttyUSB0
usbcore: registered new interface driver ftdi_sio
ftdi_sio: v1.6.0:USB FTDI Serial Converters Driver
...
The small python testprogram:

Code: Select all

#!/usr/bin/python
# -*- coding: utf-8 -*-

import serial
import time
true = 1

while true:
        ser = serial.Serial('/dev/ttyUSB0', 9600)
        line = ser.read(66)
        print line
        time.sleep(59)
        ser.close()
The "miniterm" provided by the pyserial package is also not able to display any data coming from the Power converter.

What I'm doing wrong?

User avatar
prakis
Posts: 19
Joined: Mon Aug 20, 2012 4:49 pm
Location: Ann Arbor

Re: USB to Serial

Mon Aug 20, 2012 4:55 pm

Were you able to find the cause for your problem ?
I am struggling with the same issue.
USB to serial port is recognized, (For others if you want to know how to register the USB-to-Serial http://forums.reprap.org/read.php?12,4546 ) and got the ttyUSB0.

Can open the port but can't read anything...

ser.read(1) is dead...

Let us know if you had fixed your problem.

Thanks,
-Kri

Udo
Posts: 2
Joined: Mon Aug 06, 2012 1:39 pm

Re: USB to Serial

Mon Aug 20, 2012 6:11 pm

Hey Kri,
well this took me really long, but I found a solution for me.
The main issue was the configuration of the port - after I added the parameter (rtscts=1) I made some progress. I got this from another forum which was talking about a similar issue on a Ubuntu PC. Not 100% sure if the parameter "timeout=0" is really required.

Here is my small programm that reads all input coming into the serial port from my power converter:

Code: Select all

#!/usr/bin/python
# -*- coding: utf-8 -*-
import serial
from time import sleep

ser = serial.Serial('/dev/ttyUSB1', 9600, rtscts=1, timeout=0)
while True:
        line = ser.read(ser.inWaiting())
        if len(line) > 0:
                        print line
        sleep(9)
ser.close()
The value for the sleep() function can be much smaller! In my case the power converter sents every 10 sec. one line of data.

Hope this help,
Udo

User avatar
prakis
Posts: 19
Joined: Mon Aug 20, 2012 4:49 pm
Location: Ann Arbor

Re: USB to Serial

Mon Aug 20, 2012 7:16 pm

Hi Udo,

Thanks for the quick reply.

I tried your code (serial.inWaiting() ) which didn't work either. I am using a different USB to serial port Adapter. I am planning to buy the one you are using ( Digitus DA-70156) and try it. I am using the StartTech.com USB-to-Serial port which is not able to read anything from the serial port.

Thank you,
-Kri

flobro
Posts: 1
Joined: Fri Aug 31, 2012 1:36 pm

Re: USB to Serial

Fri Aug 31, 2012 4:48 pm

It may be the driver.

It appears that data is being sent but not received, almost like the UART is not fully initialized
If you momentarily turn on rtscts then off, it appears to work normally (at least for me)

port.rtscts = 1
time.sleep(.5)
port.rtscts = 0


I have seen this on a MIPS Linux platform I have worked with before.

flobro

Tripel Hop
Posts: 10
Joined: Wed Jun 27, 2012 12:12 am

Re: USB to Serial

Sat Sep 01, 2012 11:32 am

Maybe this observation may help as a reference: the ftdi_sio driver doesn't set the baudrate (other than 9600) properly after replugging the USB device (with ft232 chip) because it didn't see the replug. As a result writing data works but reading won't because of the wrong baudrate even when your program sets the correct baudrate. A solution is to set a bogus, not wanted baudrate and then the wanted baudrate.

Return to “Interfacing (DSI, CSI, I2C, etc.)”