Exemplo n.º 1
0
        void ButtonOnClick(object sender, EventArgs e)
        {
            var slaveAddress = (byte)numericUpDownSlaveAddress.Value;
            var coilAddress  = (ushort)numericUpDownStartAddress.Value;

            context.Io((master) => {
                master.WriteCoil(slaveAddress, coilAddress, true);
            });
        }
Exemplo n.º 2
0
        void ButtonWriteClick(object sender, EventArgs e)
        {
            var slaveAddress  = (byte)numericUpDownSlaveAddress.Value;
            var startAddress  = (ushort)numericUpDownRegisterAddress.Value;
            var registerValue = (ushort)numericUpDownRegisterValue.Value;

            context.Io((master) => {
                master.WriteRegister(slaveAddress, startAddress, registerValue);
            });
        }
Exemplo n.º 3
0
        void ButtonWriteClick(object sender, EventArgs e)
        {
            var slaveAddress = (byte)numericUpDownSlaveAddress.Value;
            var startAddress = (ushort)numericUpDownRegisterAddress.Value;
            var floatValue   = numericUpDownFloatValue.Value;
            var functionCode = comboBoxFunctionCode.SelectedIndex;

            context.Io((master) => {
                var value = FloatToByteArray((float)floatValue, functionCode);
                master.WriteRegisters(slaveAddress, startAddress, value);
            });
        }
Exemplo n.º 4
0
 void Timer_Tick(object sender, EventArgs e)
 {
     timer.Enabled = false;
     foreach (var control in controls)
     {
         control.Perform();
     }
     context.Io(() => {
         context.Ui(() => {
             timer.Enabled = pollCheckBox.Checked;
         });
     });
 }
Exemplo n.º 5
0
        void ButtonReadClick(object sender, EventArgs e)
        {
            var slaveAddress = (byte)numericUpDownSlaveAddress.Value;
            var startAddress = (ushort)numericUpDownRegisterAddress.Value;
            var functionCode = comboBoxFunctionCode.SelectedIndex;

            context.Io((master) => {
                var value = functionCode == 0 ?
                            master.ReadHoldingRegister(slaveAddress, startAddress) :
                            master.ReadInputRegister(slaveAddress, startAddress);
                context.Ui(() => {
                    labelRegisterValue.Text = value.ToString();
                });
            });
        }
Exemplo n.º 6
0
        void ButtonReadClick(object sender, EventArgs e)
        {
            var slaveAddress = (byte)numericUpDownSlaveAddress.Value;
            var startAddress = (ushort)numericUpDownRegisterAddress.Value;
            var functionCode = comboBoxFunctionCode.SelectedIndex;

            context.Io((master) => {
                var value = functionCode < 2?
                            master.ReadHoldingRegisters(slaveAddress, startAddress, 2) :
                            master.ReadInputRegisters(slaveAddress, startAddress, 2);
                var floatValue = ByteArrayToFloat(value, functionCode % 2);
                context.Ui(() => {
                    labelFloatValue.Text = floatValue.ToString("0.0000");
                });
            });
        }
Exemplo n.º 7
0
        void ButtonReadClick(object sender, EventArgs e)
        {
            var slaveAddress = (byte)numericUpDownSlaveAddress.Value;
            var startAddress = (ushort)numericUpDownStartAddress.Value;
            var functionCode = comboBoxFunctionCode.SelectedIndex;

            context.Io((master) => {
                var state = functionCode == 0 ?
                            master.ReadCoil(slaveAddress, startAddress) :
                            master.ReadInput(slaveAddress, startAddress);
                context.Ui(() => {
                    labelState.Text      = state ? "On" : "Off";
                    labelState.BackColor = state ? Color.LimeGreen : Color.Gray;
                });
            });
        }