How do I read a string?
TC
Posts: 1,019
Hello all. As some of you might know, I am trying to program the prop as a 3D printer controler. The computer program I am using slices the CAD drawing, and sends the G-code out the serial port (USB) in an ASCII format. Right now I am just trying to get the prop to read those commands and print them on my LCD display. I know how to send a string out from the prop, and I can send a string to my LCD display, but I dont know how to read a string coming from my computer. One thing I do know is the string does not have a set value, or character count. To give you an idea:
Please let me know if you have any ideas on how I can see what the slicing program is sending.
Thanks
TC
29 G1 F1800.000 E-1.00000
30 G92 E0
31 G1 Z0.350 F7800.000
32 G1 X77.641 Y89.985
Please let me know if you have any ideas on how I can see what the slicing program is sending.
Thanks
TC
Comments
They might, but I am going to have to do some reading to fully understand how arrays work, since it needs an array pointer. I don’t like asking a question until I give my best effort to figure it out myself.
In there is a routine to build strings.
For your text, there may be hidden characters at the end of each line, either CR or LF or both.
When faced with these sorts of problems, the first thing I do is put some sort of trace on the data, and print out the ascii values of each character rather than the characters. Then you can work out what the end of line character is.
Then - say it was CRLF (13,10), you would ignore the 13, take the 10 as the end of line marker as this is the very last character on the line, and use that to call the routine in Kye's code that starts building a new string.
Then keep building until you get to ascii 13. Don't add the 13 though. The string in Kye's code will be the spin/C format of a string, with an ascii zero at the end.
Then you can start manipulating your string.
I wrote some parts of a GCODE-parser and I made an OpenOffice-Sheet to explain how bytearrays for strings work
see attachments. I haven't tested the gcode-parser lately before zipping it.
best regards
Stefan
OH WOW!! THANK YOU. I got the displat to read the serial from the host software, and I was just about to start working on the G-code, and figure out how the prop could understant it.