Ejemplo n.º 1
0
        /// <summary>
        /// Sets a FLOAT32, INT32 or DOUBLE64 value to the device.
        /// </summary>
        /// <param name="address">Device Address. Use null to use the DefaultDeviceAddress defined on MeComQuerySet.</param>
        /// <param name="parameterId">Device Parameter ID.</param>
        /// <param name="instance">Parameter Instance. (usually 1)</param>
        /// <param name="type">Specifies the type of the value to be set.</param>
        /// <param name="value">Value to be set. Make sure this value fits to the specified type.</param>
        /// <exception cref="ComCommandException">when the command fails. Check the inner exception for details.</exception>
        public void SetValue(byte?address, UInt16 parameterId, byte instance, MeParType type, dynamic value)
        {
            try
            {
                MeComPacket txFrame = new MeComPacket('#', address);
                MeComVarConvert.AddString(txFrame.Payload, "VS");
                MeComVarConvert.AddUint16(txFrame.Payload, parameterId);
                MeComVarConvert.AddUint8(txFrame.Payload, instance);


                switch (type)
                {
                case MeParType.FLOAT32:
                    MeComVarConvert.AddFloat32(txFrame.Payload, value);
                    break;

                case MeParType.INT32:
                    MeComVarConvert.AddInt32(txFrame.Payload, value);
                    break;

                case MeParType.DOUBLE64:
                    MeComVarConvert.AddDouble64(txFrame.Payload, value);
                    break;

                default:
                    throw new ArgumentOutOfRangeException("Unknown Type. Received value: " + type);
                }

                meQuerySet.Set(txFrame);
            }
            catch (Exception Ex)
            {
                throw new ComCommandException(String.Format("Set Value failed: Address: {0}; ID: {1}; Inst: {2}; Detail: {3}", address, parameterId, instance, Ex.Message), Ex);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Sets a signed int 32Bit value to the device.
 /// </summary>
 /// <param name="address">Device Address. Use null to use the DefaultDeviceAddress defined on MeComQuerySet.</param>
 /// <param name="parameterId">Device Parameter ID.</param>
 /// <param name="instance">Parameter Instance. (usually 1)</param>
 /// <param name="value">Value to set.</param>
 /// <exception cref="ComCommandException">when the command fails. Check the inner exception for details.</exception>
 public void SetINT32Value(byte?address, UInt16 parameterId, byte instance, int value)
 {
     try
     {
         MeComPacket txFrame = new MeComPacket('#', address);
         MeComVarConvert.AddString(txFrame.Payload, "VS");
         MeComVarConvert.AddUint16(txFrame.Payload, parameterId);
         MeComVarConvert.AddUint8(txFrame.Payload, instance);
         MeComVarConvert.AddInt32(txFrame.Payload, value);
         meQuerySet.Set(txFrame);
     }
     catch (Exception Ex)
     {
         throw new ComCommandException(String.Format("Set INT32 Value failed: Address: {0}; ID: {1}; Inst: {2}; Detail: {3}", address, parameterId, instance, Ex.Message), Ex);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Sends out a command to set the device address by type and serial number
 /// </summary>
 /// <param name="address">Device Address. Use null to use the DefaultDeviceAddress defined on MeComQuerySet.</param>
 /// <param name="deviceType">Type of the device.</param>
 /// <param name="serialNumber">Serial number of the Device</param>
 /// <param name="setaddress">Address to be set.</param>
 /// <param name="option">Option. 0=Set address, 1=rack system.</param>
 /// <exception cref="ComCommandException">when the command fails. Check the inner exception for details.</exception>
 public void SetDeviceAddress(byte?address, int deviceType, int serialNumber, byte setaddress, byte option)
 {
     try
     {
         MeComPacket txFrame = new MeComPacket('#', address);
         MeComVarConvert.AddString(txFrame.Payload, "SA");
         MeComVarConvert.AddInt32(txFrame.Payload, deviceType);
         MeComVarConvert.AddInt32(txFrame.Payload, serialNumber);
         MeComVarConvert.AddUint8(txFrame.Payload, option);
         MeComVarConvert.AddUint8(txFrame.Payload, setaddress);
         meQuerySet.Set(txFrame);
     }
     catch (Exception Ex)
     {
         throw new ComCommandException(String.Format("Set Device Address failed: Address: {0}; Device Type: {1}; Serial Number: {2}; Address to be set: {3}", deviceType, serialNumber, setaddress, Ex.Message), Ex);
     }
 }