Exemplo n.º 1
0
    static void Main(string[] args)
    {
        _parser = new YourDataParser();
        var serial = new SerialService("COM1");

        serial.DataReceived += serial_DataReceived;
    }
Exemplo n.º 2
0
        public Form1()
        {
            InitializeComponent();
            sys_option option = new sys_option()
            {
                PortName = "COM4"
            };

            s = SerialService.CreateInstance(option);
            s.Receive_Result += S_Receive_Result;
            s.Event_Msg      += S_Event_Msg;
            s.Init();

            foreach (var item in Enum.GetValues(typeof(Torque.Common.Common.TorqueUnit)))
            {
                this.ddl_unit.Items.Add(new
                {
                    name = item.ToString(),
                    code = Convert.ToInt32(item)
                });
            }

            this.ddl_unit.DisplayMember = "name";
            this.ddl_unit.ValueMember   = "code";
        }
Exemplo n.º 3
0
 public void Stop()
 {
     if (IsInitialize)
     {
         SerialService.UnRegister(CommDataObserver);
         SerialService.Stop();
     }
     IsInitialize = false;
 }
Exemplo n.º 4
0
 /// <summary>
 ///  初始化串口数据服务
 /// </summary>
 /// <param name="configure">通信参数</param>
 /// <returns>成功or失败</returns>
 private bool CreateSerialService(BasicConf configure)
 {
     _serialPort = new SerialPort(configure.GetCommGPS(), int.Parse(configure.GetGPSDataRate()));
     if (!SerialService.Init(_serialPort) || !SerialService.Start())
     {
         return(false);
     }
     SerialService.Register(CommDataObserver);
     return(true);
 }
Exemplo n.º 5
0
        private async Task <bool> LoadInstrumentOutputs()
        {
            _serial = await SerialService.InitializeAsync();

            var instruments = _serial.AvailableInstruments;

            foreach (var instrument in instruments)
            {
                ddbInstruments.DropDownItems.Add(instrument.Name);
            }
            return(true);
        }
Exemplo n.º 6
0
 static public void StartServer(string ipaddr, int portno, MemoryFifo in_fifo, MemoryFifo out_fifo)
 {
     if (SerialServer.server != null)
     {
         throw new InvalidOperationException();
     }
     SerialServer.server = new Server
     {
         Services = { SerialService.BindService(new SerialServer(in_fifo, out_fifo)) },
         Ports    = { new ServerPort(ipaddr, portno, ServerCredentials.Insecure) }
     };
     server.Start();
 }
Exemplo n.º 7
0
        public ucConnect()
        {
            InitializeComponent();

            timeOutTimer          = new Timer();
            timeOutTimer.Interval = 2000;
            timeOutTimer.Tick    += timeOutTimer_Tick;

            commandList            = new List <string>();
            serial                 = SerialService.GetInstance();
            serial.OnConnected    += serial_OnConnected;
            serial.OnConnectError += serial_OnConnectError;
            serial.OnDataReceived += serial_OnDataReceived;
            serial.OnDisconnected += serial_OnDisconnected;
            serial.OnLog          += serial_OnLog;
        }
Exemplo n.º 8
0
        public void SyncSerialPowerStatus()
        {
            bool master, fan, motor, laser;

            master = fan = motor = laser = false;
            try
            {
                SerialService.ParsePowerCode(_serialService.ReadPower(), out master, out fan, out motor, out laser);
            }
            catch (Exception e)
            {
                //ignored
            }
            Status.FanPowerStatus.IsPowered    = fan;
            Status.MasterPowerStatus.IsPowered = master;
            Status.MotorPowerStatus.IsPowered  = motor;
            Status.LaserPowerStatus.IsPowered  = laser;
        }
 private void InitSensors()
 {
     SensorsDisplay = new SensorViewModel();
     Sensors        = new SensorModel(SensorsDisplay, SmartMirror);
     Sensors.InitSensorModel();
     sensorTimer.Interval = TimeSpan.FromMilliseconds(SensorRefreshRate);
     sensorTimer.Tick    += SensorTick;
     sensorTimer.Start();
     if (SmartMirror.Settings.UseNewSerialInit == null)
     {
         SerialService.InitSerialService(Sensors);
     }
     else if (SmartMirror.Settings.UseNewSerialInit.Value)
     {
         SerialService.InitSerialServiceNew(Sensors);
     }
     else
     {
         SerialService.InitSerialService(Sensors);
     }
 }
        public void SyncRemoteSerialConfiguration()
        {
            try
            {
                if (_serialService.IsConnected())
                {
                    Status.ComConnectionStatus.SetConnected(true);
                }

                var  powerCode = _serialService.ReadPower();
                bool master, fan, laser, motor;
                SerialService.ParsePowerCode(powerCode, out master, out fan, out motor, out laser);
                Params.MasterPowerCheck.Value = master;
                Params.FanPowerCheck.Value    = fan;
                Params.MotorPowerCheck.Value  = motor;
                Params.LaserPowerCheck.Value  = laser;
            }
            catch (Exception e)
            {
                // ignored
            }
        }
Exemplo n.º 11
0
        public Form1()
        {
            InitializeComponent();

            chkIncoming.Checked = this.viewIncoming;
            chkOutgoing.Checked = this.viewOutgoing;

            timeOutTimer          = new System.Windows.Forms.Timer();
            timeOutTimer.Interval = 2000;
            timeOutTimer.Tick    += timeOutTimer_Tick;

            commandList            = new List <string>();
            serial                 = SerialService.GetInstance();
            serial.OnConnected    += serial_OnConnected;
            serial.OnConnectError += serial_OnConnectError;
            serial.OnDataReceived += serial_OnDataReceived;
            serial.OnDisconnected += serial_OnDisconnected;
            serial.OnLog          += serial_OnLog;

            System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
            customCulture.NumberFormat.NumberDecimalSeparator = ".";

            System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;
        }
Exemplo n.º 12
0
      static void Main(string[] args)
      {
          bool    running;
          bool    connected;
          int     maxPacketLen = (int)Math.Pow(2, 13);
          ILogger logger       = new LoggerConfiguration().WriteTo.File("log.txt", rollingInterval: RollingInterval.Month).CreateLogger();
          ICommunicationService communicationService = new SerialService(logger);
          IAudioCaptureService  audioCaptureService  = new NAudioCaptureService(96000, maxPacketLen, logger);
          IFFTService           fftService           = new FFTService();
          ILedService           ledService           = new AdafruitLedService(communicationService, fftService);

          running = true;
          // Attempt to connect to the device and start the equalizer.
          try
          {
              AttemptConnect(ledService, logger);
              ledService.EqualizerStart(maxPacketLen, audioCaptureService);
              connected = true;
          }
          catch (Exception e)
          {
              connected = false;
              logger.Error("Unable to connect to device: " + e.ToString());
          }


          // USEFUL DEBUG: Print everything to the Console.
          communicationService.ResponseSubscribe((response) =>
            {
                Console.WriteLine(JsonConvert.SerializeObject(response));
            });

          // Listen for user input.
          Console.WriteLine("Yo hit the spacebar to hit the lights bro, P to ping, Q/ESC to quit");
          while (running)
          {
              try
              {
                  Console.Write('>');
                  ConsoleKeyInfo input = Console.ReadKey();
                  switch (Char.ToUpper(input.KeyChar))
                  {
                  case ' ':
                  {
                      if (connected == true)
                      {
                          ledService.Disconnect();
                          connected = false;
                      }
                      else
                      {
                          AttemptConnect(ledService, logger);
                          ledService.EqualizerStart(maxPacketLen, audioCaptureService);
                          connected = true;
                      }
                  }
                  break;

                  case 'P':
                      ledService.Ping(5000);
                      break;

                  case 'Q':
                  case (char)27:       // ESC
                      running = false;
                      ledService.Disconnect();
                      break;

                  default:
                      break;
                  }

                  Console.WriteLine();
              }
              catch (Exception e)
              {
                  Console.WriteLine(">:( Okay now how did we get here?\n" + e.ToString());
                  continue;   //momma didn't raise no quitter!
              }
          }
      }
 /// <summary>
 /// Initializes an instance of class <see cref="ValuesController"/>
 /// </summary>
 public ValuesController(SerialService serialService)
 {
     _serialService = serialService;
 }