xseignard / cordovarduino

Cordova/Phonegap plugin for USB host serial communication from an Android device.
MIT License
166 stars 110 forks source link

Using multiple USB serial adapters #53

Closed DragonNZ closed 8 years ago

DragonNZ commented 8 years ago

Is there any way with this library to have multiple serial connections open? If I plug in two USB serial ports, it just randomly connects to one of them. If I was to use two USB serial ports from different vendors and opened them using the vid/pid options, would the library allow me to operate the ports independently and simultaneously, or is this library limited to using a single USB serial port.?

Thanks,

xseignard commented 8 years ago

Hello @DragonNZ That's a good question! I don't have the hardware to test it, but it seems that passing VID/PID may work.

Let me know if you can test it

Regards

xseignard commented 8 years ago

Any updates?

DragonNZ commented 8 years ago

Didn't have any luck with getting the alternate device to work on it's own, so didn't have the hardware to test it with in the end. For this project I am building an external interface that is going to multiplex 4 serial ports and some analog input data through a single USB serial input. So that has solved the issue for me at least.

DragonNZ commented 8 years ago

Hi,

I am using a binary protocol over the serial port and I have struck an issue. When using Serial.Write with a binary sequence, I am getting extra bytes injected for bytes of value 127 or greater in the string. Looking at the source code, it looks like String.getBytes() is returning a unicode sequence rather than the raw bytes themselves. Do you know of any work around for this, or maybe the string shouldn't be converted via the getBytes function?

DragonNZ commented 8 years ago

Hi, In regard to the binary protocol, took me a while to realise that the writeSerialHex is what I was looking for, which is already there.

xseignard commented 8 years ago

Hi @DragonNZ so you're ok?

If you find the docs lack of clarity, please tell me how to update them.

Regards

DragonNZ commented 8 years ago

Yep I am ok and the documents are fine. It just my inability to read them. I saw the writeSerial function and that was enough for me, until I hit the issue with Unicode and Strings. I initially added a writeSerialBase64 function to your code, until I finally read the code in the writeSerialHex function and realised what it did. I usually program in C++, not javascript, but I couldn't find a function to convert binary to a hex string in JS, so I wrote my own function for that. I note that JS includes the btoa function which encodes a byte sequence into a base64 string. Have you considered using base64 instead of hex for that function?

Regards