Serial read from a machine protocol. Anyone please help

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.

Is your machine using RS232? If so then you need to convert it into TTL levels before you feed it into the arduino.

Have you got the baud rate and data format matching on the two devices.

Grumpy_Mike: Is your machine using RS232? If so then you need to convert it into TTL levels before you feed it into the arduino.

Have you got the baud rate and data format matching on the two devices.

Thanks Grumpy, I have finished that part, right now the problem is how can I extract the measured number from the receive protocol.

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.

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.

lovemachinez:

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.

have no idea for extracting those measured number

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 ;)

lovemachinez: 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.

This may help decoding incoming serial:

http://www.gammon.com.au/serial

Inside is mentioned a "state machine" which could be useful in your case.

If that doesn't help, post what code you have.

michael_x:

have no idea for extracting those measured number

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 ;)

Thank you very much.

[quote author=Nick Gammon link=topic=103450.msg776496#msg776496 date=1335649010]

lovemachinez: 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.

This may help decoding incoming serial:

http://www.gammon.com.au/serial

Inside is mentioned a "state machine" which could be useful in your case.

If that doesn't help, post what code you have. [/quote]

WOW! That was I looking for. Thank you very much

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.