Hi.
I receive some UDP data on the socket. I want to receive 50 packets @ 114 bytes.
I receive the first 30 packets great and the data is OK. I think it is because of the available stack, because when I look at the socket.available there can only be 3550 bytes. If we divide this by 114 bytes (my receiving bytes) we get 31.
After the first 30 packets I only receive every third packets. So it is:
1 - 2 - 3 - … - 29 - 30 - 33 - 36 - 39 - 42 - …
And when I tried with just 30 bytes for each packets, the available buffer got smaller. About 930 when it was full…
How can I fix this problem? Can I make the available buffer bigger?
while (true)
{
while (socket.Poll(ReadCounter, SelectMode.SelectRead))
{
if (CheckEnable == 1)
{
if (socket.Available > 0)
{
socket.Receive(inBuf, inBuf.Length, SocketFlags.None);
counter++;
EthernetReceivedHandler.EthDataHandler(inBuf, socket); //This function is saving the data in a bytearray
}
}
else if (CheckEnable == 0)
{
return;
}
if (counter == 200)
{
CheckEnable = 0;
socket.Send(DisableCam, DisableCam.Length, SocketFlags.None);
EthernetReceivedHandler.Farve_ID_Handler(); //Now I can use my data
}
}
}
First I enable the camera data. Then I count to 200 and disable the camera. When the camera is disabled I can use my data.
I was thinking to make a interrupt (Event Handler). So the camera always was enabled and I could use the data anyway.
Every time I send a specific packets, I would read the last data in my byte array. Is that possible? So I don’t have to disable my camera.
The ReceiveEthernetData() is always running. So I wondered how I could turn this off when I was receiving some data. Every time I receive a packets from bluetooth, It should do a specific thing.
public static void ReceiveEthernetData()
{
while (true)
{
while (socket.Poll(ReadCounter, SelectMode.SelectRead))
{
if (socket.Available > 0)
{
socket.Receive(inBuf, inBuf.Length, SocketFlags.None);
EthernetReceivedHandler.EthDataHandler(inBuf, socket);
}
}
}
}
public Bluetooth(string COMport, int BAUD, Parity Paritet, int databit)
{
sp = new SerialPort(COMport, BAUD, Paritet, databit);
sp.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
sp.Open();
}
private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
try
{
while (sp.BytesToRead > 0)
{
for (int i = 0; i < rx_data.Length; i++)
{
rx_data[i] = 0;
}
rx_data[read_count] = (byte)sp.ReadByte();
}
}
catch (Exception ex)
{
;
}
}