Hi, first of all. Love droidscript! Only discovered a couple weeks ago, but its amazing.
Secondly, I have a working implementation using USBSerial. But, I have a little problem.
1) My connected device sends a string (Could be between 30-60 characters).
- The string is nicely formatted as "<datahere>\n" (So data is enclosed between Lessthansign and Greaterthansign, and each response is terminated with a Newline - should make parsing easier)
2) My callback
usb.SetOnReceive( function(e){
if ($('#log div').length > 5) {
// remove oldest if already at 300 lines
$('#log div').first().remove();
}
$('#log').append($('<div/>').text(e));
});
Using this simple debug to log out the serial Data, I saw it often truncates the line before it gets to the \n
So I'd get something like
<Idle,10,10,10,0,0,0>\n
<Idle,10,10,10,0,0,0>\n
<Idle,
10,10,10,0,0,0>\n
<Idle,10,10,10,0,0,0>\n
<Idle,10,10,10,0,0,0>\n
<Idle,10,10,10,0,0,0>\n
<Idle,10,10,10,0,0,0>\n
<Idle,10,10,
<Idle,10,10,10,0,0,0>\n
(Looks like either the lines get truncated, or theres an extra Newline injected? )
I am porting this project to Mobile, from a NodeJS original. in NodeJS we use the Node-serialport module, and there, we setup the port like this:
port = new SerialPort('COM1', {
parser: serialport.parsers.readline('\n'),
baudRate: 115200
});
(Setup the Module's parser to only call the callback once it hits a newline)
I am wondering if Droidscript's USBSerial maybe calls the callback once a buffer is full? Or what?
PS: Is the source for USBSerial available? I'd like to take a look to understand it better, and i also want to look at adding some events (Disconnect so app can know when the USB maybe gets unplugged with the app running, etc)