convert string of bytes to int
i sending arduino serial data , adding bytes array, string of values single integer. say ive got array [2, 2, 0] ... need 220 int
i found tom igoes example "web scraping" ... , similar how approaching it, thought needed ... http://www.tigoe.net/pcomp/code/archives/arduino/000761.shtml ... here using
from igoe
if (status == reading) {
if (serial.available()) {
inbyte = serial.read();
// keep reading until ">":
if (inbyte != 62) {
// save ascii numeric characters:
if ((inbyte >= 48) && (inbyte <= 57)){
instring[stringpos] = inbyte;
stringpos++;
}
}
else {
// convert string numeric value:
int airquality = stringtonumber(instring, stringpos);
// set meter appropriately:
setmeter(airquality);
status = disconnected;
from can tell looks method stringtonumber(), need when try implement @ compile, im told function not declared, assuming because not part of 007 ... browse through class reference processing doesn't turn either, turn parseint() seems same functionality, same error.
so wondering if missing library, or if doing wrong? i didtn see includes in igoes app?
my code
void simocc() {
while (serial.available() > 0) {
//read incoming byte
incomingbyte = serial.read();// store first byte in temp 1
//if incoming byte "a"
if (incomingbyte == 65) {
//read next byte , store in incomingid
incomingid = serial.read();// store second byte in temp 2
//read next 3 bytes , stroe in buffer
incomingstring[0] = serial.read();// store first byte of value in string
incomingstring[1] = serial.read();// store second byte of value in string
incomingstring[2] = serial.read();// store third byte of value in string
//convert buffer usable integer
lengthofdelay = stringtonumber(incomingstring);//to replaced simocc_parse();
}
} // end while
serial.flush();// flush serial
}
of course suggestions better process appreciated. i using cserial library send data win32 app, need able periodically send arduino series of value pairs (value id (single byte fine), value (prefer unlimited bytes limit if necessary). thanks help
i found tom igoes example "web scraping" ... , similar how approaching it, thought needed ... http://www.tigoe.net/pcomp/code/archives/arduino/000761.shtml ... here using
from igoe
if (status == reading) {
if (serial.available()) {
inbyte = serial.read();
// keep reading until ">":
if (inbyte != 62) {
// save ascii numeric characters:
if ((inbyte >= 48) && (inbyte <= 57)){
instring[stringpos] = inbyte;
stringpos++;
}
}
else {
// convert string numeric value:
int airquality = stringtonumber(instring, stringpos);
// set meter appropriately:
setmeter(airquality);
status = disconnected;
from can tell looks method stringtonumber(), need when try implement @ compile, im told function not declared, assuming because not part of 007 ... browse through class reference processing doesn't turn either, turn parseint() seems same functionality, same error.
so wondering if missing library, or if doing wrong? i didtn see includes in igoes app?
my code
void simocc() {
while (serial.available() > 0) {
//read incoming byte
incomingbyte = serial.read();// store first byte in temp 1
//if incoming byte "a"
if (incomingbyte == 65) {
//read next byte , store in incomingid
incomingid = serial.read();// store second byte in temp 2
//read next 3 bytes , stroe in buffer
incomingstring[0] = serial.read();// store first byte of value in string
incomingstring[1] = serial.read();// store second byte of value in string
incomingstring[2] = serial.read();// store third byte of value in string
//convert buffer usable integer
lengthofdelay = stringtonumber(incomingstring);//to replaced simocc_parse();
}
} // end while
serial.flush();// flush serial
}
of course suggestions better process appreciated. i using cserial library send data win32 app, need able periodically send arduino series of value pairs (value id (single byte fine), value (prefer unlimited bytes limit if necessary). thanks help
parseint() java function, isn't available in c/c++ arduino uses. you can try atoi(), c equivalent. you'll need make sure there's 0 byte @ end of array of characters, (e.g. incomingstring[3] = 0; ). then call lengthofdelay = atoi(incomingstring); .
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > convert string of bytes to int
arduino
Comments
Post a Comment