Other Trying to add SetRTS functionality to USBSerial library

sunish

Member
Licensed User
Longtime User
Iam not very familiar with Java and its libraries in B4a.

Iam trying to modify the USBSerial library to support flow control for CP2102. There is a function definition in Cp2102SerialDriver.java called public void setRTS(boolean value). I tried adding
setConfigSingle(SILABSER_SET_MHS_REQUEST_CODE, MCR_ALL | CONTROL_WRITE_DTR | CONTROL_WRITE_RTS | MCR_RTS);

Compiled the library using SimpleLibraryCompiler and got it into b4a and then tried invoking the function through reflection. But I am not sure whether the code is getting executed. I tried adding Log.d to the function but its not appearing in the B4a logs.

Would like to know how to add to the B4a logs from a library and whether this is the right way of adding the SetRTS function.
 

sunish

Member
Licensed User
Longtime User
Use the unmodified library:
B4X:
Dim r As Reflector
r.Target = UsbSerial1
Dim driver As JavaObject = r.GetField("driver")
driver.RunMethod("setRTS", Array(True))

No change in RTS status with
driver.RunMethod("setRTS", Array(True)) or
driver.RunMethod("setRTS", Array(False))

My doubt is that without implementing the function in the library, will this code have any effect ? It seems to be implemented in the Prolific driver, but not in ftdi and Silicon labs, CP2102 which I use for testing.

Sunish
 

sunish

Member
Licensed User
Longtime User
In the source files of the usbserial library the java file for prolific (..USB_Serial_2.4\src\com\hoho\android\usbserial\driver\ProlificSerialDriver.java) has
B4X:
 @Override
    public void setRTS(boolean value) throws IOException {
        mRts = value;
        setDtrRts();
    }

but for CP2102(..USB_Serial_2.4\src\com\hoho\android\usbserial\driver\Cp2102SerialDriver.java) just has

B4X:
@Override
    public void setRTS(boolean value) throws IOException {
    }

The SetRTS function is not implemented in the driver I guess. I was attempting to do that by referring to the C implementation at http://lxr.free-electrons.com/source/drivers/usb/serial/cp210x.c#L283

But I was not able to ensure the function in my modified java driver is getting executed as I was not able to get anything in the debug logs using Log.d.

Sunish
 
Top