Skip to content

Simple OutSim & OutGauge samples

Version 0.13b is finished, just cleaning up the docs, and packaging everything (switching to sandcastle for docs kind of added a new complication). Should have that out tomorrow, I hope.

In the meantime, especially, since the Tester app I include is really just something to exercise the lib, not to learn coding from (i.e. worst winforms code patterns example), I thought i'd throw out some simple code examples until i build a proper test suite. Now, these samples, with their use of straight up static methods are also nothing to learn program design from -- they're just API illustration. These examples work with the current and new release, so they're not tied to 0.13b.

The tricky thing to note about both OutSim and OutGauge is that the cfg.txt values take precedence. I.e. you can get both sent via InSim, but not if they are already set in the configuration file. Generally, I suggest sticking to manually configuring these two and going through the dedicated handlers for both and keeping them separate from your InSim handler.

OutGauge

This little Console app, just subscribes to OutGauge being sent once a second and refreshes the terminal with the new values:

static void Main(string[] args)
{
  // Assumes the following settings in LFS cfg.txt:
  //    OutGauge Mode 1
  //    OutGauge Delay 100
  //    OutGauge IP 127.0.0.1
  //    OutGauge Port 26020
  //    OutGauge ID 1

  OutGaugeHandler outGauge = new OutGaugeHandler(26020);
  outGauge.Updated += new OutGaugeHandler.GaugeEvent(outGauge_Updated);
  Console.WriteLine("created handler");
  outGauge.Initialize();
  Console.WriteLine("initialized handlers");
  Console.WriteLine("Press RETURN to exit");
  Console.ReadLine();
  outGauge.Close();
}

static void outGauge_Updated(object sender, FullMotion.LiveForSpeed.OutGauge.Events.Gauge gauge)
{
  Console.Clear();
  Console.WriteLine("OutGauge -----------------------");
  Console.WriteLine("Time:     {0}", gauge.Time);
  Console.WriteLine("ID:       {0}", gauge.Id);
  Console.WriteLine("Car:      {0}", gauge.Car);
  Console.WriteLine("RPM:      {0}", gauge.RPM);
  Console.WriteLine("Speed:    {0}", gauge.Speed);
  Console.WriteLine("Message1: {0}", gauge.DisplayMessage1);
  Console.WriteLine("Message2: {0}", gauge.DisplayMessage2);
}

OutSim

The OutSim version is virtually the same for setup, just that the eventargs contain different data

static void Main(string[] args)
{
  // Assumes the following settings in LFS cfg.txt:
  //  OutSim Mode 1
  //  OutSim Delay 100
  //  OutSim IP 127.0.0.1
  //  OutSim Port 26010
  //  OutSim ID 1
  OutSimHandler outSim = new OutSimHandler(26010);
  outSim.Updated += new OutSimHandler.PhysicsEvent(outSim_Updated);
  Console.WriteLine("created handlers");
  outSim.Initialize();
  Console.WriteLine("initialized handlers");
  Console.WriteLine("Press RETURN to exit");
  Console.ReadLine();
  outSim.Close();
}

static void outSim_Updated(object sender, FullMotion.LiveForSpeed.OutSim.Events.PhysicsState physicsState)
{
  Console.Clear();
  Console.WriteLine("OutSim -----------------------");
  Console.WriteLine("Time:     {0}", physicsState.Time);
  Console.WriteLine("ID:       {0}", physicsState.Id);
  Console.WriteLine("X:        {0}", physicsState.PositionX);
  Console.WriteLine("Y:        {0}", physicsState.PositionY);
  Console.WriteLine("Z:        {0}", physicsState.PositionZ);
}