コード例 #1
0
        private void btnWriteSingleCoil_Click(object sender, EventArgs e)
        {
            try
            {
                if (!modbusClient.Connected)
                {
                    modbusClient.IPAddress = txtIpAddressInput.Text;
                    modbusClient.Port      = int.Parse(txtPortInput.Text);
                    modbusClient.Connect();
                }

                bool coilsToSend = false;

                coilsToSend = bool.Parse(lsbAnswerFromServer.Items[0].ToString());


                modbusClient.WriteSingleCoil(int.Parse(txtStartingAddressInput.Text) - 1, coilsToSend);
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, "Exception writing values to Server", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                modbusClient.Disconnect();
            }
        }
コード例 #2
0
        private void btnWriteSingleCoil_Click(object sender, EventArgs e)
        {
            try
            {
                if (!modbusClient.Connected)
                {
                    button3_Click(null, null);
                }

                bool coilsToSend = false;

                coilsToSend = bool.Parse(lsbWriteToServer.Items[0].ToString());


                modbusClient.WriteSingleCoil(int.Parse(txtStartingAddressOutput.Text) - 1, coilsToSend);
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, "Exception writing values to Server", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }