Ejemplo n.º 1
0
        public string ReadString(ushort address, ushort points)
        {
            CustomReadHoldingRegistersRequest  readAscii = new CustomReadHoldingRegistersRequest(3, 1, address, points);
            CustomReadHoldingRegistersResponse response  = master.ExecuteCustomMessage <CustomReadHoldingRegistersResponse>(readAscii);

            return(System.Text.Encoding.ASCII.GetString(response.Data));
        }
Ejemplo n.º 2
0
        public virtual void ExecuteCustomMessage_ReadHoldingRegisters()
        {
            CustomReadHoldingRegistersRequest  request  = new CustomReadHoldingRegistersRequest(3, SlaveAddress, 104, 2);
            CustomReadHoldingRegistersResponse response = Master.ExecuteCustomMessage <CustomReadHoldingRegistersResponse>(request);

            Assert.AreEqual(new ushort[] { 0, 0 }, response.Data);
        }
Ejemplo n.º 3
0
        public float[] ReadFloat(ushort address, ushort points)
        {
            float[] floatval = new float[points];
            CustomReadHoldingRegistersRequest  readFloat = new CustomReadHoldingRegistersRequest(3, 1, address, points);
            CustomReadHoldingRegistersResponse response  = master.ExecuteCustomMessage <CustomReadHoldingRegistersResponse>(readFloat);

            for (ushort i = 0; i < points; i++)
            {
                byte[] floatOr = new byte[] { response.Data[3 + 4 * i], response.Data[2 + 4 * i], response.Data[1 + 4 * i], response.Data[0 + 4 * i] };
                floatval[i] = BitConverter.ToSingle(floatOr, 0);
            }
            return(floatval);
        }
Ejemplo n.º 4
0
        public int[] ReadInt32(ushort address, ushort points)
        {
            int[] longval = new int[points];
            CustomReadHoldingRegistersRequest  readLong = new CustomReadHoldingRegistersRequest(3, 1, address, points);
            CustomReadHoldingRegistersResponse response = master.ExecuteCustomMessage <CustomReadHoldingRegistersResponse>(readLong);

            for (ushort i = 0; i < points; i++)
            {
                byte[] longOr = new byte[] { response.Data[3 + 4 * i], response.Data[2 + 4 * i], response.Data[1 + 2 * i], response.Data[0 + 2 * i] };
                longval[i] = BitConverter.ToInt32(longOr, 0);
            }
            return(longval);
        }