This is my code. When i run this first byte is saved in tempbuf's 0th position. But when i got second byte, the first value is cleared in tempbuf :-(
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
int bytes = serialPort1.BytesToRead;
byte[] byte_buffer = new byte[200];
byte[] tempbuf = new byte[200];
byte[]tempbuf2=new byte[200];
byte[] ar = new byte[20];
byte[] ssd = new byte[4];
byte[] ctrl = new byte[20];
string pp = "";
string ll = "";
serialPort1.Read(byte_buffer, 0, bytes);
if (i == 0)
{
index = byte_buffer[0];
}
tempbuf[q++] = byte_buffer[0];
i++;
if (i == 200)
{
array[index] = TestSerializer.MarshalToStructureArray(tempbuf, tempbuf.Length);
if (textBox30.InvokeRequired)
{
this.Invoke(((MethodInvoker)delegate
{
textBox30.Text = index.ToString();
}));
}
i = 0;
}
if (q == 200)
{
q = 0;
}
qdefined and what are you using it for? Your variable names are fairly cryptic so it's hard to tell what you're trying to do.