Serial Bad Data

"Ryan Garner" <[email protected]>
Newsgroups gmane.comp.hardware.microcontrollers.tini
Message-ID <001901c41b42$9ce632e0$6401a8c0@computer>
Hi,
I was never able to resovle the problem of the missing data. The only thing
i could do was to read all data byte by byte from the input stream.  The
also makes the reading much slower, so I have to stagger my serial data
sends from the external device which happens to be an amulet in my case.
I'm using the tStik with the TILT400 PRO by Systronix.  I tried the sample
code myself and found a lot of missing data when coincidentally was also
sending 20 characters at a time.

Any answers would also be appreciated.

I am doing the following to be sure to get each byte.  I do not use serial
port events for this.
    int temp = 0;
    String tString="";
//inStream is the serialconnection input stream
    while (true) {
      try {
//if input Stream available
        while (inStream.available() > 0) {
//read a byte
          temp = inStream.read();

//if data keep reading til no data left
          if (temp > 0) {
//convert byte to ascii and append new character to string
            strCmd += new Character( (char) temp).toString();
          }
}...


--------------------------------------------------------------------
Thanks for the responses,

Here is the code snippet from the SimpleReadWrite.java
I have solved the problem, and Jac and Bruno are correct in saying that the
PIC is sending the null characters, why another question as there is nothing
in the PIC Code that sends such data. (UART stopped when empty)
However, using the FileOutputStream class, I was able to spot the pattern in
the output file. The number of null characters is always equal to the buffer
size, and this can be looked for by looking for 0 byte entry in the buffer
array. No need to loop around the array.

             byte[] readBuffer = new byte[3];
                byte[] prereadBuffer = new byte[3];
                int i;
                try {
   if(in.available() >= 3){
    while (in.available() > 0) {
     int numBytes = in.read(readBuffer);
    }
   }
   if(readBuffer[0] != 0){
         current_data = current_data + (new
String(readBuffer));
   }
                }
                catch (IOException e) {
                    // Terminate handling this event on read error
                }

Anyway, this leads me to ask why cant I get the tini to receive a burst of
20 characters from the PIC, data is always lost. I think this has been asked
here before, but never answered. The PIC is sending the data as Hyperter
reads all the characters, but the Tini doesn't, regardless of buffer size.

Any final thoughts, and thanks once again.

SAIM


_______________________________________________
TINI mailing list
TINI-6tN4nzCoH/[email protected]
To UNSUBSCRIBE, edit your profile, or see list archives:
http://lists.dalsemi.com/mailman/listinfo/tini
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.