예제 #1
0
        public void TestWriteSingleCoil()
        {
            try
            {
                IModbusMessage request;
                byte[]         sendBytes = _modbusMaster.BuildWriteSingleCoilCommand(slaveId, startAddress, 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.ValidateWriteSingleCoilResponse(readBytes, request);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }