Jepp, that saves some Code,too. Thanks. I may try that one when I am home.
...as I said, there may be a better way ![]()
Hey Fellows,
sorry to bring that up again.
I tried the code and well, the arduino seems to be too fast.
the code above just gives about 130Bytes of the full stream and then, I suppose, the buffer is empty for a short while and the readout is being terminated
int i, k;
byte OPCSend[4] = {0x1B,0x03,0x1E,0x00}; //Start Byte (ESC); Command (3);Checksum (27+3=30),CHecksum Rest (0)
byte opc_respond[1186];void setup()//initilize IO Board
{
Serial.begin(57600); //opens serial (USB) for communication with PC
Serial2.begin(57600);//opens Serialport1 (RS232-1) for communication with CDP
}void loop()
{
int received=0;
k=0;
for(i=0;i<4;i++) // Send bytes to CDP (0x1b for start, 0x03 for PBP Mode, 0x1e and 0x00 for Checksum)
{
Serial2.write(OPCSend*);//Sending Commands Byte by Byte*
}*
//---------------Waiting for data response*
if(Serial2.available()>0) //Anything received yet?*
{*
//Serial.println("DATA"); //Check for debugging*
received=reading();*
//Serial.print(Serial2.available());*
}*
Serial.print("Received");*
Serial.println(received);*
Serial.print("in Buffer:");*
Serial.println(Serial2.available());*
delay(5000);*
}
int reading()
{while(Serial2.available() > 0 && k<1185)*
{*
opc_respond[k++]=Serial2.read();*
//delayMicroseconds(150);*
}*
return k;*
}[/quote]
The Response I get is:
Received0
in Buffer:16
Received130
in Buffer:21
Received130
in Buffer:21
Received130
in Buffer:21
when I put in the Microseconds delay it gives me:
Received1185
in Buffer:72
Received1185
in Buffer:72
which looks fine for the received bytes, but the remaining rest in the buffer is strange, because the stream only contains 1186 Bytes
The Arduino is not too fast.
If I'm reading this correctly your problem is that you're resetting "k" (and sending the command) as soon as there is no serial data avaialble, which will be quite often.