Ejemplo n.º 1
0
        /// <summary>
        /// 数据类型转换WCS-->PLC
        /// </summary>
        /// <param name="type"></param>
        /// <param name="v"></param>
        /// <returns></returns>
        private BllResult TansforWCSDataToAddressData(PLCDataType type, string data)
        {
            try
            {
                object obj = null;
                switch (type)
                {
                case PLCDataType.BYTE:
                    obj = Convert.ToInt32(data); break;

                case PLCDataType.BOOL:
                    obj = Convert.ToBoolean(data); break;

                case PLCDataType.DWORD:
                    obj = Convert.ToUInt32(data); break;

                case PLCDataType.WORD:
                    obj = Convert.ToUInt16(data); break;

                case PLCDataType.INT:
                    obj = Convert.ToInt16(data); break;

                case PLCDataType.DINT:
                    obj = Convert.ToInt32(data); break;

                case PLCDataType.CHAR:
                    obj = ConverHelper.StringToASCII(data); break;

                default:
                    obj = data;
                    break;
                }
                return(BllResultFactory.Sucess(obj, "成功"));
            }
            catch (Exception ex)
            {
                return(BllResultFactory.Error(null, "WCS到PLC数据转换出现异常,值:" + data + " 目标类型:" + type + " 异常:" + ex.ToString()));
            }
        }