Exemplo n.º 1
0
 /// <summary>
 /// Return a singleton of this class.
 /// </summary>
 /// <returns>The SerialIO instance</returns>
 public static SerialIO GetInstance()
 {
     if (instance == null)
     {
         instance = new SerialIO();
     }
     return(instance);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Initialize the SerialIO instance and start the listening thread
 /// </summary>
 public void Start()
 {
     //Create setters for these properties
     SerialIO.BaudRate = 9600;
     SerialIO.PortName = CoreState.SettingsInstance.COMPort;
     SerialIO.GetInstance().Init();
     SerialIO.GetInstance().Listen();
     serialThread = new Thread(Listen);
     serialThread.Start();
 }
Exemplo n.º 3
0
 /// <summary>
 /// Listen on the serial port while the SerialIO instance is open
 /// </summary>
 private void Listen()
 {
     while (SerialIO.GetInstance().Active())
     {
         try
         {
             string msg = SerialIO.GetInstance().Read();
             InputDispatcher.PerformAction(msg);
         }
         catch (Exception e)
         {
             Console.WriteLine(e.Message.ToString()); //TODO better exceptions
         }
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Destroy the Serial instance
 /// </summary>
 public void Dispose()
 {
     SerialIO.GetInstance().Close();
 }