B4J Question (Solved) B4J Serial Ver 1.31 Issues on data recieved

rodmcm

Active Member
Licensed User
I have an Arduino program that sends 270 analog values as byte in prefix mode , and it works fine on Bluetooth serial on B4A and B4J
I do not want to convert this to B4R as it has extensive use of interrupts
The main send routine is

B4X:
void Send270Array()
{
        byte b[4];
        b[0] = 0;                                             // Sending 270 items in prefix mode
        b[1] = 0;
        b[2] = 0b00000001;                          // prefix header for 270 items
        b[3]=  0b00001110;
        for(int j=0;j<4;j++)
           Serial.write(b[j]);
        for (int i = 0;i<NoVals;i++)
           Serial.write(AnalogVal[i]);
}

But it will not work with B4j Serial in prefix mode.

So after lots of hair pulling I set up a series of tests and just logged the serial port astream buffer length (for ease I used B4jChat) using prefix and non prefix receiving where appropriate
I put a counter on the bytes sent to check send quantity.


a) Sent 40 Bytes Sent = 40 Buffer received length 129
b) Send 40 bytes in prefix mode Sent = 44 Buffer received length 109 Prefix failed java.lang.NegativeArraySizeException: -2147450880
c) Sent 20 Integers ( print send = 20) Sent = 20 x 2 Buffer received length length 159
d) Send 20 Integers as High and Low Byte Sent = 40 Buffer received length Length 86
e) Send 270 Bytes (the one working on bluetooth) Sent = 274 Buffer received length Length 276 Buffer length never logged in prefix mode

Can someone please assist...
Enclosed is Arduino test program
 

Attachments

  • Test Program to serial on B4j.txt
    2.3 KB · Views: 185

rodmcm

Active Member
Licensed User
Yes, just bad wording in my comments.

I send 270 bytes, and the header reflects this for prefix mode. NoVals = 270 and AnalogVal[] is a byte array
 
Upvote 0

rodmcm

Active Member
Licensed User
Setting the parameters solved the issue for the straight byte transfer and purging the receive RXCLEAR solved the prefix mode
 
Upvote 0
Top