Example #1
0
        internal void SynchroniseSensor(Sensor sensor, string serialPort)
        {
            try
            {
                SerialPortToken.Instance.ConnectToSerialPort(serialPort);
                InitializeModbus();

                var activeMode = GetActiveMode();

                var isActive = _modbusService.CheckActivityStatusOfDevice(new Slave
                {
                    DeviceNumber = (ushort)sensor.Id,
                    SlaveId      = (byte)sensor.GatewayId
                }, activeMode);

                if (!isActive)
                {
                    throw new Exception("Wybrany czujnik jest niedostępny.");
                }

                _modbusService.SendControlMessage(new Slave
                {
                    DeviceNumber = (ushort)sensor.Id,
                    SlaveId      = (byte)sensor.GatewayId
                });
            }
            finally
            {
                SerialPortToken.Instance.DisconnectSerialPort();
            }
        }
Example #2
0
 private void uxCalibration_Click(object sender, EventArgs e)
 {
     try
     {
         foreach (var node in _enableNodes)
         {
             var deviceNumber = (ushort)Convert.ToInt32(node);
             _modbusService.SendControlMessage(new Slave
             {
                 DeviceNumber = deviceNumber,
                 SlaveId      = 1
             });
             uxConsole.Nodes.Add(String.Format("Node{0} skalibrowany", node)).EnsureVisible();
         }
     }
     catch (Exception ex)
     {
         uxConsole.Nodes.Add(ex.Message).EnsureVisible();
     }
 }