Beispiel #1
0
        private void WriteSingleRegister(Device _d, ModbusCommandSignal _commandSignal)
        {
            ModbusTCPDevice d     = Devices.Where(device => device.ID == _d.ID).First();
            ushort          value = 0;

            try
            {
                switch (_commandSignal.commandType)
                {
                case ModbusCommandSignal.CommandType.Binary:
                    int bit = (_commandSignal.CommandValue) > 0 ? 1 : 0;
                    value = (ushort)(bit << _commandSignal.BitNumber);
                    master.WriteSingleRegister(d.SlaveID, _commandSignal.Address, value);
                    break;

                case ModbusCommandSignal.CommandType.Analog:
                    value = (ushort)_commandSignal.CommandValue;
                    break;

                default:
                    break;
                }

                master.WriteSingleRegister(d.SlaveID, _commandSignal.Address, value);
            }
            catch (Exception ex)
            {
                Log.Instance.Error("{0}: {1} adlı sinyale {2} değeri yazılamadı => {3}", this.GetType().Name, _commandSignal.Identification, _commandSignal.CommandValue, ex.Message);
            }
        }
Beispiel #2
0
        public frm_AddNewOrUpdateModbusCommandSignal()
        {
            InitializeComponent();

            InitializeDatabase();

            InitializeControlProperties();

            commandSignal = new ModbusCommandSignal();
        }
Beispiel #3
0
        private void WriteSingleCoil(Device _d, ModbusCommandSignal _commandSignal)
        {
            ModbusTCPDevice d = Devices.Where((device) => device.ID == _d.ID).First();

            try
            {
                bool value = _commandSignal.CommandValue > 0 ? false : true;
                master.WriteSingleCoil(d.SlaveID, _commandSignal.Address, value);
            }
            catch (Exception ex)
            {
                Log.Instance.Error("{0}: {1} adlı sinyale {2} değeri yazılamadı => {3}", this.GetType().Name, _commandSignal.Identification, _commandSignal.CommandValue, ex.Message);
            }
        }
Beispiel #4
0
        public override bool WriteValue(Device d, CommandSignal c)
        {
            ModbusTCPDevice     _d             = Devices.Where(device => device.ID == d.ID).FirstOrDefault();
            ModbusCommandSignal _commandSignal = _d.CommandSignals.Where(command => command.ID == c.ID).FirstOrDefault();

            if (_d.Connected && _d.isActive)
            {
                switch (_commandSignal.FunctionCode)
                {
                case 5:
                    WriteSingleCoil(_d, _commandSignal);
                    return(true);

                case 6:
                    WriteSingleRegister(_d, _commandSignal);
                    return(true);

                case 15:
                    WriteMultipleCoils(_d, _commandSignal);
                    return(true);

                case 16:
                    WriteValueMultipleRegisters(_d, _commandSignal);
                    return(true);

                default:
                    Log.Instance.Error("Yanlış function code : {0} sinyaline değer yazılamadı", _commandSignal.Identification);
                    return(false);
                }
            }
            else
            {
                Log.Instance.Warn("{0}: {1} adlı komut cihaz ile haberleşme olmadığı için gönderilemedi", this.GetType().Name, _commandSignal.Identification);
                return(false);
            }
        }
Beispiel #5
0
 private void WriteMultipleCoils(Device _d, ModbusCommandSignal _commandSignal)
 {
     //throw new NotImplementedException();
 }
Beispiel #6
0
 private void WriteValueMultipleRegisters(Device _d, ModbusCommandSignal _commandSignal)
 {
     //throw new NotImplementedException();
 }