Open ndvalkov opened 9 years ago
You could, but it will be slow. Really slow.
What about a separate cordova plugin with an xmodem implementation like this one?
I noticed it uses java.io libraries, vs java.nio in this plugin. And I guess it has to be compatible with the usb-serial-for-android drivers library.
I am not gonna be the one to write it, I'm just interested if you have any idea if it's doable or not.
Hi,
Nice idea, as far I can see, the code sample is almost "plug and play", I suspect getChar and putCahr to be the only things to adapt to use the opened port.
Since I have no idea on how to handle file transfer in the arduino/whatever side, I'm not sure how to implement it.
Regards,
Xavier
OK. Thanks.
Hello,
Everyone is busy, so I decided to to add the XMODEM functionality to your plugin, instead of writing a separate one.
However, that particular implementation I shared seems a bit strange. For one, there's a broken while loop, at line 52, that should be do..while. There's a label for nested loops, that I think is unnecessary. So I abandoned it. Decided to reimplement the functionality, given in this example from stackoverflow.
http://stackoverflow.com/questions/606074/implementation-of-x-modem-protocol-in-java
He tends to name variables of type DataInputStream 'foo', but apart from that I think it is ok.
I added it to the plugin Java source, made the necessary adjustments.
But I've been having difficulties with the getchar() and putchar() methods. I have some sample Delphi xmodem from an old app, that sends the handshaking commands(NAK, ACK..) the way it sends standard command through serial. So I tried with the standard port.write() port.read(). I menaged to receive the content of a file, and get some (false)handshake response, but in some rare, uncontrolled, cases. Very far from a decent implementation.
Do you have any idea if I need to use inStream.read()/outStream.write() as given in the example?
Here's an app that uses the "usb-serial-for-android" library, and the guy has added some classes to the lib:
https://learn.adafruit.com/smart-cocktail-shaker/usb-communication
"Added an InputStream and OutputStream implementation to better integrate the USB serial device with other Java classes."
Here's the code, if you want to check it out:
https://gist.github.com/ndvalkov/738cf450097d08aa67b0
Thank you.
Hi @ndvalkov,
I would love to try it, but I'm lacking time right now, and I think I don't have the matching devices.
Or maybe an arduino+sd shield would do the trick? If so please provide any info you have in order to be able to setup a test case on my side.
Regards,
Xavier
I don't know. Still can't do it, and I started considering alternative options.
Hello,
Can I use the plugin to transfer files over RS232?
So far I just got to fetching a file object from a file input, making conversions to hexstring and passing it as a parameter to the writeHex() method, but I doubt that will work. I thought about using some javascript libs for binary data, or implementing xmodem file transfer protocol with java for possible solutions.