예제 #1
0
        void ButtonReadClick(object sender, EventArgs e)
        {
            var slaveAddress = (byte)numericUpDownSlaveAddress.Value;
            var startAddress = (ushort)numericUpDownRegisterAddress.Value;
            var functionCode = comboBoxFunctionCode.SelectedIndex;

            context.ioRunner.Run(() => {
                if (context.Master != null)
                {
                    context.EnsureDelay();
                    var value = functionCode == 0 ?
                                context.Master.ReadHoldingRegister(slaveAddress, startAddress) :
                                context.Master.ReadInputRegister(slaveAddress, startAddress);
                    context.uiRunner.Run(() => {
                        labelRegisterValue.Text = value.ToString();
                    });
                }
            });
        }
예제 #2
0
        void ButtonReadClick(object sender, EventArgs e)
        {
            var slaveAddress = (byte)numericUpDownSlaveAddress.Value;
            var startAddress = (ushort)numericUpDownRegisterAddress.Value;
            var functionCode = comboBoxFunctionCode.SelectedIndex;

            context.ioRunner.Run(() => {
                if (context.Master != null)
                {
                    context.EnsureDelay();
                    var value = functionCode < 2?
                                context.Master.ReadHoldingRegisters(slaveAddress, startAddress, 2) :
                                context.Master.ReadInputRegisters(slaveAddress, startAddress, 2);
                    var floatValue = ByteArrayToFloat(value, functionCode % 2);
                    context.uiRunner.Run(() => {
                        labelFloatValue.Text = floatValue.ToString("0.0000");
                    });
                }
            });
        }
예제 #3
0
        void ButtonReadClick(object sender, EventArgs e)
        {
            var slaveAddress = (byte)numericUpDownSlaveAddress.Value;
            var startAddress = (ushort)numericUpDownStartAddress.Value;
            var functionCode = comboBoxFunctionCode.SelectedIndex;

            context.ioRunner.Run(() => {
                if (context.Master != null)
                {
                    context.EnsureDelay();
                    var state = functionCode == 0 ?
                                context.Master.ReadCoil(slaveAddress, startAddress) :
                                context.Master.ReadInput(slaveAddress, startAddress);
                    context.uiRunner.Run(() => {
                        labelState.Text      = state ? "On" : "Off";
                        labelState.BackColor = state ? Color.LimeGreen : Color.Gray;
                    });
                }
            });
        }