Help with Serial Communication - Please! - Page 2
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 21 of 21

Thread: Help with Serial Communication - Please!

  1. #16
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,553

    Re: Help with Serial Communication - Please!

    Quote Originally Posted by ChadReitsma View Post
    0x0018e4b4 "!ANG:0.54,2.08,-178.62
    !ANG:0.43,2.05,-178.64
    !ANG:0.44,1.96,-178.65
    "
    How can I strip out everything inside of the "s I don't need the 0x0018e4b4 etc...
    Please show the code that is outputting this result. The "0x0018e4b4" is probably the memory location where the string shown is quotes is stored. If it's simply the memory location, then there is nothing to "strip out", and you can simply use the string stored at the buffer pointed to by the memory location.

    Mike

  2. #17
    Join Date
    Apr 2012
    Posts
    18

    Re: Help with Serial Communication - Please!

    Hi Mike, yeah I figured I could do some string manipulation there - I'm so used to PHP that getting my brain working with C++ again is a little tricky, haha.

    Here's the code: szBuffer is: char[101];
    Code:
    std::string comData;
    comData = szBuffer;
    Then I use a trace to echo the value of comData into the output log...
    I've had minimal success with .substr and .find... Might have to modify the Serial port code a little more...

  3. #18
    Join Date
    Apr 2012
    Posts
    18

    Re: Help with Serial Communication - Please!

    Ok, getting a little bit further here, but these string functions aren't working... not sure what's wrong

    Here's what's up.
    I'm reading the com-port data, and storing that into a buffer.
    I strip the buffer of all unnecessary data and store that in a String that looks like this:

    std:string comData;

    and comData contains: "X:0.59Y:0.42Z:-171.80"

    So far so good... now, I need to extract the positions of X: , Y: and Z:
    So I tried doing it like this:

    Code:
    int xpos, ypos, zpos;  //(Also tried with size_t, sorry - I'm a noob)
    
    xpos = comData.find("X:");
    ypos = comData.find("Y:");
    zpos = comData.find("Z:");
    Which I would expect to return: 0, 6, 12
    But nope, C++ has stumped me again - nothing gets returned
    Last edited by ChadReitsma; April 5th, 2012 at 03:21 AM.

  4. #19
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,011

    Re: Help with Serial Communication - Please!

    Quote Originally Posted by ChadReitsma View Post
    Code:
    int xpos, ypos, zpos;  //(Also tried with size_t, sorry - I'm a noob)
    
    xpos = comData.find("X:");
    ypos = comData.find("Y:");
    zpos = comData.find("Z:");
    Which I would expect to return: 0, 6, 12
    But nope, C++ has stumped me again - nothing gets returned
    1. Please, define "nothing".
    2. I don"t see any return statement here. So what did you expect to be "returned"?
    Victor Nijegorodov

  5. #20
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,553

    Re: Help with Serial Communication - Please!

    Quote Originally Posted by ChadReitsma View Post
    ... and comData contains: "X:0.59Y:0.42Z:-171.80"
    Are you sure about this? In yesterday's post, you told us that comData contained "!ANG:0.43,2.05,-178.64", which does not contain an "X:" or "Y:" or "Z:".

    Please debug by single-stepping through the pertinent code, and confirm that all variables contain what you think they contain.

    Also, reiterating what VictorN said, define "nothing gets returned". The std::string::find function always returns something. Even if the requested content is not found, the member value npos (equal to -1) is returned.

    Mike

  6. #21
    Join Date
    Apr 2012
    Posts
    18

    Re: Help with Serial Communication - Please!

    Ah yes, sorry about that - I changed the output to contain the X,Y,Z values - and tried using find() ... still ran in to some problems, but I think I've got it figured out.

    Thanks for the help!

Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center