Hello, here is my code. I would like to send a large array to the PC.
if (commandString.equals("IMPOR")) {
digitalWrite(led2Pin, HIGH);
digitalWrite(led3Pin, LOW);
byte buf[2048];
for (int i = 0; i < 1024; i++) {
if (Serial.availableForWrite() > 2) {
byte lb = SRAM.readByte(2 * i);
byte hb = SRAM.readByte(2 * i + 1);
int16_t raw2 = word(hb, lb);
buf[2 * i] = raw2 & 255;
buf[2 * i + 1] = (raw2 >> 8) & 255;
//delay(10);
//Serial.println(raw2);
//Serial.write(lb);
//Serial.write(hb);
}
}
Serial.write(buf,sizeof(buf));
I have the following c# code:
private void SerialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
//if (!ComPort.IsOpen) return;
int bytes = 2048; // ComPort.BytesToRead;
byte[] buffer = new byte[bytes]; //Párosak a low bytok. Páratlanok a hugh byteok
ComPort.Read(buffer, 0, bytes);
int[] intbuffer = Array.ConvertAll(buffer, x => (int)x);
//int[] bdata = new int[bytes / 2];
for(int i = 0; i < 1024; i++)
{
bdata[i] = intbuffer[2 * i + 1] * 256 + intbuffer[2 * i];
}
}
Problem is that the buffer array looks like this: The first 100-200 bytes are corret, but the others are all zero. It's fully randim how much byte arrives corret. It's between 10 and 1800. I tried all standard baud rates.
Is there any idea what could be the problem. When I use Serial.println command and check the seria monitor manually all bytes arrived.