Shop OBEX P1 Docs P2 Docs Learn Events
How do I read a string? — Parallax Forums

How do I read a string?

TCTC Posts: 1,019
edited 2013-05-12 05:30 in Propeller 1
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 don’t 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:
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

  • kuronekokuroneko Posts: 3,623
    edited 2013-05-10 18:17
    Do PST's StrIn/StrInMax methods sound reasonable? You provide the buffer and (for StrInMax) a length limit. Unfortunately(?) the delimiter is hardwired to CR but that may be sufficient.
  • TCTC Posts: 1,019
    edited 2013-05-10 18:39
    kuroneko wrote: »
    Do PST's StrIn/StrInMax methods sound reasonable? You provide the buffer and (for StrInMax) a length limit. Unfortunately(?) the delimiter is hardwired to CR but that may be sufficient.

    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.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2013-05-11 18:40
    I've used Kye's string object a lot http://obex.parallax.com/object/579

    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.
  • StefanL38StefanL38 Posts: 2,292
    edited 2013-05-11 21:25
    Hi TC,

    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
  • TCTC Posts: 1,019
    edited 2013-05-12 05:30
    StefanL38 wrote: »

    I wrote some parts of a GCODE-parser and I made an OpenOffice-Sheet to explain how bytearrays for strings work
    see attachments.
    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.
Sign In or Register to comment.