isolating sections of string
in
Programming Questions
•
10 months ago
When i read from the serial port i get the response in the format "Read 00 00 00 " (this is because of the usb/serial conversion tool i am using) where i need actual returned values (in this case 00 00 00) i have been using the substring command coupled with the length of the returned string and some maths to do this.
- readTarget(); //see what it returns
String ssdata1 = myString.substring(L1 - 6); // take the last 6 bytes to clear all the response text from the usbio ie "spi read" etc
data11=int(ssdata1);
where readTarget() is the serial read and L1 is the length of the read string such as below
- void readTarget(){
csn(01); //chip enable/select config subroutine
myPort.write("SPITX 00\n");
countdelay(5);
myPort.readBytes(byteBuffer); //get bytes of data
myString = new String (byteBuffer); //get values and put them into a string
L1 = myString.length(); //work out length of response
csn(05);
}
-
the question is: is there a better/more reliable way of doing the same thing?
-
also my formatting doesnt seem to be correct as i never get consistant strings (if you have any ideas on how to solve i would be most interested) ie:
0
RTPRT 5
Read 00 00 0
0
ReadWRTPRT 5
Rea
0
RTPRT 5
Read 000 00
0
5
Read 00 00 00W
0
T 5
Read 00 00 00
0
SPI ReadWRTPRT 5
1