Go Down

Topic: Arduino to Flash, bytes are missing (Read 428 times) previous topic - next topic

Zwaf

Hi guys!

I'm working on a project here whereby I send bytes from an Arduino to a computer.
On the computer I have Serproxy running, which catches the bytes and supplies the socket connection for Flash.
However, bytes seem to get lost in the transfer and it is likely a Serproxy of Flash problem.

What I do is I send the following from Arduino to PC:
101 (a few microsec) 200 (wait 2 sec) 102 (a few microsec) 200 (wait 2 sec) 103 (a few micr....
All the way up to 115, 200 and then returns to 101 and 200.
Why it does this, I think is irrelevant for the problem being :)

When I open a serial monitor (such as the one included with Arduino, or in my case Terminal 1.9b), the bytes are delivered as expected.
It prints the value and 101 and 200 simultaneously, followed by 102 and 200 two seconds later.

However, in Flash and via Serproxy, it seems to regularly skip a value. If I directly copy the trace result from Flash you can see:
Code: [Select]

Value received:106
Value received:107
Value received:200
Value received:108
Value received:109
Value received:110
Value received:111
Value received:112
Value received:200
Value received:113
Value received:114
Value received:115
Value received:101
Value received:102
Value received:200
Value received:103
Value received:104
Value received:105
Value received:106
Value received:107
Value received:200
Value received:108
Value received:109
Value received:110
Value received:111
Value received:112
Value received:200
Value received:113
Value received:114
Value received:115
Value received:101
Value received:102
Value received:200
Value received:103
Value received:104
Value received:105
Value received:106
Value received:107
Value received:200
Value received:108
Value received:109
Value received:110
Value received:111
Value received:112
Value received:200
Value received:113
Value received:114
Value received:115
Value received:101
Value received:102
Value received:200
Value received:103
Value received:104
Value received:105
Value received:106


There does seem to be a certain rhythm in it, once about every 5 values it manages to catch a 200.
The BAUD rate is configured correctly, 9600 in both Serproxy and Arduino.
Parity/Stop bits are the same in Serproxy as in Terminal 1.9b (and since it works in Terminal, this can't be the problem either).

Is there anyone who recognises this? Might it be a problem with the buffer of Serproxy or the speed at which Flash can fire a SOCKET_DATA event?
In Flash I simply create a Socket Object with event listeners and have the SOCKET_DATA retrieve the value from the following: connection.readUTFBytes(connection.bytesAvailable);

Thanks in advance!

Zwaf

I managed to fix the problem myself! For those that might some time experience a similar problem:

I performed a CharCodeAt function on the incoming data. This does not take into account that the incoming data might be longer than 1 byte!
So if I would receive j? in ASCII, charCodeAt would only return 1 value, namely 102 of the J.
You will need to perform the charCodeAt for every char in the received array of bytes (in the form of a string)

Go Up