USB support in Linux

Linux specific questions.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: USB support in Linux

Post by caseih »

Dinosaur wrote:Hi All

Problem is now identified as Baud rate.
When opening the port with FB program line:

Code: Select all

        Open Com "/dev/ttyUSB0:38400,n,8,1,cs0,ds0,cd0,rs" For Binary As #CP
it opens the port at the default Baud rate set by the Linux system.
On my system, it happens to be 115200.
In Dos, you could use a Mode statement to set the baud rate.
Is there such a statement in Linux ?
Well the stty command can set the baud rate as well as determine what it is. There're also some API calls you can make using the termios.h file, which is how you do it from C (http://stackoverflow.com/questions/6947 ... -port-in-c).

Looks to me like a bug in the runtime library. I reduced the test to just:

Code: Select all

Open Com "/dev/ttyUSB0:38400" For Binary As #1
and confirm it does not set the baud rate. Running minicom or stty does, though.

Probably we should have the list moderators change the subject of this thread to "Serial support in Linux" since it's more about accessing serial ports, whether physical or USB. I started to look through the runtime library source files, but I haven't had time to figure out where the actual serial port code is.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: USB support in Linux

Post by caseih »

I looked in the runtime code and it sure looks like it's trying to set the baud rate. Also, when the serial port is closed, FB will restore the port settings to what they were before you opened the port. So just because stty reports 115200 doesn't mean that's what FB is setting it to. So maybe the stty thing was a false lead. At this point I'm confused! I guess I could comment out the line in the runtime that restores the previous serial port settings on close so we could get a better look at what FB is doing to the port. Unfortunately I can't run stty on the serial port while FB has it open.

Also FB attempts to make COM# notation work on Linux, but it's only for built-in ports. COMx becomes ttySx-1.
Dinosaur
Posts: 1481
Joined: Jul 24, 2005 1:13
Location: Hervey Bay (.au)

Re: USB support in Linux

Post by Dinosaur »

Hi All

At this point in time this issue is not holding me up.

caseih I am reliant on the developers to solve this problem.
That is, if this is a problem for Linux across the board.
I am running Linux Mint, what flavour are you running that is also showing the problem.

Can someone else confirm the same problem with other Linux distro's

Regards
speedfixer
Posts: 606
Joined: Nov 28, 2012 1:27
Location: CA, USA moving to WA, USA
Contact:

Re: USB support in Linux

Post by speedfixer »

To ensure that Linux ports are setup as requested, typical solution is to tell Linux OS what you want first, as:

Code: Select all

    shell "stty -F /dev/ttyUSB0 speed 9600 -clocal -hupcl"
    sleep 1000
    open com "/dev/ttyUSB0:9600,n,8,1,cs0,cd0,ds0,rs" as #filnum
You have a little more control over what you are doing, not trusting FB and Linux matches.

David
Dinosaur
Posts: 1481
Joined: Jul 24, 2005 1:13
Location: Hervey Bay (.au)

Re: USB support in Linux

Post by Dinosaur »

Hi All

Thanks for that David.

I looked at the command, but only saw ispeed & ospeed, and when I tried them they failed.
That whole issue is shady in my opinion.
When I use your suggestion in the Terminal it replied with 38400
Then using stty on it's own it replied with 115200
Then using your statement again, it replied with 9600 ???

Regards
speedfixer
Posts: 606
Joined: Nov 28, 2012 1:27
Location: CA, USA moving to WA, USA
Contact:

Re: USB support in Linux

Post by speedfixer »

yes.

It seems Linux always replies with the baud as set *before* the operation.

But the change was made..

David
speedfixer
Posts: 606
Joined: Nov 28, 2012 1:27
Location: CA, USA moving to WA, USA
Contact:

Re: USB support in Linux

Post by speedfixer »

You also have to remember that almost every terminal program has some init process that will set the desired port to some expected inititial settings. They usually don't 'float' with whatever is already present.

Each terminal run will reset the port in the OS.
Post Reply