Re: Help with Serial Communication - Please!
Quote:
Originally Posted by
ChadReitsma
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
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...
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 :(
Re: Help with Serial Communication - Please!
Quote:
Originally Posted by
ChadReitsma
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 :(
- Please, define "nothing".
- I don"t see any return statement here. So what did you expect to be "returned"?
Re: Help with Serial Communication - Please!
Quote:
Originally Posted by
ChadReitsma
... 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
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! :thumb: