The online racing simulator
outgauge rpm
(10 posts, started )
outgauge rpm
I use the insim library for c# and i'm trying to make a panel with gauges.
But the rpm doesn increase. I tried with a while loop, but the same thing.
private void button1_Click(object sender, EventArgs e)
{

/// Create timeout interval.
TimeSpan timeout = TimeSpan.FromSeconds(1);

// Create OutGauge object with the specified timeout.
using (OutGauge outgauge = new OutGauge(timeout))
{
// Attach event handler to packet-received event.
outgauge.PacketReceived += new EventHandler<OutGaugeEventArgs>(outgauge_PacketReceived);
outgauge.TimedOut += new EventHandler(outgauge_TimedOut);

// Start listening for packets from LFS.
outgauge.Connect("127.0.0.1", 30000);

}
}
static void outgauge_TimedOut(object sender, EventArgs e)
{
MessageBox.Show("OutGauge timed out!");
}
private void outgauge_PacketReceived(object sender, OutGaugeEventArgs e)
{
// Handle packet.
float FValue = e.RPM;
int FValue1 = Convert.ToInt16(FValue);
string final = Convert.ToString(FValue1);
if (FValue > 0)
{
while (true)
{
label1.Text = final;
}
}
}

This is not correct.

if (FValue > 0)
{
while (true)
{
label1.Text = final;
}
}

If you do it like this, the event handler gets stuck in an infinite loop. You should use

private void outgauge_PacketReceived(object sender, OutGaugeEventArgs e)
{
// Handle packet.
float FValue = e.RPM;
string RpmText = Convert.ToString(Convert.ToInt16(FValue));
label1.Text = RpmText;
}

BTW, You should not be checking for the OutGauge timeout. OutGauge uses UDP packets which should be expected to not arrive because there are no checking mechanisms used. Also, if a car is in the pits, no OutGauge packets are sent which could also trigger a timeout.
It gets stucked when i press the start button. It takes the value (eg. 950) and it doesn't update it.
Have you tried my code? Does it behave the same?

Can you use the simplest event handler possible and do something like Console.WriteLine("OutGauge packet received") to check that you're really getting the packets?
Yes i tried it.

And yes, i did it also with the Console.WriteLine as in the example on insim.net. With this method i receive the packets, but i need it in the Forms mod.
I'm no C# expert, but it might be that you're declaring the OutGague object locally in the button1_Click method. Declare a global OutGague object and only set it up when the button is clicked.
Yeah, the OutGauge object is local to that method, so it gets disposed before the method exits. Also the label is being updated from a different thread from the UI, so Windows won't like that. Need to invoke the label text update onto the UI thread.

private OutGauge outgauge = new OutGauge();

private void button1_Click(object sender, EventArgs e)
{
// Attach event handler to packet-received event.
outgauge.PacketReceived += new EventHandler<OutGaugeEventArgs>(outgauge_PacketReceived);
outgauge.TimedOut += new EventHandler(outgauge_TimedOut);

// Start listening for packets from LFS.
outgauge.Connect("127.0.0.1", 30000);
}

static void outgauge_TimedOut(object sender, EventArgs e)
{
MessageBox.Show("OutGauge timed out!");
}

private void outgauge_PacketReceived(object sender, OutGaugeEventArgs e)
{
// Handle packet.
float FValue = e.RPM;
int FValue1 = Convert.ToInt16(FValue);
string final = Convert.ToString(FValue1);
if (FValue > 0)
{
Invoke(new Action(()=> label1.Text = final));
}
}

Thanks DarkTimes. I made the program. Now i have to put in the left functions and after that i'll put it on the forum.
Glad to know increasing scope of outGage as an instance variable worked, btw there are many gauges present at http://www.lfsforum.net/showthread.php?t=26643

I hope your work won't be redundant from a community perpective. So try to make it unique by giving it your own spin on it, when you release. But that said, of course one should continue to learn and explore by themselves anyways So good luck
...Even if I don't know what you may have in mind, I cross my fingers (& toes ) that you could maybe give us some "improvements" to the existing .dll addon (better talk about re-do).
If not, consider this as a "soft" mayday.

outgauge rpm
(10 posts, started )
FGED GREDG RDFGDR GSFDG