static int getSendData(clsFaim3 _faim3, string vCmdName, string vHL, string vReset) { 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 vCmdName = _faim3.dict_DevFunction[vCmdName].varName; } else { F_Log.Error_4("clsProtocol.getSendData()", string.Format(" --->>>> 此命令不存在 {0} {1} {2}", vCmdName, vHL, vReset)); return(-1); //没有此命令 模板 } int _ref_1i = _faim3.sect_iDev * _devNo; int _ref_1s = _faim3.sect_sDev * _devNo + _faim3.sect_sDev_start; string _str_HL = " "; string _str_Reset = " "; int _val_HL = F_TransCalc._Get_Value_2(_faim3, vHL, ref _str_HL); int _val_Reset = F_TransCalc._Get_Value_2(_faim3, vReset, ref _str_Reset); clsCommonInfo _en = null; if (_val_Reset > 0) { if (_faim3.dict_CommonInfo.ContainsKey(_val_Reset)) // 可能是表值 tb_CommonInfo.xls { _en = _faim3.dict_CommonInfo[_val_Reset]; } } switch ((eDeviceName)_devNo) { case eDeviceName.RS485_6: #region // RS485_6 if (_en != null) // 有表值 tb_CommonInfo.xls { #region // SeekHome Home_Dir switch (vCmdName) { case "SeekHome": SeekHome _SeekHome = _faim3._SeekHome; _SeekHome.v02.OutputNum = F_Parse._ConverToInt(clsFaim3.StringFormat(_faim3, _en.val_01)); _SeekHome.v03.Condition = F_Parse._ConverToInt(clsFaim3.StringFormat(_faim3, _en.val_02)); break; case "Home_Dir": Home_Dir _Home_Dir = _faim3._Home_Dir; _Home_Dir.v02.Acc = F_Parse._ConverToDouble(clsFaim3.StringFormat(_faim3, _en.val_01)); _Home_Dir.v03.Dec = F_Parse._ConverToInt(clsFaim3.StringFormat(_faim3, _en.val_02)); _Home_Dir.v04.Vel = F_Parse._ConverToDouble(clsFaim3.StringFormat(_faim3, _en.val_03)); _Home_Dir.v05.Location = F_Parse._ConverTofloat(clsFaim3.StringFormat(_faim3, _en.arr_01[0])); _Home_Dir.v06.Location = F_Parse._ConverTofloat(clsFaim3.StringFormat(_faim3, _en.arr_01[1])); break; } #endregion } clsProt485 _485 = new clsProt485(_faim3); _485.Out_Ready(vCmdName, _val_HL); // 485 对象 break; #endregion case eDeviceName.TCP_5: case eDeviceName.TCP_8: case eDeviceName.TCP_9: string _Format2 = _faim3.dict_CmdFormats[vCmdName].Format; //[2]; 模板 //clsRobot_AZ _az = new clsRobot_AZ(_faim3); List <string> _lstPara = new List <string>(); if (_val_HL != -999) { // $GetVariable,{0}&CrLf if (!string.IsNullOrEmpty(vHL)) { _lstPara.Add(vHL); } } else if (_str_HL != " ") { if (!string.IsNullOrEmpty(vHL)) { _lstPara.Add(_str_HL); } } if (_en != null) // 有表值 { // J Point {0} {1} {2} {3} if (!string.IsNullOrEmpty(_en.val_01)) { _lstPara.Add(clsFaim3.StringFormat(_faim3, _en.val_01)); } if (!string.IsNullOrEmpty(_en.val_02)) { _lstPara.Add(clsFaim3.StringFormat(_faim3, _en.val_02)); } if (!string.IsNullOrEmpty(_en.val_03)) { _lstPara.Add(clsFaim3.StringFormat(_faim3, _en.val_03)); } if (!string.IsNullOrEmpty(_en.arr_1)) { _lstPara.Add(clsFaim3.StringFormat(_faim3, _en.arr_1)); } if (!string.IsNullOrEmpty(_en.arr_2)) { _lstPara.Add(clsFaim3.StringFormat(_faim3, _en.arr_2)); } if (!string.IsNullOrEmpty(_en.arr_3)) { _lstPara.Add(clsFaim3.StringFormat(_faim3, _en.arr_3)); } } _faim3._sss[_ref_1s] = ""; // 非标准二进制字节码 string _cmd = F_TransCalc.StringFormat(_Format2, _lstPara); _faim3._sss[_ref_1s + _faim3.snd_sAsc] = _cmd; // string _Echo4 = _faim3.dict_CmdFormats[vCmdName].Echo; //[4]; 反馈 _faim3._sss[_ref_1s + _faim3.test_sLoc] = _Echo4; break; } return(_devNo); }
// 返回待发送数据的绝对位置 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); }