UsbSerial library - Supports FTDI, Arduinos and other USB serial devices

Status
Not open for further replies.

arge06

Member
Licensed User
Longtime User
@arge06 why do you use Chr? Do you want to send bytes or characters?

B4X:
Dim data() as byte = Array as byte(0XDF, 0x00, ...)
astreams.Write(data)

I want to send and receive data in bytes, with your example I can send bytes, my main problem this.

for example, i send 0x41 and 0x42 from tablet, in the pc i can see AB, this is ok, when i send AB from pc, i must receive data and put it into an array

AB sent from pc, in tablet I want to see
received(1) --->A and received(2)--->B or something else.

Is there a detailed wiki for the library ? I read the present one but its not enough for me.

Thanks in advance.
 

arge06

Member
Licensed User
Longtime User
I'm sorry but I don't understand the question. I guess that the BytesToString keyword can help you.

Thanks for your help bro,
Eveything seems to be done, now I have only two questions;
I’m sending data from pc to my tablet via ftdi interface, tablet sends perfectly but when I send data from pc to tablet; for example I sent “HELLO”, tablet gets data but there is a problem in bytes; it gets data like “ELLOH”, “OHELL” , “LLOHE” or not receiving complete data; like “HE”, “HELL”, “LO”... and something like this. I tryed in different baud rates (2400 to 57600) but nothing changed. Is there any way to receive control for data, I want to receive as I send.

My second question is: I want to send data from variables, I can send constant strings or bytes but I couldn’t manage to send a variable as data.

For example;

Dim k(4) as byte
Astreams.write(k(1),k(3)
Or
Dim s as string
S=”hello”
Astreams.write(s&”qqq”)
I couldn’t find any way to do this.

Thanks in advance to eveyone.
 

yo3ggx

Active Member
Licensed User
Longtime User
patched library

Hi all,

I've packaged a version of Erel's UsbSerial library which integrates the latest version of the usb-serial-for-android library (with CP2102 support) and the patch for the FTDI control data filter (git.altlinux.org - usb-serial-for-android.git/blobdiff - UsbSerialLibrary/src/com/hoho/android/usbserial/driver/FtdiSerialDriver.java)

If someone with a FTDI module can test it and tell me how it works would be great. I still have some issues with my interface.

This is the new package. Just unzip in the library folder and use UsbSerial3 instead of UsbSerial in your app.
No need to copy anything else in the Library folder.


Thanks,
Dan
 

Attachments

  • usbserial3.zip
    30.1 KB · Views: 356

yo3ggx

Active Member
Licensed User
Longtime User
You might consider exposing the modem control methods which might be useful.

Yes, but first I need to understand why is not working for me as expected if big chunks of data are expected to be received.
The communication hangs after a few tens of bytes are received and then is no more possible till the interface is reinitalized.

Is there anybody reading this thread successfully communicating with FT232R using this library?

Thank you
Dan
 

agraham

Expert
Licensed User
Longtime User
From looking in the library it would seem to me that as long as you have not received an "Expected at least 2 bytes" exception and reading the input stream is still occurring, is not hung and is repeatedly returning 0 then it seems the synchronous reads of the endpoint at the adaptor are succeeding and it must be sending the two status bytes.

In that case there is nothing wrong with the USB communication and looks like the adaptor that for some reason is failing to pass any data bytes in addition to the status. Flow control of some sort gone wrong?
 

yo3ggx

Active Member
Licensed User
Longtime User
In my case I'm expecting 4000 bytes to be returned by the FT232 after I'm sending the right command.
I receive only 56 bytes even the interface still sends data to the USB/serial adapter (there is a LED telling me that).

The communication is at 115200 bauds and works as expected if using a CP2102 based USB/Serial interface instead of the FT232R based one.
 

agraham

Expert
Licensed User
Longtime User
My guess is that the problem is at the FT232R as the read routine in the library for the CP2102 is very similar to that for the FT232R and it already seems that the FT232R is returning status but no data for those reads.

If it is exactly 56 bytes every time it looks like a flow control problem as buffer overruns and lost data would tend to be variable. Have/can you dramatically slow the baud rate down to see if that changes the symptoms?
 

yo3ggx

Active Member
Licensed User
Longtime User
If it is exactly 56 bytes every time it looks like a flow control problem as buffer overruns and lost data would tend to be variable. Have/can you dramatically slow the baud rate down to see if that changes the symptoms?
No, the number of returned bytes is different if I repeat the same command after a initialization.
The same happen with two different devices which are not of the same type.

The connection using a Bluetooth/Serial module and at the same baudrate is ok with the Serial library, with both devices.
 

yo3ggx

Active Member
Licensed User
Longtime User
CP2102 work with Erel library wrapper only if you use an updated library file to include CP2102 support. Version 010 does not have it.
I cannot use CP2102 as I have to connect to some devices (Antenna analyzers) with FT232R chip included.
 

yo3ggx

Active Member
Licensed User
Longtime User
Even the original one is made only for FTDI, for me does not work as expected.
This was the reason I've tried to filter control data without success.
 

yo3ggx

Active Member
Licensed User
Longtime User
Some updates with the original Erel's code and FTDI (FT232R).
I'm sending a command and expect to receive 8000 bytes.
FT232 sends me the following chunks over USB (as received in AStream_NewData callback routine):

chunk total received bytes
25 25
799 824
824 1648
824 2472
824 3296
824 4120
824 4944
824 5768
824 6592
824 7416
824 XXX

As I'm expecting no more and no less than 8000 bytes, my app does not go further considering that the received data is corrupted.
This means for sure that control bytes are inserted in the stream so without filtering them the library cannot be used.

And now surprise!
With the patched library I receive exactly 8000 bytes in chunks of 800.
I haven't changed anything from yesterday to today. This is weird.

Someone else can confirm my results?

Dan YO3GGX
 
Status
Not open for further replies.
Top