I'm developing an XPlane 11 ground control station in C# .net framework winforms. I am successfully pulling data from XPlane. However, I have a problem. Data comes via UDP. After selecting the data packets that I want to send in the Xplane interface, I start the program and only the packet with the smallest index number is transmitted from the selected packets. If I just pick a random package I can successfully see it in the c# interface. What is the reason of this?
Note: My data retrieval code is communicating with the UAV. So I don't think there is a problem in my code.
Only one packet comes from Xplane 11 data packets to C#
private UdpClient udpClient;
private IPEndPoint endPoint;
readonly byte[] ExpectedSignature = { 68, 65, 84, 65, 42 };
bool IsValidSignature = true;
byte[] receivedData;
public Form8()
{
InitializeComponent();
InitializeUdpClient();
}
private void InitializeUdpClient()
{
udpClient = new UdpClient();
endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 49001);
udpClient.Client.Bind(endPoint);
}
private void BtnGetData_Click(object sender, EventArgs e)
{
timer1.Start();
}
private void Timer1_Tick(object sender, EventArgs e)
{
byte[] data = GetData();
ShowData(data);
ResetData();
}
private byte[] GetData()
{
receivedData = udpClient.Receive(ref endPoint);
return receivedData;
}
private void ResetData()
{
receivedData = null;
}
private void ShowData(byte[] data)
{
for (int i = 0; i < ExpectedSignature.Length; i++)
{
if (data[i] != ExpectedSignature[i])
{
IsValidSignature = false;
break;
}
}
if (IsValidSignature)
{
for (int i = 0; i < data.Length; i++)
{
if (i == (data.Length - 1))
{
richTextBox1.AppendText(data[i] + "\n");
}
else
{
richTextBox1.AppendText(data[i] + ", ");
}
}
switch (data[5])//https://www.x-plane.com/kb/data-set-output-table/
{
case 1:
double realtime_value = BitConverter.ToSingle(data, 9);
Lbl_1_RealTime.Text = realtime_value.ToString();
double totaltime_value = BitConverter.ToSingle(data, 13);
Lbl_1_TotalTime.Text = totaltime_value.ToString();
double missiontime_value = BitConverter.ToSingle(data, 17);
Lbl_1_MissionTime.Text = missiontime_value.ToString();
double timertime_value = BitConverter.ToSingle(data, 21);
Lbl_1_TimerTime.Text = timertime_value.ToString();
double zulutime_value = BitConverter.ToSingle(data, 29);
Lbl_1_ZuluTime.Text = zulutime_value.ToString();
double localtime_value = BitConverter.ToSingle(data, 33);
Lbl_1_LocalTime.Text = localtime_value.ToString();
double hobbstime_value = BitConverter.ToSingle(data, 37);
Lbl_1_HobbsTime.Text = hobbstime_value.ToString();
break;
case 3:
double VindKias_value = BitConverter.ToSingle(data, 9);
Lbl_3_VindKias.Text = VindKias_value.ToString();
double VindKeas_value = BitConverter.ToSingle(data, 13);
Lbl_3_VindKeas.Text = VindKeas_value.ToString();
double VtrueKtas_value = BitConverter.ToSingle(data, 17);
Lbl_3_VtrueKtas.Text = VtrueKtas_value.ToString();
double VtrueKtgs_value = BitConverter.ToSingle(data, 21);
Lbl_3_VtrueKtgs.Text = VtrueKtgs_value.ToString();
double VindMph_value = BitConverter.ToSingle(data, 29);
Lbl_3_VindMph.Text = VindMph_value.ToString();
double VtrueMphas_value = BitConverter.ToSingle(data, 33);
Lbl_3_VtrueMphas.Text = VtrueMphas_value.ToString();
double VtrueMphgs_value = BitConverter.ToSingle(data, 37);
Lbl_3_VtrueMphgs.Text = VtrueMphgs_value.ToString();
break;
}
}
else
{
IsValidSignature = true;
}
}