usb to rs232 - How to set baudrate?

Dirk A

Member
Licensed User
Longtime User
Hi ,

I'm trying to communicate with an rs232 port through an usb converter.
I allready found the info on this forum for opening the port :
B4X:
  Writer.Initialize(File.OpenOutput("/dev/ttyS1","", False))
 Writer.WriteLine("This is a test")
and it works , I can see incoming data using a monitoring app. The problem is : the baud rate is incorrect , how do I adjust it ?
thanks
 

Dirk A

Member
Licensed User
Longtime User
I'm using an ftdi converter with the usbserial library now and I'm able to send and receive data but only at a baudrate of 9600. If I try to open the device with another baudrate - open(baudrate int) - it stays at 9600 . How come ?
 
Upvote 0

Dirk A

Member
Licensed User
Longtime User
I tried adding setparameter to the usbserial demo
B4X:
usb.SetParameters(19200,usb.DATABITS_8,usb.STOPBITS_1,usb.PARITY_NONE)
but it keeps on sending in 9600 ...

Maybe there's something wrong with my ftdi device.

When I run the program my permission is asked for the usb device ,I say yes but then
B4X:
Msgbox(usb.DeviceInfo, "Device Information")
says : "No device found . Is an accessory connected ? "

But then later in the code:
B4X:
Dim dev As Int
dev = usb.Open(19200)   
If dev <> usb.USB_NONE Then
Log("Connected successfully!") 
end if
Writes "Connected succesfully" to the log and I'm able to send at 9600 . I don't get it.

When I run the demo from the ftdi site my device is recognized as an ftdi device....
 
Upvote 0

Dirk A

Member
Licensed User
Longtime User
Are you sure that the usbserial lib is 100% compatible with ftdi chips ?
I'm sending data to a device using an ftdi usb to rs485 converter . The device sends me an answer back but the data is incorrect.
So the Astreams_NewData event is fired but when I check the log ,the data is wrong (it's just plain ascii data).

When I do the same thing with demo from FTDI site for android the received data is correct.
 
Upvote 0

Dirk A

Member
Licensed User
Longtime User
Well the response should be something like *0052009 etc
but the response is (pasted from the log)
*�L���9L��

so some characters seem to be ok but most of them are incorrect

EDIT
I've done some tests and when i send only 1 character at a time with my device to the android everything is received well in b4a. But when i send more than 1 character data gets corrupted.
 
Last edited:
Upvote 0

Dirk A

Member
Licensed User
Longtime User
thanks !
I adjusted the stopbits to 2 and now the data is received well!
Now I just need to figure out why I can't adjust the baudrate...
 
Upvote 0
Top