Page 1 of 1

rs 232 receive by pic

Posted: Mon Nov 05, 2007 4:26 pm
by silviodanceclub
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

Posted: Mon Nov 05, 2007 5:45 pm
by Benj
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.

Posted: Tue Nov 06, 2007 9:29 am
by silviodanceclub
Hello,

I`m sorry but i dont get this working rigt. is there some one who can make me a small example ?

thanx ! silviodanceclub (a) hotmail. com

Posted: Tue Nov 06, 2007 12:27 pm
by Benj
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.

Posted: Sat Nov 10, 2007 9:10 pm
by silviodanceclub
Thanx ! i`ll check it out !