Need help (sample code) to convert text string to integer, compare with a table of values
Akbar
Posts: 3
Problem statement. Need to convert text string to integer, compare them to a table of 14 resistors (rows) with +/-5% tolerance and provide pass or fail result.
Input: From Digital voltmeter (DVM), (14 bytes (time=16msec) at 9600 baud every 720 msec.) as a resistance value in Ohms, in to propeller board.
Input format: Data is format is like (“+0104 3! NULL NULL SPACE NULL CR LF”) Resistance value in Ohms. 3! Is where decimal point need to get inserted into the 4 digit number to become 010.4 Ohms.
Software used: full-duplex_test.spin and full_duplex Communication Engin.spin,
Hardware setup: DVM RS232(Tx) goes to Propeller Rx, then propeller Tx goes to Rx of pc Parallax serial terminal, during the test.
What I got so far: Data from DVM comes to propeller, I remove the "+" from the string, by advancing the address and send the string to Parallax serial terminal now I get 0104 3! ohms.
result := com0.readString(@data, 9) ' wait till string arrive read 9 characters of it (+0104 3!null)(0 terminated string)
com0.writeString(result + 1) ' advance pointer to remove "+" in front of the number.
What it need to be done:
1. I tried many thing to insert the decimal point Into 4 digit base number to get 010.4 Ohms, still got problem. DVM always give 4 digit with decimal point insertion separate like 1!, 2!, 3!. We need to generate fraction number for next steps.
2. I need to make a table with 14 rows and 3 columns. Rows are 14 given resistance, columns (A=resistance value), Column (B= +5% of calculate of column A), Column (C= -5% of calculated value of column A). We could have a one column table if we could calculate the +/- tolerance’s mathematically during the process.
3. Then we can produce a result if DVM reading is in range or not, and report a result over RS232.
Input: From Digital voltmeter (DVM), (14 bytes (time=16msec) at 9600 baud every 720 msec.) as a resistance value in Ohms, in to propeller board.
Input format: Data is format is like (“+0104 3! NULL NULL SPACE NULL CR LF”) Resistance value in Ohms. 3! Is where decimal point need to get inserted into the 4 digit number to become 010.4 Ohms.
Software used: full-duplex_test.spin and full_duplex Communication Engin.spin,
Hardware setup: DVM RS232(Tx) goes to Propeller Rx, then propeller Tx goes to Rx of pc Parallax serial terminal, during the test.
What I got so far: Data from DVM comes to propeller, I remove the "+" from the string, by advancing the address and send the string to Parallax serial terminal now I get 0104 3! ohms.
result := com0.readString(@data, 9) ' wait till string arrive read 9 characters of it (+0104 3!null)(0 terminated string)
com0.writeString(result + 1) ' advance pointer to remove "+" in front of the number.
What it need to be done:
1. I tried many thing to insert the decimal point Into 4 digit base number to get 010.4 Ohms, still got problem. DVM always give 4 digit with decimal point insertion separate like 1!, 2!, 3!. We need to generate fraction number for next steps.
2. I need to make a table with 14 rows and 3 columns. Rows are 14 given resistance, columns (A=resistance value), Column (B= +5% of calculate of column A), Column (C= -5% of calculated value of column A). We could have a one column table if we could calculate the +/- tolerance’s mathematically during the process.
3. Then we can produce a result if DVM reading is in range or not, and report a result over RS232.
Comments
dgately
This gives you integer values, that can easy be compared to a table.
Here is a testcode with methodes you can use in your code:
Andy