well, I am new in arduino. so anyone can give me an example I would be appreciated much.
I have a machine that use serial protocol to get the measurement data from it. The protocol was attatched below:
My problem is after I sent the "M|E|S|CR|LF" via serial port to the machine, the machine give me back with a number of unknown letter.
I only want to extract the number (for example 5000 as in attatched) from the receive bytes. also I found out that the receive bytes have a lot of white space, does arduino has any function to do with it, to trim it out I just need the number left.
Thank you in advance, if anyone give some example would help me much.
btw, sorry for my english if you do not understand it all.
Grumpy_Mike:
I thought that the problem you were having is that the numbers don't make sense.
If you are having trouble with your code then please post it.
Well, I have got that receive protocol but have no idea for extracting those measured number. any suggested idea would help. Thank you very much. Refer to my attatchment, please see the received side.
Grumpy_Mike:
I thought that the problem you were having is that the numbers don't make sense.
If you are having trouble with your code then please post it.
Well, I have got that receive protocol but have no idea for extracting those measured number. any suggested idea would help. Thank you very much. Refer to my attatchment, please see the received side.
At the moment you haven't explained what problem you're trying to solve and you still haven't answered Grumpy_Mike's request for you to post the code that is giving you the problem.
My guess from what you've said is that you can successfully send commands and receive the expected response but you don't understand how to parse the response string to get the numeric values out of it. That's only a guess, though. You need to make it clear what the problem is, if you're having trouble parsing a string then provide an example of the string that you need to have parsed and show us your existing code that is intended to process it.
I have lots of ideas and it's pretty easy in your case:
You know that the response ends with CR LF
You know that the response is 12 characters + CR LF
You know which character contains what
There is a function called sscanf : google it and see if that helps you.
Alternatively:
characters representing decimal digits are coded one after the other
If you calculate '5' - '0' the result is the integer number 5 etc. ( characters are in single quotes )
Hope now you have some ideas as well. Come back when stuck
I have lots of ideas and it's pretty easy in your case:
You know that the response ends with CR LF
You know that the response is 12 characters + CR LF
You know which character contains what
There is a function called sscanf : google it and see if that helps you.
Alternatively:
characters representing decimal digits are coded one after the other
If you calculate '5' - '0' the result is the integer number 5 etc. ( characters are in single quotes )
Hope now you have some ideas as well. Come back when stuck
So is this machine a measuring tool such as micrometer or caliper? Because if it is, we have already had someone work it through just last year. IIRC his was a Mitutoyo micrometer.