Sending big amount of data via SoftSerial / Serial

Hi a lot
I have a problem with transmitting data through my Arduino, lets start from the beginning.
Arduino Duemilanove communicates via Software Serial with acceleration sensor. Sensor uses RS485 protocol, so I prepared converter with MAX485. Arduino sends frames of data to sensor to set measure parameters or start measure, and sensor responds. It works well, until you want to receive measure results. Sensor has its own memory - 32kB, where it stores results. After it get ‘result request’ it sends whole data in one frame so it is way bigger than buffer size. SoftwareSerial communicates at 38400 kbps, received bytes are sent by Hardware Serial to PC hyperterminal , at 57600 kbps. But unfortunately I am able to receive only 256 bytes (size of SoftwareSerial buffer) , it just overflows. I’ve tried to save bytes to array, but results were the same - I recieved only size of buffer bytes.
Increasing buffer size is pointless in my case - I have to receive much more then maximum possible bufer size. Only way is to get data from buffer when it is coming - but I have no idea how…

Thank you in advance for any help

 #include <SoftwareSerial.h>

 int pinControl = 9; // Max485 listens when LOW
 char kontrol;
 char znak;

SoftwareSerial mySerial(10, 11); // RX, TX
  
// a don't enclose all communication functions, because they have the same structure as 'odczyt' 

void odczyt(){ //request results 
  digitalWrite(pinControl,HIGH);
  delay(1);
  mySerial.flush();
  mySerial.write(58); //:
  mySerial.print("0101000114");
  mySerial.write(13); //cr
  mySerial.write(10); //lf
  delay(1);
  digitalWrite(pinControl,LOW);
}
  
 
void setup() {  
  pinMode(pinControl, OUTPUT);  
  pinMode(12, OUTPUT);
  mySerial.begin(38400);
  Serial.begin(57600);
  Serial.println("hello");
  digitalWrite(pinControl, LOW);
  digitalWrite(12, LOW); // power supply for sensor

}

  

void loop() {
 
if(Serial.available()){ //reading commands from terminal
  kontrol = Serial.read();
  Serial.println("");

  switch(kontrol){
    case 'l': // set parameters of measure 
      ustaw_parametry();
      break;
    case 's': // start measure
      startpomiaru();
      break;   
    case 'o': //rquest results from sensor 
      odczyt();
      break; 
  }
    
}


while (mySerial.available()>0){
    znak = mySerial.read();
    Serial.write(znak);

  }

}

Given your datarate to the computer is faster than from the sensor, the loop you have at the end of loop():

while (mySerial.available()>0){
    znak = mySerial.read();
    Serial.write(znak);

  }

ought to be able to keep up...

Have you tested that you can send 32k out on Serial and hyperterminal can keep up with that?

You said "38400 kbps" - I assume you didn't mean that!

void odczyt(){ //request results 
  digitalWrite(pinControl,HIGH);
  delay(1);
  mySerial.flush();
  mySerial.write(58); //:
  mySerial.print("0101000114");
  mySerial.write(13); //cr
  mySerial.write(10); //lf
  delay(1);
  digitalWrite(pinControl,LOW);
}

Two questions. First, the SoftwareSerial::flush() function empties the incoming buffer. This function only modifies the outgoing stream. Why are you throwing away random amounts of unread data?

Second, if you are having problems sending data fast enough, why the hell are you sitting on your hands doing nothing for ANY amount of time?

Thanks for answers.

Mark: yes, I have tested and terminal deals with it. I also tried to increase Serial speed - no result..
I also tried to do this in loop():

if(mySerial.overflow()){
  Serial.println("over");
}

if(mySerial.available()>0){
    znak = mySerial.read();
    Serial.write(znak);
}

and I have received on hyperterminal this:

 over
:over
FF0000F1150002FFE0FFEE0002...................

I received again 256 bytes, but as You can see buffer is full before it start to send any bits... Why? Can it be caused by using SoftwareSerial itself?

And yes, 38,4 kbps :wink:

Paul :
You are right, this flush is just useless but I think it doesn't make a mess, because I launch method 'odczyt' before sensor starts sending data. I had removed flush() and it haven't solved my problem..
I am sorry, but I don't understand what You mean in second question. I would be pleased if You could write it again, a bit easier. Thank You.