FullDuplexSerial string operation
Harley
Posts: 997
Looking at this object, which is almost NOT commented, I think I see how to transmit a string from one Prop to a second.
But how does one receive a string?___ I see no reference to that.
And, if a string is longer than the buffer length, will it wait for room to open up in the buffer?___
Sorry about questions so late in the day prior to a Holiday. Good turkeys to all forum members.
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Harley Shanko
h.a.s. designn
But how does one receive a string?___ I see no reference to that.
And, if a string is longer than the buffer length, will it wait for room to open up in the buffer?___
Sorry about questions so late in the day prior to a Holiday. Good turkeys to all forum members.
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Harley Shanko
h.a.s. designn
Comments
Regarding your second question - if the buffer fills and you're not servicing the serial device fast enough, you'll start getting serial overruns.
- Rich
I'm using one Prop with TV_text object for debugging; want to get some info from the 2nd Prop's program plus CHIPVER; the latter works OK. Seems something like this might be required, from what I think you're suggesting:
with Prop2 sending a '0' character at the end of the sending of a string?___
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Harley Shanko
h.a.s. designn
The code above takes a TAB delimted string, and separates it, and converts it into two integers. Here is what I sent it from a computer:
In this example, the computer looks at a slider position, and sends the ascii ID of the Slider value plus a TAB(chr(9)), then the string value of X(i.e. 5000), then a CR. The propeller reads it, and separates the string at the TAB, and terminates at CR. Then, the Propeller reads through a list of about 10 cases, and assigns values to variables depending on the ID is received. You could modify the code to suit your needs.
If you only needed to get a byte only, then you could just"
This will get the most recent byte rec'd.
Good luck with it.
Post Edited (originator99) : 11/23/2006 7:23:15 AM GMT
Appears to be much more complicated than I'd of imagined. No wonder nothing seemed to work right.
Will mull over why it is so involved and try your suggestions.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Harley Shanko
h.a.s. designn
When you read in the string, the first rec'd byte goes to MyArray[noparse][[/noparse]0], and then each iteration of the readByte adds the next byte to the next element until it hits the termintor. So that the result is:
The z_string, or zero terminated string, is a method to tell your loop that is reading the bytes that the string is done. You could in fact set up the loop to determine other values as the termination. Sometimes a Return (CR) is the termination, as in the example posted above. However, once it is read into the Propeller, whatever termination used is ultimately converted to a zero.
The end result is, once all the elements have been filled with your string, the array MyArray can then be used for the purpose of the application. For example, if you were wanting only to see the string on the LCD, you'd refer to the LCD object and display all or part of the array.
To make this simpler, here is what I would do:
1. determine what you want to do with the string
2. deterimine your termination scheme(CR for example)
3. set a loop to read the bytes in (see example above), just use ser.rx to wait until a byte is rec'd, or a code block that uses ser.rx to read each byte, and increment the append to the array(see PRI receiveStr above)
4. separate your string if needed by a TAB or other separator
5. run some code to do something with the variable or array, or ignore the string as desired
6. go back to the loop and wait for more bytes
Hopefully this helps more than it confuses, but at this hour you don't have many options left on the forum [noparse]:)[/noparse]
Post Edited (originator99) : 11/23/2006 9:24:49 AM GMT
This stands to be corrected by someone that knows what they are talking about, but I think there are several problems with this.
1. What if your data had a 0 in it? You'd want to use some termination that would certainly not be a possibility for some real data.
2. Your loop does nothing with each byte it receives in terms of keeping it around for future use. If you tell it to loop until c:= 0, you are just making c = the most recent byte received and all other bytes are now gone forever as you didn't park them anywhere in a variable/array for future use. Instead, run a loop that increments and appends the array as in the example I posted. It reads a byte, sticks it in the first element of the array, reads another, sticks it in the next elemenet and so forth. Note that there is a "count" parameter passed that tell the loop how many times to repeat. This could be any number, just be sure to have your array set to receive that number plus the termination. You start counting at array[noparse][[/noparse]0].
3. Unless there is a good reason, don't use .RxCheck, since if the cog is busy with other things it may miss a byte. Use .Rx as it never misses a byte as it is always waiting for a byte. If needed put the .rx on another cog. if the Propeller is to be doing other things while it is waiting for the byte. If no action is needed prior to getting the string, just put your loop at the top of the block, when the loop hits the termination it can go run some other code and then come back and wait til the next string/byte.
4. Don't worry about using <> -1, it will just read whatever comes in, it doesn't matter if if is nil.
5. You may take a look at this syntax
You may want
Post Edited (originator99) : 11/23/2006 6:42:33 PM GMT
I may not have stated that it is a 'string' that is being sent from one Prop to another. So a '0' terminated string will just send the ASCII characters; the '0' stopping the transmission, right?___
Now the problem at the receiving end is 'how' to recognize when the string is ended. I suppose the transmitting Prop could append a '0' (0000_0000 binary) and the routine would see the string properly end.
I was hoping there was already implemented was some (normal???) way to deal with receiving ASCII codes. And testing for CRs or TABs, or the '0's for endings.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Harley Shanko
h.a.s. designn
Below is an example that sends out a string of various info, note that ID is a variable that is an integer(4270), TAB is a hex number $09, Temp2 is a variable that is an integer, all followed by a Space. The receiver in this case chops off the string after the Space as terminator.
So in simpler terms, the string looks like all these values sent in succession:
4270 'contains 0's
$09 '0's again!
25000 'only an example, this could be any number, but note that it does contain 0's
$09
" " ' an ascii space
Since a string cannot be a real integer since it is only ascii values, you must use some ascii value as terminator/separator that does not get used in your real info.
If you go back and study the first code I posted, or rather pulg it in and test it, you will see that it gets to a TAB, then it runs the convert method to convert the ascii values to integers and assigns the value to a long variable for future use. In the example it assigns the first block of ascii info to Temp1. Then it continues reading, it assigns the second ascii block following the TAB to Temp2. This could in fact be any number of separate ascii blocks, separated by however many tabs you need. But when it gets to the CR, it is done for that string.
If you post what you are trying to send, it will be easier to point you in a direction of how to receive it.
Thanks for the further information.
Gotta break now to go to Thanskgiving dinner. Will try suggestions tomorrow. Family and holidays gets in the way for this 'fun' stuff.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Harley Shanko
h.a.s. designn
Note that I return the position where an int or float was found and pass the variable to be taken from a string by reference -- this is because I'm using this mostly to parse NMEA strings, this allows me to do things like checking that a value is present and/or getting the next value by calling ParseNextInt or ParseNextFloat repeatedly.
If someone more knowledgeable than me would care to help me optimize this, please do [noparse]:)[/noparse]