public async Task ReadInputsAsyncThrowsOnInvalidNumberOfPoints(ushort numOfPoints)
        {
            // Arrange
            var target = new ModbusMaster(new Mock <IModbusTransport>().Object);

            // Act/Assert
            await Assert.ThrowsAsync <ArgumentOutOfRangeException>(
                "numberOfPoints",
                () => target.ReadInputsAsync(1, 0, numOfPoints));
        }
Beispiel #2
0
    private async void ReadButton_Click(object sender, EventArgs e)
    {
        UIEnabled(bFlg: false);
        try
        {
            int    tab_idx = tabControl1.SelectedIndex;
            bool[] task    = await Master.ReadInputsAsync((byte)devno, (ushort)TargetSensor.DescriteAddress, (ushort)TargetSensor.DescriteMaps.Count);

            int item_idx2 = 0;
            foreach (typeBase descriteMap in TargetSensor.DescriteMaps)
            {
                if (task[item_idx2])
                {
                    ((typeCh)descriteMap).bit = 1;
                }
                else
                {
                    ((typeCh)descriteMap).bit = 0;
                }
                item_idx2++;
            }
            TabPage      pg   = tabControl1.TabPages[tab_idx];
            DataGridView mdgv = (DataGridView)pg.Controls[0];
            item_idx2 = 0;
            foreach (typeBase descriteMap2 in TargetSensor.DescriteMaps)
            {
                mdgv[1, item_idx2].Value = descriteMap2.ToString();
                item_idx2++;
            }
        }
        catch (SlaveException)
        {
            MessageBox.Show("Device error response.");
        }
        catch (Exception ex2)
        {
            if (ex2.Message != null)
            {
                MessageBox.Show(ex2.Message);
            }
            else
            {
                MessageBox.Show("Error");
            }
        }
        UIEnabled(bFlg: true);
    }