static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Usage: decode.exe <filename>"); return; } try { // Attempt to open .FIT file fitSource = new FileStream(args[0], FileMode.Open); Console.WriteLine("Opening {0}", args[0]); //Attempt to create an output file String fileName = String.Format("{0}.csv", args[0].Split('.')); //Strip off the first part of the file name FileStream fs = new FileStream(fileName, FileMode.Create); // First, save the standard output. StreamWriter sw = new StreamWriter(fs); sw.AutoFlush = true; Console.SetOut(sw); } catch (Exception ex) { Console.WriteLine("DecodeDemo caught Exception: " + ex.Message); return; } Decode decodeDemo = new Decode(); BufferedMesgBroadcaster mesgBroadcaster = new BufferedMesgBroadcaster(); // Connect the Broadcaster to our event (message) source (in this case the Decoder) decodeDemo.MesgEvent += mesgBroadcaster.OnMesg; decodeDemo.MesgDefinitionEvent += mesgBroadcaster.OnMesgDefinition; // Subscribe to message events of interest by connecting to the Broadcaster mesgBroadcaster.MesgEvent += new MesgEventHandler(OnMesg); IMesgBroadcastPlugin plugin = new HrToRecordMesgBroadcastPlugin(); mesgBroadcaster.RegisterMesgBroadcastPlugin(plugin); // Process the file try { //Attempt to decode the file Console.WriteLine("Type,Local Number,Message,Field 1,Value 1,Units 1,Field 2,Value 2,Units 2,Field 3,Value 3,Units 3,Field 4,Value 4,Units 4,Field 5,Value 5,Units 5,Field 6,Value 6,Units 6"); decodeDemo.Read(fitSource); mesgBroadcaster.Broadcast(); } catch (FitException ex) { Console.WriteLine("DecodeDemo caught FitException: " + ex.Message); } fitSource.Close(); return; }
static void Main(string[] args) { StreamWriter sw; if (args.Length != 1) { Console.WriteLine("Usage: ThreeDSensorAdjustmentPluginExample.exe <filename>"); return; } try { // Attempt to open .FIT file fitSource = new FileStream(args[0], FileMode.Open); Console.WriteLine("Opening {0}", args[0]); //Attempt to create an output file string fileName = String.Format("{0}.csv", args[0].Split('.')); //Strip off the first part of the file name FileStream fs = new FileStream(fileName, FileMode.Create); // First, save the standard output. sw = new StreamWriter(fs); sw.AutoFlush = true; Console.SetOut(sw); } catch (Exception ex) { Console.WriteLine("ThreeDSensorAdjustmentPluginExample caught Exception: " + ex.Message); return; } Decode decodeDemo = new Decode(); BufferedMesgBroadcaster mesgBroadcaster = new BufferedMesgBroadcaster(); // Connect the Broadcaster to our events (message) source (in this case the Decoder) decodeDemo.MesgEvent += mesgBroadcaster.OnMesg; decodeDemo.MesgDefinitionEvent += mesgBroadcaster.OnMesgDefinition; //Subscribe to the message events of the interest by connecting to the Broadcaster mesgBroadcaster.MesgEvent += OnMesg; IMesgBroadcastPlugin plugin = new ThreeDSensorAdjustmentPlugin(); mesgBroadcaster.RegisterMesgBroadcastPlugin(plugin); try { //Writing headers for columns int maxFieldNum = 9; Console.Write("Type,Local Number,Message,"); for (int i = 1; i <= maxFieldNum; i++) { Console.Write("Field {0},Value {0},Units {0},", i); } Console.WriteLine(); //Attempting to Decode the file decodeDemo.Read(fitSource); mesgBroadcaster.Broadcast(); } catch (FitException ex) { Console.WriteLine("ThreeDSensorAdjustmentPluginExample caught Exception: decoding threw a FitException: " + ex.Message); } fitSource.Close(); sw.Close(); return; }