Hello,
i want to receive some rs232 data with my pic. but i dont know how to do this.
i receive this strings.
BLAH TESTxxx.IMG
the TEST .IMG is always the same.
the blah is a text variable to activate some outputs on the pic the xxx are numbers to activate diffrent outputs also on the pic.
receive example:
BLAH TEST132.IMG
RORO TEST142.IMG
so the first 4 letters are changing and the 3 numbers are diffrent every time.
how can i readout this numbers ?
Thanx !
Silvio
rs 232 receive by pic
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Hello
The best way would be to do the following.
1. Listen for incoming characters and wait until 'T' and 'E' and 'S' and 'T' have been received in order.
2. create an array of 3 bytes or just create 3 byte variables to hold the next three incoming characters.
input[3]
or
hundreds
tens
units
3. create an int variable and load in each of the data bytes.
total = input[2] - '0'
total = total + (10 * (input[1] - '0'))
total = total + (100 * (input[0] - '0'))
or
total = units - '0'
total = total + (10 * (tens - '0'))
total = total + (100 * (hundreds - '0'))
The total variable shold now hold your three digit number.
the - '0' ( - 48 ) is used to convert the ascii number into a numeric value between 0 - 9.
The best way would be to do the following.
1. Listen for incoming characters and wait until 'T' and 'E' and 'S' and 'T' have been received in order.
2. create an array of 3 bytes or just create 3 byte variables to hold the next three incoming characters.
input[3]
or
hundreds
tens
units
3. create an int variable and load in each of the data bytes.
total = input[2] - '0'
total = total + (10 * (input[1] - '0'))
total = total + (100 * (input[0] - '0'))
or
total = units - '0'
total = total + (10 * (tens - '0'))
total = total + (100 * (hundreds - '0'))
The total variable shold now hold your three digit number.
the - '0' ( - 48 ) is used to convert the ascii number into a numeric value between 0 - 9.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 12
- Joined: Tue Oct 30, 2007 11:10 am
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Hello
I have posted an example online for you.
http://www.matrixmultimedia.com/softwar ... _Input.fcf
The example waits for the string TEST and then reads the next three characters and converts into a number. Every time the TEST is detected the number is refreshed.
I have posted an example online for you.
http://www.matrixmultimedia.com/softwar ... _Input.fcf
The example waits for the string TEST and then reads the next three characters and converts into a number. Every time the TEST is detected the number is refreshed.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel