On Tue, Nov 25, 2014 at 4:23 PM, John Mladenik <[email protected]> wrote:
> Does anyone know an easier way to send a packet of hex data out the serial
> port. Here is what works for me
>
> var dio6Hi = [0x7E, 0x00, 0x10, 0x17, 0x01, 0x00, 0x13, 0xA2, 0x00,
> 0x40, 0xC0, 0xA9, 0x99, 0xFF, 0xFE, 0x02, 0x44, 0x36, 0x05, 0x72 ];
>
> b.serialWrite(port, [
> dio6Hi[0] ,dio6Hi[1] ,dio6Hi[2] ,dio6Hi[3] ,dio6Hi[4] ,dio6Hi[5]
> ,dio6Hi[6] ,dio6Hi[7] ,dio6Hi[8] ,dio6Hi[9],
>
> dio6Hi[10],dio6Hi[11],dio6Hi[12],dio6Hi[13],dio6Hi[14],dio6Hi[15],dio6Hi[16],dio6Hi[17],dio6Hi[18],dio6Hi[19]
> ]);
>
> This will write all of the data in variable dio6Hi out of the UART in
> order that I want. But I would like to do this or something like it:
>
> for (var i = 0; i < dio6Hi.length; i++) {
> b.serialWrite(port, [dio6Hi[i]] );
> }
>
> or even this:
>
> b.serialWrite(port, [dio6Hi[0]] );
> b.serialWrite(port, [dio6Hi[1]] );
> b.serialWrite(port, [dio6Hi[2]] );
>
> .
> .
> .
> b.serialWrite(port, [dio6Hi[18]] );
> b.serialWrite(port, [dio6Hi[19]] );
>
> Either of these do not work they only send out the first byte in dio[0] and
> then stop. Is there any way with the serialWrite function to index the
> variable with a "for" or other command in order to simplify sending out an
> array of numbers?
I believe your primary issue here is that the calls to b.serialWrite()
are asynchronous and you aren't waiting for the writes to complete.
I'm not really sure why you'd want to have individual calls to write
each byte, but you could try something like:
var i = 0;
mySerialWrites();
function mySerialWrites() {
if(i < dio6Hi.length) {
b.serialWrite(port, [dio6Hi[i]], mySerialWrites);
i++;
}
}
I haven't tested this, but I think it might be your issue. Let us know.
>
> --
> For more options, visit http://beagleboard.org/discuss
> ---
> You received this message because you are subscribed to the Google Groups
> "BeagleBoard" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.