using System;
namespace MiCom2022_MIBL
{class HMS_MiCom2022_MIBL
 {static void Main()
  {    
   Console.WriteLine(">HMS_MiCom2022_MIBL.exe  ==> how to use MiCom_v2022 for MIBL driver");
   Console.WriteLine(">Usage : HMS_MiCom2022_MIBL.exe   \"ComName\"   \n");
   
   Midi_Ingenierie.MiComm_2022 myCom = new Midi_Ingenierie.MiComm_2022();

   Console.WriteLine(">here after , myCom is the instance type of MiCom_2022.\n");
            
   Console.WriteLine(">first check  : version and copyright");
   Console.WriteLine("myCom.Get_Info('IDENTITY') = " + myCom.Get_Info("IDENTITY"));
   Console.WriteLine();

   Console.WriteLine(">looking for the comName arg in the command line");
   string ComName;
   string[] args = Environment.GetCommandLineArgs();
   if (args.Length > 1)
   {
    Console.WriteLine(">" + args[1] + " found , so ComName = " + args[1]);
    ComName = args[1];
   }
   else
   {
    Console.Write(">no ComName founded , input a comName :");
    ComName = Console.ReadLine();
   }

   Console.WriteLine() ;
   Console.WriteLine(">method Open = select DRIVER,PortCOM and baudrate");
   int Cr = myCom.Open("MIBL", ComName, "115200");
   Console.WriteLine("myCom.Open('MIBL','" + ComName +  "',115200') = 0x" + Cr.ToString("X4"));
   if (Cr > 0x8000)
   {
     Console.WriteLine(">Bad Cr !!! : Check the ComName");
     Console.Write(">[ESC] close the program"); Console.ReadKey();
     return;
   }
   Console.WriteLine();

   Console.WriteLine(">method Send  = send a command / requete to the driver (MIBL)");
   Cr = myCom.Send("R00");
   Console.WriteLine("myCom.Send(\'R00') " + " Cr= 0x" + Cr.ToString("X4"));
   Console.WriteLine(">property Reponse = the last driver (MIBL) response");
   Console.WriteLine("myCom.Reponse = " + myCom.Reponse);
   Console.WriteLine();
            
   myCom.Send("X00");
   Console.WriteLine("myCom.Send(\"X00\") a bad command !"); 
   Console.WriteLine(">property Status = the last Status");
   Console.WriteLine("myCom.Status  = 0x" + myCom.Status.ToString("X4"));
   Console.WriteLine("myCom.Reponse = " + myCom.Reponse);

   Console.WriteLine();
   Console.Write("[ESC] All is done ,close the program"); Console.ReadKey();
  }
 }
}
