Esempio n. 1
0
        protected override string OnGetDeviceIdentification(ModbusObjectId objectId)
        {
            switch (objectId)
            {
            case ModbusObjectId.VendorName:
                return("Axon Instruments");

            case ModbusObjectId.ProductCode:
                return("AX-100");

            case ModbusObjectId.MajorMinorRevision:
                return("1.0");

            case ModbusObjectId.VendorUrl:
                return("http://www.axoninstruments.biz");

            case ModbusObjectId.ProductName:
                return("AXGIF");

            case ModbusObjectId.ModelName:
                return("GAUGE");

            case ModbusObjectId.UserApplicationName:
                return("GaugeModbusInterface");
            }
            return(null);
        }
    protected override string OnGetDeviceIdentification(ModbusObjectId objectId)
    {
        switch (objectId)
        {
        case ModbusObjectId.VendorName:
            return("Vendor Name");

        case ModbusObjectId.ProductCode:
            return("101");

        case ModbusObjectId.MajorMinorRevision:
            return("1.0");

        case ModbusObjectId.VendorUrl:
            return("www.test.com.au");

        case ModbusObjectId.ProductName:
            return("Test Modbus");

        case ModbusObjectId.ModelName:
            return("1");

        case ModbusObjectId.UserApplicationName:
            return("SC100");
        }
        return(null);
    }
Esempio n. 3
0
 /// <summary>
 /// Is called when the value of the object id is needed for a ReadDeviceIdentification request.
 /// </summary>
 /// <param name="objectId">Object id.</param>
 /// <returns>Returns the value of the requested object id.</returns>
 protected override string OnGetDeviceIdentification(ModbusObjectId objectId)
 {
    return "";
 }
Esempio n. 4
0
        /// <summary>
        /// Reads one specific Device Information by using the function code (0x2b / 0x0e)
        /// </summary>
        /// <param name="deviceAddress">Address of the modbus device.</param>
        /// <param name="objectId">Object id to read.</param>
        /// <param name="timeout">Timeout for response in milli seconds.</param>
        /// <returns>Returns the requested device information.</returns>
        /// <remarks>
        /// Look at http://www.modbus.org/docs/Modbus_Application_Protocol_V1_1b3.pdf for more details.
        /// </remarks>
        public virtual DeviceIdentification ReadSpecificDeviceIdentification(byte deviceAddress, ModbusObjectId objectId, int timeout = 4000)
        {
            object telegramContext = null;

            [email protected](deviceAddress, (byte)ModbusFunctionCode.ReadDeviceIdentification, 3,
                                           this.buffer, out var telegramLength, out var dataPos, false, ref telegramContext);

            this.buffer[dataPos]     = 0x0e;
            this.buffer[dataPos + 1] = 0x04;
            this.buffer[dataPos + 2] = (byte)objectId;

            this.SendReceive(deviceAddress, ModbusFunctionCode.ReadDeviceIdentification, timeout, telegramLength, -1, telegramContext, ref dataPos);
            if (deviceAddress == ModbusConst.BroadcastAddress)
            {
                return(new DeviceIdentification());
            }
            var cnt = this.buffer[dataPos + 5];

            if (cnt == 0)
            {
                return(new DeviceIdentification());
            }

            dataPos += 6;
            var v = new char[this.buffer[dataPos + 1]];

            for (var n = 0; n < v.Length; ++n)
            {
                v[n] = (char)this.buffer[dataPos + 2 + n];
            }
            return(new DeviceIdentification {
                ObjectId = (ModbusObjectId)this.buffer[dataPos],
                Value = new string(v)
            });
        }
Esempio n. 5
0
        /// <summary>
        /// Reads the Device Information by using the function code (0x2b / 0x0e)
        /// </summary>
        /// <param name="deviceAddress">Address of the modbus device.</param>
        /// <param name="deviceIdCode">Device id code to read.</param>
        /// <param name="objectId">Object id to start at. Receives the next object id to read from if moreFollows is set to true.</param>
        /// <param name="moreFollows">Receives true if there is more information to read.</param>
        /// <param name="timeout">Timeout for response in milli seconds.</param>
        /// <returns>Returns an array with all device information.</returns>
        /// <remarks>
        /// Look at http://www.modbus.org/docs/Modbus_Application_Protocol_V1_1b3.pdf for more details.
        /// </remarks>
        public virtual DeviceIdentification[] ReadDeviceIdentification(byte deviceAddress, ModbusConformityLevel deviceIdCode, ref ModbusObjectId objectId, out bool moreFollows, int timeout = 2000)
        {
            object telegramContext = null;

            [email protected](deviceAddress, (byte)ModbusFunctionCode.ReadDeviceIdentification, 3,
                                           this.buffer, out var telegramLength, out var dataPos, false, ref telegramContext);

            this.buffer[dataPos]     = 0x0e;
            this.buffer[dataPos + 1] = (byte)deviceIdCode;
            this.buffer[dataPos + 2] = (byte)objectId;

            this.SendReceive(deviceAddress, ModbusFunctionCode.ReadDeviceIdentification, timeout, telegramLength, -1, telegramContext, ref dataPos);
            if (deviceAddress == ModbusConst.BroadcastAddress)
            {
                moreFollows = false;
                return(null);
            }
            moreFollows = this.buffer[dataPos + 3] != 0;
            objectId    = (ModbusObjectId)this.buffer[dataPos + 4];
            var cnt = this.buffer[dataPos + 5];

            var values = new DeviceIdentification[cnt];

            dataPos += 6;
            for (var i = 0; i < cnt; i++)
            {
                var v = new char[this.buffer[dataPos + 1]];
                for (var n = 0; n < v.Length; ++n)
                {
                    v[n] = (char)this.buffer[dataPos + 2 + n];
                }
                values[i] = new DeviceIdentification {
                    ObjectId = (ModbusObjectId)this.buffer[dataPos],
                    Value    = new string(v)
                };
                dataPos += (short)(2 + v.Length);
            }
            return(values);
        }
Esempio n. 6
0
 /// <summary>
 /// Is called when the value of the object id is needed for a ReadDeviceIdentification request.
 /// </summary>
 /// <param name="objectId">Object id.</param>
 /// <returns>Returns the value of the requested object id.</returns>
 protected override string OnGetDeviceIdentification(ModbusObjectId objectId)
 {
     return("");
 }
Esempio n. 7
0
 /// <summary>
 /// Is called when the value of the object id is needed for a ReadDeviceIdentification request.
 /// </summary>
 /// <param name="objectId">Object id.</param>
 /// <returns>Returns the value of the requested object id.</returns>
 protected override string OnGetDeviceIdentification(ModbusObjectId objectId) => "";
Esempio n. 8
0
 /// <summary>
 /// Is called when the value of the object id is needed for a ReadDeviceIdentification request.
 /// </summary>
 /// <param name="objectId">Object id.</param>
 /// <returns>Returns the value of the requested object id.</returns>
 protected abstract string OnGetDeviceIdentification(ModbusObjectId objectId);
Esempio n. 9
0
      /// <summary>
      /// Reads one specific Device Information by using the function code (0x2b / 0x0e)
      /// </summary>
      /// <param name="deviceAddress">Address of the modbus device.</param>
      /// <param name="objectId">Object id to read.</param>
      /// <param name="timeout">Timeout for response in milli seconds.</param>
      /// <returns>Returns the requested device information.</returns>
      /// <remarks>
      /// Look at http://www.modbus.org/docs/Modbus_Application_Protocol_V1_1b3.pdf for more details.
      /// </remarks>
      public virtual DeviceIdentification ReadSpecificDeviceIdentification(byte deviceAddress, ModbusObjectId objectId, int timeout = 4000)
      {
         short telegramLength;
         short dataPos;
         object telegramContext = null;

         _Interface.CreateTelegram(deviceAddress, (byte)ModbusFunctionCode.ReadDeviceIdentification, 3,
            _Buffer, out telegramLength, out dataPos, false, ref telegramContext);

         _Buffer[dataPos] = 0x0e;
         _Buffer[dataPos + 1] = 0x04;
         _Buffer[dataPos + 2] = (byte)objectId;

         SendReceive(deviceAddress, ModbusFunctionCode.ReadDeviceIdentification, timeout, telegramLength, -1, telegramContext, ref dataPos);
         if (deviceAddress == ModbusConst.BroadcastAddress)
         {
            return new DeviceIdentification();
         }
         byte cnt = _Buffer[dataPos + 5];
         if (cnt == 0)
         {
            return new DeviceIdentification();
         }

         dataPos += 6;
         var v = new char[_Buffer[dataPos + 1]];
         for (int n = 0; n < v.Length; ++n)
         {
            v[n] = (char)_Buffer[dataPos + 2 + n];
         }
         return new DeviceIdentification
            {
            ObjectId = (ModbusObjectId)_Buffer[dataPos],
            Value = new string(v)
         };
      }
Esempio n. 10
0
      /// <summary>
      /// Reads the Device Information by using the function code (0x2b / 0x0e)
      /// </summary>
      /// <param name="deviceAddress">Address of the modbus device.</param>
      /// <param name="deviceIdCode">Device id code to read.</param>
      /// <param name="objectId">Object id to start at. Receives the next object id to read from if moreFollows is set to true.</param>
      /// <param name="moreFollows">Receives true if there is more information to read.</param>
      /// <param name="timeout">Timeout for response in milli seconds.</param>
      /// <returns>Returns an array with all device information.</returns>
      /// <remarks>
      /// Look at http://www.modbus.org/docs/Modbus_Application_Protocol_V1_1b3.pdf for more details.
      /// </remarks>
      public virtual DeviceIdentification[] ReadDeviceIdentification(byte deviceAddress, ModbusConformityLevel deviceIdCode, ref ModbusObjectId objectId, out bool moreFollows, int timeout = 2000)
      {
         short telegramLength;
         short dataPos;
         object telegramContext = null;

         _Interface.CreateTelegram(deviceAddress, (byte)ModbusFunctionCode.ReadDeviceIdentification, 3,
            _Buffer, out telegramLength, out dataPos, false, ref telegramContext);

         _Buffer[dataPos] = 0x0e;
         _Buffer[dataPos + 1] = (byte)deviceIdCode;
         _Buffer[dataPos + 2] = (byte)objectId;

         SendReceive(deviceAddress, ModbusFunctionCode.ReadDeviceIdentification, timeout, telegramLength, -1, telegramContext, ref dataPos);
         if (deviceAddress == ModbusConst.BroadcastAddress)
         {
            moreFollows = false;
            return null;
         }
         moreFollows = _Buffer[dataPos + 3] != 0;
         objectId = (ModbusObjectId) _Buffer[dataPos + 4];
         byte cnt = _Buffer[dataPos + 5];

         var values = new DeviceIdentification[cnt];
         dataPos += 6;
         for (int i = 0; i < cnt; i++)
         {
            var v = new char[_Buffer[dataPos + 1]];
            for (int n = 0; n < v.Length; ++n)
            {
               v[n] = (char) _Buffer[dataPos + 2 + n];
            }
            values[i] = new DeviceIdentification
               {
                  ObjectId = (ModbusObjectId) _Buffer[dataPos],
                  Value = new string(v)
               };
            dataPos += (short)(2 + v.Length);
         }
         return values;
      }
Esempio n. 11
0
 /// <summary>
 /// Is called when the value of the object id is needed for a ReadDeviceIdentification request.
 /// </summary>
 /// <param name="objectId">Object id.</param>
 /// <returns>Returns the value of the requested object id.</returns>
 protected abstract string OnGetDeviceIdentification(ModbusObjectId objectId);