LFSLib.NET 0.13b released
Now with full patch X goodness!
This version of LFSLib.NET takes advantage of all the new features of Live For Speed S2 0.5X (as well as the X2 test patch additions). The new version can be found here and the release notes are here. There is a new binary distro with a winforms Tester app, which is located here, but in general the tester app does not provide full coverage and will eventually be replaced with a better example and test harness. The highlights are:
- TCP connections (more on that below)
- Multiple InSim Connections at the same time
- Custom Button system
- Lots more tracking events
I've run it through its paces, but as InSim coverages is getting quite large now and I don't have an automated test suite, I cannot claim to have full test coverage. In general, if something doesn't work, assume it's LFSLib.NET, not LFS and let me know. Contact me via the email on the left, blog comments or posting about LFSLib.NET on the LFS programmer forums (which I monitor fairly consistently).
Moving the documentation to SandCastle has taken more time than I hoped. The new doc system is now a dynamic web application and provides a (IMHO) much improved interface thanks to Dave Sexton's excellent DocProject. This has required my moving of the docs off this server to a new host, so the docs and future information for LFSLib.NET from now on lives at lfs.fullmotionracing.com.
About TCP & UDP
A quick note about TCP and UDP in 0.13b. You can have up to 8 TCP connections, but you still can only have one UDP connection. When you configure the
InSimHandler, set the
UseTCP flag in the
configuration. In general, you want to make sure that you do NOT set
ReplyPort. Why? As soon as you set reply port, LFS will send
RaceTrackNodelap (IS_NLP) and
RaceTrackMultiCarInfo (IS_MCI) events via that port on UDP. LFSLib.NET handles that transparently, but since you've now crossed over into UDP land, you have now used up that one UDP connection that is available and things will get wonky if you connect another InSimHandler with the same settings, even though you thought you were just using TCP.
Labels: .net, c#, InSim, LFS, LFSLib.NET, live for speed, OutGauge, OutSim
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);
}
Labels: LFS, LFSLib.NET, live for speed, OutGauge, OutSim