Strings, serials, bytes and other animals.
Hugh
Posts: 362
Any help with the following would be gratefully received....
I am using v1.2 of the Simple_serial object to send data from one propeller to another. The data is being received at the other end, but when I go to write it to an SD card or LCD the received and re-assembled string of bytes is either 0 or a lot of gibberish.
This is the code at the 'receive' end. The goal is to grab the numbers out of a comma-delimited stream (e.g., ",1212,1213,1214,1215,1216 ..) passed by the other prop so it has a zero terminated string with which I can do things (send to an SD card or to an LCD).
I've tried using 'Scratchpad' directly and by pointer (writing it as a string to an LCD and via SimpleDebug to serial Terminal), to no avail. Another PUB in a different cog does the writing.
serial.str(@scratchpad) doesn't work - all I get is the final comma received, preceded by a single character, typically
I am using v1.2 of the Simple_serial object to send data from one propeller to another. The data is being received at the other end, but when I go to write it to an SD card or LCD the received and re-assembled string of bytes is either 0 or a lot of gibberish.
This is the code at the 'receive' end. The goal is to grab the numbers out of a comma-delimited stream (e.g., ",1212,1213,1214,1215,1216 ..) passed by the other prop so it has a zero terminated string with which I can do things (send to an SD card or to an LCD).
PUB getDataCount | rxByteR, rxcount ' (Scratchpad is a 20 byte array, i.e., declared as "byte Scratchpad[20]" in VAR) [B]SOLVED[/B]. PICNIC (Problem In Chair, Not In Computer) dira[4]~~ ' Set pin4 as output debug.init(16, 18, 100) ' Start "simple_serial" object @ 100 baud repeat ' Repeat infinitely rxByteR := 0 ' Set this to zero bytefill(@scratchpad, 0, 20) ' Set all of the bytes of ~scratchpad~ to zero. This will mean it should get treated as a zero-terminated string repeat until rxByteR == 44 ' Keep receiving data until a comma (ASCII 44) is received rxByteR := debug.rx ' Receive data.... rxByteR := 0 ' Having found the first comma. set this two values back to zero rxCount := 0 ' Set this counter to zero - this is going to track repeat while rxByteR <> 44 ' Keep going until the next comma is found rxByteR := debug.rx ' Receive the next byte byteMove(@scratchpad + rxCount++, @rxByteR , 1) ' Put the received byte into ~scratchpad~ at the position tracked by the counter; increment the counter dcFlag:=1 ' Set this flag to 1 so that another PUB knows it is ready !outa[4] ' Toggle pin 4 so that the LED indicates traffic rxByteR := 0 ' Set this back to zero
I've tried using 'Scratchpad' directly and by pointer (writing it as a string to an LCD and via SimpleDebug to serial Terminal), to no avail. Another PUB in a different cog does the writing.
serial.str(@scratchpad) doesn't work - all I get is the final comma received, preceded by a single character, typically
Comments
Should be - rxByteR not @rxByteR
A little easier to read... and I believe I did not break any logic...
Or just
Andy
The bytemove method is a lot of overkill for a simple indexed store but the move operation requires a source address, not a source byte so the original version was correct. Unless of course rxByteR is already an address (is it?)
Your last method using the simple indexed store is of course the best way of storing a byte in a buffer.