Exemple #1
0
        // 复杂协议格式二: 最优使用 ---------------------------
        // 方法2: 取当前数据类的名字, 要求,数据类与内置功能名称一致



        // ReadStatus,{0}{1}|01 02 03 04 05 v02.Acc_2|v03.Dec_2
        public string doObjectToString(object vEn)
        {
            string        _rec = "";
            Base_Set_Para _en  = vEn as Base_Set_Para;

            if (_en.v00.cmdName == eDev485obj.Free)
            {
                return(_rec);
            }
            string _format     = _faim3.dict_CmdFormats[_en.v00.cmdName.ToString()].Format;//[2];
            string _split_flag = " ";

            string[] _arr1 = _format.Split(_split_flag[0]);
            for (int i = 0; i < _arr1.Length; i++)
            {
                if (!_arr1[i].Contains('.'))
                {
                    continue;
                }
                string[] _ar_0 = _arr1[i].Split('|');
                for (int j = 0; j < _ar_0.Length; j++)
                {
                    string[] _ar_1 = _ar_0[j].Split('_');
                    int      _len  = 2;
                    if (_ar_1.Length > 1)
                    {
                        _len = Convert.ToInt32(_ar_1[1]);
                    }
                    string _v_1 = F_TransCalc.doGetValue_byName(vEn, _ar_1[0]);
                    if (j == 0)
                    {
                        _arr1[i] = F_TransCalc.doDecToHexs(
                            F_Parse._ConverToDouble(_v_1), 16, _len, _split_flag);
                    }
                    else
                    {
                        _arr1[i] = _arr1[i] + _split_flag +
                                   F_TransCalc.doDecToHexs(
                            F_Parse._ConverToDouble(_v_1), 16, _len, _split_flag);
                    }
                }
            }
            //
            string _k = _en.v00.cmdName.ToString() + "_k";

            if (_faim3.dict_CmdFormats.ContainsKey(_k))
            {
                _k = _faim3.dict_CmdFormats[_k].Format;//[2];
                string[] _ar_11 = _k.Split('|');
                foreach (var item in _ar_11)
                {
                    string[] _arr12 = item.Split('_');
                    int      _idx   = Convert.ToInt32(_arr12[0]) - 1;
                    int      _add   = Convert.ToInt32(_arr12[1], 16);
                    int      _mul   = Convert.ToInt32(_arr12[2], 16);
                    int      _val   = Convert.ToInt32(_arr1[_idx], 16);
                    _val        = _add + _val * _mul;
                    _arr1[_idx] = _val.ToString("X").PadLeft(2, '0');
                }
            }
            for (int i = 0; i < _arr1.Length; i++)
            {
                if (_rec == "")
                {
                    _rec = _arr1[i];
                }
                else
                {
                    _rec = _rec + _split_flag + _arr1[i];
                }
            }
            _rec = string.Format(_rec, _en.v00.cmdName.ToString(), _en.v01.AxisNum.ToString("X").PadLeft(2, '0'));
            return(_rec);
        }
Exemple #2
0
        // 返回待发送数据的绝对位置
        public int Out_Ready(string vCmdName, int vAxisNum)
        {
            int    _ret    = 0;
            string _result = "";

            string[] _names = Enum.GetNames(typeof(eDev485));
            if (Array.IndexOf(_names, vCmdName) > -1)
            {
                #region // 参数 SimpleFormat
                //int _AxisNum = Convert.ToInt32(vAxisNum);
                _result = doSimpleToString(new SimpleFormat()
                {
                    v01_AxisNum = vAxisNum,
                    v00_cmdName = (eDev485)Enum.Parse(
                        typeof(eDev485),
                        vCmdName)
                });
                #endregion
            }
            else
            {
                #region // 对象Home_Dir OutputLine Position_Set_Pos SeekHome SetRegisterSub
                switch (vCmdName)
                {
                case "Home_Dir":
                    _faim3._Home_Dir.v01.AxisNum = vAxisNum;
                    _result = Home_Dir(_faim3._Home_Dir);
                    break;

                case "OutputLine":
                    _faim3._OutputLine.v01.AxisNum = vAxisNum;
                    _result = OutputLine(_faim3._OutputLine);
                    break;

                case "Position_Set_Pos":
                    _faim3._Position_Set_Pos.v01.AxisNum = vAxisNum;
                    _result = Position_Set_Pos(_faim3._Position_Set_Pos);
                    break;

                case "SeekHome":
                    _faim3._SeekHome.v01.AxisNum = vAxisNum;
                    _result = SeekHome(_faim3._SeekHome);
                    break;

                case "SetRegisterSub":
                    _faim3._SetRegisterSub.v01.AxisNum = vAxisNum;
                    _result = SetRegisterSub(_faim3._SetRegisterSub);
                    break;
                }
                #endregion
            }
            #region // 置预发的数据
            int _devNo = -1;
            // 设备号
            if (_faim3.dict_CmdFormats.ContainsKey(vCmdName))
            {
                _devNo = Convert.ToInt32(_faim3.dict_CmdFormats[vCmdName].devNo);//[0] cfgCmdFormat.xls
            }
            else if (_faim3.dict_DevFunction.ContainsKey(vCmdName))
            {
                _devNo = _faim3.dict_DevFunction[vCmdName].devNo;//[0] cfgDev_Function.xls
            }
            else
            {
                F_Log.Error_4("clsProt485.Out_Ready()",
                              string.Format(" --->>>> 设备号不存在 {0} vAxisNum:{1}", vCmdName, vAxisNum));
                return(-1); //没有此命令 模板
            }
            int _ref_1i = _faim3.sect_iDev * _devNo;
            int _ref_1s = _faim3.sect_sDev * _devNo + _faim3.sect_sDev_start; // 偏移位

            string[] _arr  = _result.Split('|');                              // 分解模板
            string   _send = _arr.Length > 1 ? _arr[1] : _arr[0];
            int      _crc  = F_TransCalc.doCRC(_send);                        // AA BB CC DD CRC CRC
            _send = _send + " " + F_TransCalc.doDecToHexs(_crc);
            _faim3._sss[_ref_1s] = _send;                                     // 置 数据部份
            _faim3._sss[_ref_1s + _faim3.snd_sAsc]  = "";                     // 无ASCII, 置空
            _faim3._sss[_ref_1s + _faim3.test_sLoc] = vCmdName;               // 置 发出的命令
            _faim3._sss[_ref_1s + _faim3.snd_sLen]  = "0";                    // 置 长度为空
            #endregion
            _ret = _ref_1s + _faim3.snd_sLen;
            return(_ret);
        }