HELP.spin - I Am Going In Circles And Getting Dizzy - Byte Array
idbruce
Posts: 6,197
I thought I understood this stuff, but apparently not, because I am having quite a bit of trouble accessing the data in my arrays, and I have tried numerous methods. Anyhow, I need help.
The provided source code and archive represents the concept of what I want to achieve, but just in case it is unclear, I will provide a small description. Basically I am parsing a G-Code file one character at a time, and shoving that character into one of the elements of a predetermined array. When I need the data for further processing, I am attempting to parse the elements of the various arrays. Can someone please enlighten me and tell me what I am doing wrong?
The provided source code and archive represents the concept of what I want to achieve, but just in case it is unclear, I will provide a small description. Basically I am parsing a G-Code file one character at a time, and shoving that character into one of the elements of a predetermined array. When I need the data for further processing, I am attempting to parse the elements of the various arrays. Can someone please enlighten me and tell me what I am doing wrong?
CON _CLKMODE = XTAL1 + PLL16X _XINFREQ = 5_000_000 TX = 30 RX = 31 COMM_MODE = 0 COMM_BAUD_RATE = 115_200 VAR BYTE bFieldElement_4[7] BYTE bFieldElement_5[7] OBJ Terminal: "FullDuplexSerial" PUB Main bFieldElement_4[0] := "-" bFieldElement_4[1] := "9" bFieldElement_4[2] := "9" bFieldElement_4[3] := "." bFieldElement_4[4] := "9" bFieldElement_4[5] := "9" bFieldElement_5[0] := "1" bFieldElement_5[1] := "1" bFieldElement_5[2] := "." bFieldElement_5[3] := "1" bFieldElement_5[4] := "1" Terminal.Start(RX, TX, COMM_MODE, COMM_BAUD_RATE) WAITCNT(CNT + (1 * CLKFREQ)) ProcessCoordinate(@bFieldElement_4) ProcessCoordinate(@bFieldElement_5) Terminal.Str(STRING("Finished")) PUB ProcessCoordinate(StrPtr) | Index, Char Index := 0 REPEAT Char := BYTE[StrPtr]'[Index] IF(Char >= "0" AND Char =< "9") Terminal.Str(STRING("0-9")) Terminal.Tx(13) IF(Char == "-") Terminal.Str(STRING("Minus")) Terminal.Tx(13) IF(Char == ".") Terminal.Str(STRING("Period")) Terminal.Tx(13) Index++ WHILE((Char => "0") AND (Char =< "9")) OR (Char == ".") OR (Char == "-")
Comments
If the equal sign is on the right, it's an assignment operator.
You have them in the correct order in your "while" comparison.
Bean
Bean- The ++ would be if you were parsing a variable, not the elements. The ++ made the terminal totally blank.
The code now works with Duanes correct and the use of Index. Here is the final working source.
Bean's suggestion is one of the ways the buffer could be incremented.
It would work with Index++ or StrPtr++ but not both (with the latest version of the code).
The first source had Index commented out, because it was not doing me any good, until your correction about the operators. I also tried ++, but it did not work, however I just tried it again and it now works. Perhaps I did not wait long enough. My apologies Bean
Here is better source code for those with similar problems.
You can get the address of your string with @ and modify it at will. For example
By terminating the ASCII string with 0 allows one to use .str() methods in serial objects.
That is a very good tip. Thanks.
I have to go shovel some snow , but I will check it out as soon as possible and see how it fits into the grand scheme of things, but I think it sounds good and it is probably a much better solution than what I am using.
I also suppose it would also depend how much grief it would cause me at this point.
Thanks Jon
If you decide to stick with your traditional byte arrays you can load them with one line of code:
After taking a look at the source, I could easily see that changing that aspect would be a major undertaking. However I sincerely appreciate the tips of good advice and the sharing of your knowledge.
Bruce
P.S. If you care to take a peek, I just post the source at this thread: http://forums.parallax.com/showthread.php/159950-The-Teacup-Port-A-Work-In-Progress-With-Added-Extras-3D-Printer-Firmware?p=1313959#post1313959