Пример #1
0
        public static void setSigTypeU(ref BPLibApi.SigTypeU sigTypeU, SignalDataItem.BPValueType valueType, Object value)
        {
            if (null == valueType)
            {
                return;
            }
            if (null == value)
            {
                return;
            }
            switch (valueType)
            {
            case SignalDataItem.BPValueType.U32:
                sigTypeU.t_u32 = (UInt32)value;
                break;

            case SignalDataItem.BPValueType.U16:
                sigTypeU.t_u16 = (UInt16)value;
                break;

            case SignalDataItem.BPValueType.I32:
                sigTypeU.t_i32 = (Int32)value;
                break;

            case SignalDataItem.BPValueType.I16:
                sigTypeU.t_i16 = (Int16)value;
                break;

            case SignalDataItem.BPValueType.ENUM:
                sigTypeU.t_enm = (UInt16)value;
                break;

            case SignalDataItem.BPValueType.FLOAT:
                sigTypeU.t_flt = (float)value;
                break;

            case SignalDataItem.BPValueType.STRING:
                /* TODO */
                // sigTypeU.t_str = (UInt32)value;
                break;

            case SignalDataItem.BPValueType.BOOLEAN:
                sigTypeU.t_bool = (char)value;
                break;

            case SignalDataItem.BPValueType.MEM:
                break;
            }
        }
Пример #2
0
        public static Boolean setSigValue(ref Object sigValue, SignalDataItem.BPValueType valueType, string newValue)
        {
            Boolean ret = false;

            if (null == valueType)
            {
                return(ret);
            }
            if (null == newValue)
            {
                return(ret);
            }
            try
            {
                ret = true;

                switch (valueType)
                {
                case SignalDataItem.BPValueType.U32:
                    if (string.IsNullOrWhiteSpace(newValue))
                    {
                        UInt32 tmp = new UInt32();
                        tmp      = 0;
                        sigValue = tmp;
                    }
                    else
                    {
                        sigValue = Convert.ToUInt32(newValue);
                    }
                    break;

                case SignalDataItem.BPValueType.U16:
                    if (string.IsNullOrWhiteSpace(newValue))
                    {
                        UInt16 tmp = new UInt16();
                        tmp      = 0;
                        sigValue = tmp;
                    }
                    else
                    {
                        sigValue = Convert.ToUInt16(newValue);
                    }
                    break;

                case SignalDataItem.BPValueType.I32:
                    if (string.IsNullOrWhiteSpace(newValue))
                    {
                        Int32 tmp = new Int32();
                        tmp      = 0;
                        sigValue = tmp;
                    }
                    else
                    {
                        sigValue = Convert.ToInt32(newValue);
                    }
                    break;

                case SignalDataItem.BPValueType.I16:
                    if (string.IsNullOrWhiteSpace(newValue))
                    {
                        Int16 tmp = new Int16();
                        tmp      = 0;
                        sigValue = tmp;
                    }
                    else
                    {
                        sigValue = Convert.ToInt16(newValue);
                    }
                    break;

                case SignalDataItem.BPValueType.ENUM:
                    if (string.IsNullOrWhiteSpace(newValue))
                    {
                        UInt16 tmp = new UInt16();
                        tmp      = 0;
                        sigValue = tmp;
                    }
                    else
                    {
                        sigValue = Convert.ToUInt16(newValue);
                    }
                    break;

                case SignalDataItem.BPValueType.FLOAT:
                    if (string.IsNullOrWhiteSpace(newValue))
                    {
                        float tmp;
                        tmp      = 0;
                        sigValue = tmp;
                    }
                    else
                    {
                        sigValue = (float)(Convert.ToDouble(newValue));
                    }
                    break;

                case SignalDataItem.BPValueType.STRING:
                    sigValue = "\"" + newValue + "\"";
                    break;

                case SignalDataItem.BPValueType.BOOLEAN:
                    if (SignalDataItem.yesOrNoTable.ContainsKey(newValue))
                    {
                        sigValue = SignalDataItem.yesOrNoTable[newValue];
                    }
                    else
                    {
                        ret = false;
                    }

                    break;

                case SignalDataItem.BPValueType.MEM:
                    /* TODO: set it mem values */
                    sigValue = newValue;
                    break;
                }
            }
            catch (Exception e)
            {
                Console.Write(e.Message);
                ret = false;
            }

            return(ret);
        }