Esempio n. 1
0
        void Btn_CardInit_Click(object sender, EventArgs e)
        {
            int status = -1;

            headcard = new HZC_Head08Card(1, 7);
            try
            {
                if (CAN_flag)
                {
                    status = headcard.Initial(1, 0);
                    if (status == 0)
                    {
                        SetText("初始化成功!", -1);
                        for (int i = 0; i < 8; i++)
                        {
                            headcard.SetPfParam(i, 35, 0.03, 0);
                            headcard.SetPfParam(i, 70, 0.026, 1);
                            headcard.SetPfParam(i, 100, 0.024, 2);
                            headcard.SetPfParam(i, 130, 0.024, 3);
                            headcard.SetPfParam(i, 170, 0.020, 4);
                            headcard.SetPfParam(i, 200, 0.015, 5);
                        }


                        Card_flag = true;
                    }
                    else
                    {
                        SetText("初始化失败!", -1);
                        Card_flag = false;
                    }
                }
                else
                {
                    SetText("请打开CAN卡!", -1);
                }
            }
            catch { }
        }
Esempio n. 2
0
    private int home()
    {
        HZC_Head08Card headcard = new HZC_Head08Card(1, 7);
        int            status   = 0;

        switch (home_flag)
        {
        case 0:
            headcard.SetPos(axis, 0);
            headcard.SetEncPos(axis, 0);
            if (headcard.GetAxisSensor(homesensorid) == sensorstate)
            {
                home_flag = 1;
            }
            else
            {
                home_flag = 20;
            }
            break;

        case 1:    //处于感应状态
            //headcard.PfMove(axis, pulse, 0);
            headcard.CnstMove(axis, speed1, -10000);
            home_flag = 2;
            break;

        case 2:
            int s = -1;
            s = headcard.GetAxisSensor(homesensorid);
            if (s != sensorstate)
            {
                headcard.AbortMoving(axis);
                sw.StartStopWatch(150);
                while (!sw.TimeUp())
                {
                    ;
                }
                home_flag = 3;
            }
            break;

        case 3:
            headcard.SearchForhomepos(axis, 0, 450, 300);

            sw.StartStopWatch(300);

            home_flag = 4;
            break;

        case 4:
            //if (headcard.GetStatus(axis) != 0) break;

            while (!sw.TimeUp())
            {
                ;
            }
            if (headcard.GetAxisSensor(homesensorid) == 0)
            {
                headcard.SetPos(axis, 0);
            }
            else
            {
                home_flag = 3;
                break;
            }
            home_flag = 0;
            status    = 1;
            break;

        case 20:    //未感应状态
            headcard.CnstMove(axis, speed1, 10000);
            home_flag = 21;

            break;

        case 21:
            //headcard.CnstMove(axis, 100, 1000);
            if (headcard.GetAxisSensor(homesensorid) == sensorstate)
            {
                headcard.AbortMoving(axis);
                sw.StartStopWatch(150);
                while (!sw.TimeUp())
                {
                    ;
                }
                home_flag = 1;
            }
            break;
        }
        return(status);
    }