示例#1
0
        public void TestWriteSingleRegister()
        {
            try
            {
                IModbusMessage request;
                byte[]         sendBytes = _modbusMaster.BuildWriteSingleRegisterCommand(slaveId, startAddress, 123, 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.ValidateWriteSingleRegisterResponse(readBytes, request);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }