Exemplo n.º 1
0
        /// <summary>
        /// 数据类型转换PLC-->WCS
        /// </summary>
        /// <param name="type"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        private BllResult <String> TransforAddressDataToWCSData(PLCDataType type, object data)
        {
            string str;

            try
            {
                switch (type)
                {
                case PLCDataType.BYTE:
                    int i = Convert.ToInt32(data);
                    str = i.ToString();
                    break;

                case PLCDataType.BOOL:
                case PLCDataType.DWORD:
                case PLCDataType.WORD:
                case PLCDataType.INT:
                case PLCDataType.DINT:
                    str = data.ToString(); break;

                case PLCDataType.CHAR:
                    str = ConverHelper.ASCIIToString((short[])data).Trim().Replace("$03", "").Replace("\u0003", "").Replace("\0", ""); break;

                default:
                    str = data.ToString();
                    break;
                }

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