Closed alexsaenko27 closed 2 years ago
what kind of multiport serial device are you using?
Zebra VC8300, it's a vehicle-mounted computer https://www.zebra.com/us/en/products/mobile-computers/vehicle-mounted/vc8300.html
which driver are you using in this library? CDC?
It should be FTDI
How do you check that the other port is busy? The library has no related function.
From screenshot below, you can see that both ports of a FT2232 can be opened in different apps. When opened in the other app, the connection is revoked from the previous app
Following is reported the description of the error reproduction with some screenshots.
The test environment is composed as is:
Configuration:
Serial port 1
Serial port 2
I open the system application in order to setup the Serial port 2
usage:
|:--:|
| Fig. 1 |
As you can see in the red rectangle the two serial ports are displayed and available for usage.
I select the Serial port 2
as shown in the image Fig 2.
|:--:|
| Fig. 2 |
From this point, the traffic sent through the Serial port 2
will be translated by the system as a keyboard input.
I open Chrome Web Browser on the Android device and I try to send some data from the computer. As could be seen in the Fig. 3, from the computer the text “test serial port 2” was sent on the Serial port 2
channel and it was received by the device and translated as keyboard input (Fig. 4).
|:--:|
| Fig. 3 |
|:--:| | Fig. 4 |
Now I start debugging My Application and as could be seen in the Fig. 5, the Serial port 1
is opened (portNum=0).
|:--:|
| Fig. 5 |
In particular, using the expression evaluation tool offered by my IDE, I check the state of the two ports and as supposed the Serial port 1
results open from My Application (as shown in Fig. 6) and Serial port 2
results closed (Fig. 7).
|:--:|
| Fig. 6 |
|:--:| | Fig. 7 |
Now from My Application I try to send a message on the opened serial port (Serial port 1
) and I received it on the computer as displayed in Fig. 8
|:--:|
| Fig. 8 |
Putting the focus on the Input Text Box in My Application, and trying to send “12345” on the Serial port 2
from the computer (Fig. 9), as displayed in Fig. 10, the system interprets it another time as keyboard input.
|:--:| | Fig. 9 |
|:--:| | Fig. 10 |
From this point all seems to work correctly.
Now if I try minimize My application, trying to reopen Chrome Web Browser on the Android device and sending “another serial port 2 test” from the computer (Fig. 11), it seems that the device is unable to receive the data from the Serial port 2
(Fig. 12).
|:--:| | Fig. 11 |
|:--:| | Fig. 12 |
Also if i try to reopen My Application and sending “6789“ from the computer, the device seems unable to receive the input data (Fig. 13 and Fig. 14).
|:--:| | Fig. 13 |
|:--:| | Fig. 14 |
Another strange things is that if I try to open the System Application, both serial ports have disappeared from the list of available inputs (Fig. 15) that could be translated as keyboard input, so I deduct that the ports are busy by My Application. Serial port 2
should still be available.
|:--:| | Fig. 15 |
At this point I try to close entirely My Application and, as can be seen in the Fig. 16, I perform the closing of the serial port that I have previously opened.
|:--:| | Fig. 16 |
Reopening the System Application can be noted that now the serial ports reappear as available as shown in Fig. 17.
|:--:| | Fig. 17 |
Now opening another time the Chrome App in the device and trying to send data (“third serial port 2 test“ Fig. 18) from the computer, the android device receives correctly the data (Fig. 19).
|:--:| | Fig. 18 |
|:--:| | Fig. 19 |
Note that I can’t perform the serial port closing when I minimize My Application, because also when it is in background it must continue to communicate on the Serial Port 1
.
Now I’m trying to repeat the previous steps but switching the port.
In this example you can note the correct behaviour that one would expect from the library.
Configuration:
Serial port 1
Serial port 2
As first step, I open the System Application and activate the Serial Port 1
as keyboard input (Fig. 20 and Fig. 21).
|:--:|
| Fig. 20 |
|:--:| | Fig. 21 |
I open the Chrome App on the android device and I try to send the string “test serial port 1“ (Fig. 22) from the computer. As could be seen in the Fig. 23, it is received by the application.
|:--:| | Fig. 22 |
|:--:| | Fig. 23 |
In the next step, I start the debugging of My Application and, as could be seen in the Fig. 24, I open the Serial port 2
(portNum=1).
|:--:| | Fig. 24 |
Through the evaluation tool of the IDE, I check the status of the ports opened by My Application and as expected the Serial port 1
is closed (Fig. 25) and Serial port 2
is open (Fig. 26)
|:--:| | Fig. 25 |
|:--:| | Fig. 26 |
Now from My Application I sent data to the Serial port 2
, that are received by the computer (Fig. 27)
|:--:| | Fig. 27 |
Now from the computer I try to send the string “12345“ (Fig. 28) and it is received by the device and translated as Keyboard input (Fig. 29)
|:--:| | Fig. 28 |
|:--:| | Fig. 29 |
I try to minimize My Application and reopen the Chrome App. As could be seen in Fig. 30 and Fig. 31, if I try to send another string on the Serial port 1
(“another test serial port 1“), contrary to what happened in the Test 1, this time it is received by the device.
|:--:| | Fig. 30 |
|:--:| | Fig. 31 |
Also if My Application is brought back to the front the data are received correctly (Fig. 32 and 33) |:--:| | Fig. 32 |
|:--:| | Fig. 33 |
Another difference with the previous test could be seen also in the System Application (Fig. 34). The list of the available inputs are correctly shown. The Serial port 2
used by My Application is not shown as available, while the Serial port 1
is.
|:--:|
| Fig. 34 |
Closing My Application, as shown in Fig. 35, also the Serial port 2
returns available.
|:--:| | Fig. 35 |
As last thing, I try to send another message on the Serial port 1
and as shown in Fig. 36 and Fig. 37 it is received correctly from the device.
|:--:|
| Fig. 36 |
|:--:| | Fig. 37 |
How does the External Application check that a port is available? usb-serial-for-android does not offer a function to check if it is already opened somewhere else, it's isOpen()
only checks if opened by itself. Do you know which library the External Application is using?
With Android USB API one can open an USB device in multiple Apps and steal the connection from the previous App. I suspect one of your involved Apps is doing this by chance and stops at a certain port, so it works in one direction
Hi, I have an Android device with 2 serial ports on which I am developing an application using the library. The two ports are associated with the same UsbSerialDriver.
Opening the first port (... driver.getPorts().get(0)) and verifying through the method offered by the library (isOpen()) the opening status of the two ports, it appears that the first is open and the second closed. From here I assume that the second port is still available for use by other applications, but this does not appear to be the case as the second port results as busy. The latter becomes available only when the first port gets disconnected.
Viceversa by opening the second port (... driver.getPorts().get(1)) and repeating the checks carried out in the first case, it appears that the first port remains available for use by other applications, that is, it is not busy.
It has also been noted that, if the second port is used by another application and you try to open the first port through the library, the traffic on the second serial continues to transit until my application is put in the background. Afterwards the second serial port seems to be busy and the other application that had previously opened it cannot use it until, as described above, the first port is explicitly disconnected from my application.