コード例 #1
0
        public void TestWriteMultipleCoils()
        {
            try
            {
                IModbusMessage request;
                byte[]         sendBytes = _modbusMaster.BuildWriteMultipleCoilsCommand(slaveId, startAddress, new bool[] { true, true, true }, out request);
                _sr.Write(sendBytes, 0, sendBytes.Length);

                byte[] readBuffer = new byte[1024];
                int    num        = _sr.Read(readBuffer, 0, readBuffer.Length);
                byte[] readBytes  = new byte[num];
                Buffer.BlockCopy(readBuffer, 0, readBytes, 0, num);

                _modbusMaster.ValidateWriteMultipleCoilsResponse(readBytes, request);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }