Esempio n. 1
0
        internal string GetResponse(Gateway gateway)
        {
            try
            {
                SerialPortToken.Instance.ConnectToSerialPort(gateway.SerialPort);
                InitializeModbus();

                var registers = _modbusService.GetAllRegisterForSelectedDevice(new Slave
                {
                    DeviceNumber = 0,
                    SlaveId      = (byte)gateway.HardwareGatewayId
                });

                var response = String.Empty;

                foreach (var register in registers)
                {
                    response += String.Format("{0};", register);
                }

                return(response);
            }
            finally
            {
                SerialPortToken.Instance.DisconnectSerialPort();
            }
        }
Esempio n. 2
0
        internal List <ushort> GetAllSensorRegisters(Sensor sensor, string serialPort)
        {
            try
            {
                SerialPortToken.Instance.ConnectToSerialPort(serialPort);
                InitializeModbus();

                return(_modbusService.GetAllRegisterForSelectedDevice(new Slave
                {
                    DeviceNumber = (ushort)sensor.Id,
                    SlaveId = (byte)sensor.GatewayId
                }));
            }
            finally
            {
                SerialPortToken.Instance.DisconnectSerialPort();
            }
        }
Esempio n. 3
0
        internal string GetFirstAndEightRegisters(Sensor sensor, ModbusService modbusService)
        {
            var registers = modbusService.GetAllRegisterForSelectedDevice(new Slave
            {
                DeviceNumber = (ushort)sensor.Id,
                SlaveId      = (byte)sensor.GatewayId
            });

            return(string.Format("Rejestr 1 - {0}, rejestr 8 - {1}", registers[0], registers[7]));
        }
Esempio n. 4
0
        private void uxGetRegisterValues_Click(object sender, EventArgs e)
        {
            try
            {
                var gatewayRegisters = _modbusService.GetAllRegisterForSelectedDevice(new Slave
                {
                    DeviceNumber = 0,
                    SlaveId      = 1
                });

                var rootNode = uxConsole.Nodes.Add("Wartości rejestrów Gateway'a");

                foreach (var gateway in gatewayRegisters)
                {
                    rootNode.Nodes.Add(gateway.ToString(CultureInfo.InvariantCulture)).EnsureVisible();
                }

                foreach (var node in _enableNodes)
                {
                    var deviceNumber   = (ushort)Convert.ToInt32(node);
                    var node1Registers = _modbusService.GetAllRegisterForSelectedDevice(new Slave
                    {
                        DeviceNumber = deviceNumber,
                        SlaveId      = 1
                    });

                    var treeNode = uxConsole.Nodes.Add(String.Format("Wartości rejestrów Node{0}", node));
                    foreach (var node1Register in node1Registers)
                    {
                        treeNode.Nodes.Add(node1Register.ToString(CultureInfo.InvariantCulture)).EnsureVisible();
                    }
                }
            }
            catch (Exception ex)
            {
                uxConsole.Nodes.Add(ex.Message).EnsureVisible();
            }
        }