コード例 #1
0
        static int RunWrite6(Write6Options opts)
        {
            using (var client = new ModbusRtuClient())
            {
                client.PortName = opts.PortName;
                client.BaudRate = opts.BaudRate;
                client.DataBits = opts.DataBits;
                client.Parity   = opts.Parity;

                if (!OpenPort(client))
                {
                    return(1);
                }

                try
                {
                    client.WriteHoldingRegister(opts.UnitAddress, opts.RegisterAddress, opts.Value);
                }
                catch (Exception exp)
                {
                    return(HandleException(exp));
                }

                return(0);
            }
        }