예제 #1
0
        // 较好使用
        // 方法1: 取当前方法的名字, 要求, 方法名与内置功能名称一致

        public string Home_Dir(Home_Dir vEn)
        {
            if (vEn.v00.cmdName == eDev485obj.Free)
            {
                vEn.v00.cmdName = (eDev485obj)Enum.Parse(
                    typeof(eDev485obj),
                    vEn.GetType().Name);
            }
            return(doObjectToString(vEn));
        }
예제 #2
0
        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);
        }
예제 #3
0
        /*
         * 把需要的参数,顺序放到设备域的 bt_out数组中
         * 此函数 取 数组中的数据放到 对象中,组合为字符串
         * --- 用法比较麻烦 ---
         * int _ref = vDevNo * _faim3.sect_iDev;  // 偏移
         * _faim3.Comm_Data._bt_out[0][_ref + 1] = 12;
         * _faim3.Comm_Data._bt_out[0][_ref + 2] = X;
         * _faim3.Comm_Data._bt_out[0][_ref + 3] = Y;
         * call doProtocol_01(-1, "home_set_pos", 2)
         * ------
         */
        string doProtocol_01(int vAxisNum = -1, string vCmdName = "", int vDevNo = 0)
        {
            string _res = "";

            if (string.IsNullOrEmpty(vCmdName))
            {
                return(_res);                                 // 命令名为空
            }
            //if (vAxisNum < 0) return _res;
            int _ref = vDevNo * _faim3.sect_iDev;  // 偏移

            if (vAxisNum < 0)
            {
                vAxisNum = _faim3.Comm_Data._bt_out[0][_ref + 1]; // 无轴号,则自动取轴号
            }
            int i = 0;

            switch (vCmdName.ToLower())
            {
                #region //..
            case "home_set_pos":
                _res = home_Set_Pos(vAxisNum);
                break;

            case "home_set_posa":
                _res = home_Set_PosA(vAxisNum);
                break;

            case "motoron":
                _res = MotorOn(vAxisNum);
                break;

            case "motoroff":
                _res = MotorOff(vAxisNum);
                break;

            case "motoralarmreset":
                _res = MotorAlarmReset(vAxisNum);
                break;

            case "readstatus":
                _res = ReadStatus(vAxisNum);
                break;

            case "readpos":
                _res = ReadPOS(vAxisNum);
                break;

            case "stopmove":
                _res = StopMove(vAxisNum);
                break;

            case "position_a_move":
                _res = Position_A_Move(vAxisNum);
                break;

            case "position_r_move":
                _res = Position_R_Move(vAxisNum);
                break;

            case "setregistersub":
                SetRegisterSub _en1 = new SetRegisterSub();
                _en1.v00.cmdName = eDev485obj.SetRegisterSub;
                _en1.v01.AxisNum = vAxisNum;
                i             = _ref + 2;
                _en1.v02.Addr = _faim3.Comm_Data._bt_out[0][i++];
                _en1.v03.Acc  = _faim3.Comm_Data._bt_out[0][i++];
                _res          = SetRegisterSub(_en1);
                break;

            case "outputline":
                OutputLine _OutputLine = new OutputLine();
                _OutputLine.v00.cmdName = eDev485obj.OutputLine;
                _OutputLine.v01.AxisNum = vAxisNum;
                i = _ref + 2;
                _OutputLine.v02.InputNum  = _faim3.Comm_Data._bt_out[0][i++];
                _OutputLine.v03.Condition = _faim3.Comm_Data._bt_out[0][i++];
                _res = OutputLine(_OutputLine);
                break;

            case "seekhome":
                SeekHome _SeekHome = new SeekHome();
                _SeekHome.v00.cmdName = eDev485obj.SeekHome;
                _SeekHome.v01.AxisNum = vAxisNum;
                i = _ref + 2;
                _SeekHome.v02.OutputNum = _faim3.Comm_Data._bt_out[0][i++];
                _SeekHome.v03.Condition = _faim3.Comm_Data._bt_out[0][i++];
                _res = SeekHome(_SeekHome);
                break;

            case "home_dir":
                Home_Dir _Home_Dir = new Home_Dir();
                _Home_Dir.v00.cmdName = eDev485obj.Home_Dir;
                _Home_Dir.v01.AxisNum = vAxisNum;
                i = _ref + 2;
                _Home_Dir.v02.Acc      = _faim3.Comm_Data._bt_out[0][i++];
                _Home_Dir.v03.Dec      = _faim3.Comm_Data._bt_out[0][i++];
                _Home_Dir.v04.Vel      = _faim3.Comm_Data._bt_out[0][i++];
                _Home_Dir.v05.Location = _faim3.Comm_Data._bt_out[0][i++];
                _Home_Dir.v06.Location = _faim3.Comm_Data._bt_out[0][i++];
                _res = Home_Dir(_Home_Dir);        // 一般使用



                break;

            case "position_set_pos":
                Position_Set_Pos _Position_Set_Pos = new Position_Set_Pos();
                _Position_Set_Pos.v00.cmdName = eDev485obj.Position_Set_Pos;
                _Position_Set_Pos.v01.AxisNum = vAxisNum;
                i = _ref + 2;
                _Position_Set_Pos.v02.Acc      = _faim3.Comm_Data._bt_out[0][i++];
                _Position_Set_Pos.v03.Dec      = _faim3.Comm_Data._bt_out[0][i++];
                _Position_Set_Pos.v04.Vel      = _faim3.Comm_Data._bt_out[0][i++];
                _Position_Set_Pos.v05.Location = _faim3.Comm_Data._bt_out[0][i++];
                _Position_Set_Pos.v06.Location = _faim3.Comm_Data._bt_out[0][i++];
                _res = Position_Set_Pos(_Position_Set_Pos);
                break;
                #endregion
            }
            return(_res);
        }