static void Main(string[] args) { Console.WriteLine(".NETCore Console"); Console.WriteLine("SampleThreads_C#"); Console.WriteLine("--------------------"); Console.WriteLine("Library Version: " + iIDReaderLibrary.Version.LibraryVersion); //Get SpcInterfaceControl instance SpcInterfaceControl spcIntControl = Console_InitializeSpcInterfaceControl(); if (spcIntControl != null) { //SpcInterfaceControl is initialized AddConsoleLines(); //Check cyclically if key pressed bool exit = false; while (!exit) { var key = Console.ReadKey(); switch (key.Key) { case ConsoleKey.R: SendReadRequest(spcIntControl); break; case ConsoleKey.W: SendWriteRequest(spcIntControl); break; case ConsoleKey.X: exit = true; break; } Thread.Sleep(500); } spcIntControl.Terminate(); Console.WriteLine(""); Console.Write("EXITING in 5"); Thread.Sleep(1000); Console.Write(", 4"); Thread.Sleep(1000); Console.Write(", 3"); Thread.Sleep(1000); Console.Write(", 2"); Thread.Sleep(1000); Console.Write(", 1"); Thread.Sleep(1000); } }
private static SpcInterfaceControl Console_InitializeSpcInterfaceControl() { Console.WriteLine("== Select initialize parameters =="); //Get PortType int portType = Console_InitializePortType(); string portName = ""; switch (portType) { case 0: case 2: //For Serial & bluetooth, PortName needed. portName = Console_InitializePortName(); break; } //Initialize InterfaceCommunicationSettings class var readerPortSettings = InterfaceCommunicationSettings.GetForSerialDevice(portType, portName); //Parameters selected --> Initialize class instance Console.WriteLine(""); SpcInterfaceControl result = new SpcInterfaceControl(readerPortSettings, "", "\r\n"); Console.WriteLine(string.Format("Selected parameters: PortType: {0} | PortName: {1}", portType, portName)); //Call initialize to open the communication port result.InitializeCompleted += SpcInterfaceControl_InitializeCompleted; result.StartInitialize(); Console.Write("Initializing..."); //For demo purposes, just wait blocking execution until "Initialize" process is completed (notified using "InitializeCompleted" event) while (!initializeCompleted) //Alternative, call "IsInitializing" { Thread.Sleep(100); Console.Write("."); } Console.WriteLine(""); if (result.IsInitialized) { Console.WriteLine("\tInitialized"); result.RawDataReceived += SpcInterface_RawDataReceived; result.ReaderHeartbeatReceived += SpcInterface_ReaderHeartbeatReceived; return(result); } else { //Initialization failed: Terminate class instance & try again Console.WriteLine("\tInitialize failed"); result.Terminate(); return(Console_InitializeSpcInterfaceControl()); } }
static async void MainAsync() { Console.WriteLine(".NETCore Console"); Console.WriteLine("SampleThreads_C#"); Console.WriteLine("--------------------"); Console.WriteLine("Library Version: " + iIDReaderLibrary.Version.LibraryVersion); //Get SpcInterfaceControl instance SpcInterfaceControl spcIntControl = Console_InitializeSpcInterfaceControl(); if (spcIntControl != null) { //SpcInterfaceControl is initialized Console.WriteLine(""); Console.Write("Waiting for Heartbeat..."); var heartbeat = await spcIntControl.GetHeartbeatAsync(); if (heartbeat != null) { Console.WriteLine(""); Console.WriteLine("Detected Reader:"); ShowHeartbeat(heartbeat); } //Reader info obtained --> execute functions using menu Console.WriteLine(""); while (await Console_ExecuteAndContinueAsync(spcIntControl)) { Thread.Sleep(500); } spcIntControl.Terminate(); Console.WriteLine(""); Console.Write("EXITING in 5"); Thread.Sleep(1000); Console.Write(", 4"); Thread.Sleep(1000); Console.Write(", 3"); Thread.Sleep(1000); Console.Write(", 2"); Thread.Sleep(1000); Console.Write(", 1"); Thread.Sleep(1000); } m_Completed = true; }
private static SpcInterfaceControl Console_InitializeSpcInterfaceControl() { Console.WriteLine("== Select initialize parameters =="); //Get PortType int portType = Console_InitializePortType(); string portName = ""; switch (portType) { case 0: case 2: //For Serial & bluetooth, PortName needed. portName = Console_InitializePortName(); break; } //Initialize InterfaceCommunicationSettings class var readerPortSettings = InterfaceCommunicationSettings.GetForSerialDevice(portType, portName); //Parameters selected --> Initialize class instance Console.WriteLine(""); SpcInterfaceControl result = new SpcInterfaceControl(readerPortSettings, "", "\r\n"); Console.WriteLine(string.Format("Selected parameters: PortType: {0} | PortName: {1}", portType, portName)); //Call initialize to open the communication port Console.Write("Initializing..."); Console.WriteLine(""); if (result.Initialize()) { Console.WriteLine("\tInitialized"); return(result); } else { //Initialization failed: Terminate class instance & try again Console.WriteLine("\tInitialize failed"); result.Terminate(); return(Console_InitializeSpcInterfaceControl()); } }