Simple ascii char question
I have a string that contains parsed data, specifically 4 ascii characters.· What I need to do is append an addition ascii character of my chosing ( char = 137 ) to serve as a termination indicator on·a·receiveing unit using Visual Basic 6.0.·· The characters must be sent as ascii format otherwise data gets lost in conversion. I'm sure it's a simple one line command but for some reason it has been eluding me.· Any help would be appreciated.
atekippe
ISU
· public static void main(){
· CPU.writePin(CPU.pin1, true);········ // enable write to pin 1 and 2
· CPU.writePin(CPU.pin2, true);
· while (count <1){···················· // WORKING
···· if(rxUart.byteAvailable()){
········ x=rxUart.receiveByte();······· // set x to incoming data if available
········ if(x>90 && x<93){············· // check that x is desired data
··········· while (buffnum<12){········ // loop until max string length is reached
················ c = (char)rxUart.receiveByte();· // write incoming data to dummy variable
················ if(buffnum==6){······· // append data if at first desired position
················ buffer.append(c);
················ }
················ if(buffnum==7){······· // append data if at second desired position
················ buffer.append(c);
················ }
················ if(buffnum==10){····· // append data if at third desired position
················ buffer.append(c);
················ }
················ if(buffnum==11){···· // append data if at forth desired position
················ buffer.append(c);
················ }
················ buffnum=buffnum+1;·· // increase position indicator by one
··········· y=137;·················· // append termination character to end of parsed string
··········· buffer.append(char(y));
··········· String s = buffer.toString();·· // convert buffer to string for output
··········· System.out.println(s);········· // output string over JIDE Port on Javelin
··········· buffnum=0;····················· // reset position indicator
··········· buffer.clear();················ // clear buffer
atekippe
ISU
· public static void main(){
· CPU.writePin(CPU.pin1, true);········ // enable write to pin 1 and 2
· CPU.writePin(CPU.pin2, true);
· while (count <1){···················· // WORKING
···· if(rxUart.byteAvailable()){
········ x=rxUart.receiveByte();······· // set x to incoming data if available
········ if(x>90 && x<93){············· // check that x is desired data
··········· while (buffnum<12){········ // loop until max string length is reached
················ c = (char)rxUart.receiveByte();· // write incoming data to dummy variable
················ if(buffnum==6){······· // append data if at first desired position
················ buffer.append(c);
················ }
················ if(buffnum==7){······· // append data if at second desired position
················ buffer.append(c);
················ }
················ if(buffnum==10){····· // append data if at third desired position
················ buffer.append(c);
················ }
················ if(buffnum==11){···· // append data if at forth desired position
················ buffer.append(c);
················ }
················ buffnum=buffnum+1;·· // increase position indicator by one
··········· y=137;·················· // append termination character to end of parsed string
··········· buffer.append(char(y));
··········· String s = buffer.toString();·· // convert buffer to string for output
··········· System.out.println(s);········· // output string over JIDE Port on Javelin
··········· buffnum=0;····················· // reset position indicator
··········· buffer.clear();················ // clear buffer
Comments
Couple of thoughts;
1) By reading from UART twice, and checking the data twice you will potentially miss odd characters.
2) To add ascii char 137 to a StringBuffer object use something similar - replace the code at the bottom of yours:
y=137; // append termination character to end of parsed string
buffer.append(char() y);
System.out.println( buffer.toString() ); // output string over JIDE Port on Javelin
buffnum=0; // reset position indicator
buffer.clear(); // clear buffer
Hope this helps,
james
atekippe