示例#1
0
        public void MmsValueDouble()
        {
            var val = new MmsValue((double)1234.5678);

            Assert.AreEqual(val.ToDouble(), (double)1234.5678);

            val.SetDouble((double)0.1234);

            Assert.AreEqual(val.ToDouble(), (double)0.1234);

            Assert.AreEqual(val.ToFloat(), (float)0.1234);
        }
示例#2
0
            public void UpdateValue(IedServer server, object DataValue)
            {
                if (DataValue == null)
                {
                    return;
                }
                if (server == null)
                {
                    return;
                }
                if (mmsValue == null)
                {
                    mmsValueInit();
                }
                switch (mmsType)
                {
                /** array type (multiple elements of the same type) */
                case MmsType.MMS_ARRAY:
                    // not supported
                    break;

                /** structure type (multiple elements of different types) */
                case MmsType.MMS_STRUCTURE:
                    // not supported
                    break;

                /** boolean */
                case MmsType.MMS_BOOLEAN:
                    server.UpdateBooleanAttributeValue(this, Convert.ToBoolean(DataValue));
                    break;

                /** bit string */
                case MmsType.MMS_BIT_STRING:
                    if (DataValue is uint)
                    {
                        server.UpdateBitStringAttributeValue(this, Convert.ToUInt32(DataValue));
                    }
                    break;

                case MmsType.MMS_INTEGER:
                    if (daType == DataAttributeType.INT8 ||
                        daType == DataAttributeType.INT16 ||
                        daType == DataAttributeType.INT32)
                    {
                        server.UpdateInt32AttributeValue(this, Convert.ToInt32(DataValue));
                    }
                    else if (daType == DataAttributeType.INT64)
                    {
                        server.UpdateInt64AttributeValue(this, Convert.ToInt64(DataValue));
                    }
                    else if (daType == DataAttributeType.ENUMERATED)
                    {
                        server.UpdateInt32AttributeValue(this, Convert.ToInt32(DataValue));
                    }
                    break;

                /** unsigned integer */
                case MmsType.MMS_UNSIGNED:
                    if (daType == DataAttributeType.INT8U ||
                        daType == DataAttributeType.INT16U ||
                        daType == DataAttributeType.INT32U)
                    {
                        server.UpdateUnsignedAttributeValue(this, Convert.ToUInt32(DataValue));
                    }
                    break;

                /** floating point value (32 or 64 bit) */
                case MmsType.MMS_FLOAT:
                    if (daType == DataAttributeType.FLOAT32)
                    {
                        server.UpdateFloatAttributeValue(this, (float)DataValue);
                    }
                    else if (daType == DataAttributeType.FLOAT64)
                    {
                        // !!! Attention does not generate reports !!!
                        mmsValue.SetDouble((double)DataValue);
                    }
                    break;

                /** octet string */
                case MmsType.MMS_OCTET_STRING:
                    // !!! Attention does not generate reports !!!
                    mmsValue.setOctetString((byte[])DataValue);
                    break;

                /** visible string - ANSI string */
                case MmsType.MMS_VISIBLE_STRING:
                    server.UpdateVisibleStringAttributeValue(this, (string)DataValue);
                    break;

                /** Generalized time */
                case MmsType.MMS_GENERALIZED_TIME:
                    // not supported
                    break;

                case MmsType.MMS_BINARY_TIME:
                    // !!! Attention does not generate reports !!!
                    mmsValue.SetBinaryTime((ulong)DataValue);
                    break;

                /** Binary coded decimal (BCD) - not used */
                case MmsType.MMS_BCD:
                    // Not supported
                    break;

                /** object ID - not used */
                case MmsType.MMS_OBJ_ID:
                    // Not supported
                    break;

                /** Unicode string */
                case MmsType.MMS_STRING:
                    // Not supported
                    //mmsValue.SetMmsString((string)DataValue);
                    break;

                /** UTC time */
                case MmsType.MMS_UTC_TIME:
                    if (DataValue is ulong)
                    {
                        server.UpdateUTCTimeAttributeValue(this, Convert.ToUInt64(DataValue));
                    }
                    else if (DataValue is DateTime)
                    {
                        server.UpdateUTCTimeAttributeValue(this, Util.ConvertDateTime((DateTime)DataValue));
                    }
                    //mmsValue.SetUtcTimeMs((ulong)DataValue);
                    break;

                /** will be returned in case of an error (contains error code) */
                case MmsType.MMS_DATA_ACCESS_ERROR:
                    // Not supported
                    break;
                }
            }