Example #1
0
 private void fmMain_FormClosing(object sender, FormClosingEventArgs e)
 {
     Thread.Sleep(500);
     for (byte i = 0; i < EziMOTIONPlusRLib.MAX_SLAVE_NUMS; i++)
     {
         if (EziMOTIONPlusRLib.FAS_IsSlaveExist(VarGlobal.PortNo, i) != 0)
         {
             int nRtn = EziMOTIONPlusRLib.FAS_ServoEnable(VarGlobal.PortNo, i, 0);
             if (nRtn != EziMOTIONPlusRLib.FMM_OK)
             {
                 string strMsg;
                 strMsg = "FAS_ServoEnable() \nReturned: " + nRtn.ToString();
                 MessageBox.Show(strMsg, "Function Failed");
             }
         }
     }
 }
Example #2
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            byte SlaveNo;
            int  nRtn;

            if (m_bConnected == false)
            {
                return;
            }
            if (textSlaveNo.Text.Length <= 0)
            {
                textSlaveNo.Focus();
                return;
            }
            SlaveNo = byte.Parse(textSlaveNo.Text);
            nRtn    = EziMOTIONPlusRLib.FAS_ServoEnable(m_nPortNo, SlaveNo, 1);
            if (nRtn != EziMOTIONPlusRLib.FMM_OK)
            {
                string strMessage;
                strMessage = "FAS_ServoEnable() \nReturned:" + nRtn.ToString();
                MessageBox.Show(strMessage, "Function Failed");
            }
        }
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            var woker = sender as BackgroundWorker;

            Invoke(new MethodInvoker(delegate
            {
                if (comboBoxPortNo.Text.Length <= 0)
                {
                    comboBoxPortNo.Focus();
                    return;
                }
                if (comboBoxAdamCOM.Text.Length <= 0)
                {
                    comboBoxAdamCOM.Focus();
                    return;
                }
            }));

            //Connect ezi step plus R

            while (_mConnected == false)
            {
                Invoke(new MethodInvoker(delegate
                {
                    _portNo  = byte.Parse(comboBoxPortNo.Text);
                    _adamCOM = int.Parse(comboBoxAdamCOM.Text);
                    dwBaud   = uint.Parse(comboBaudrate.Text);
                }));

                if (EziMOTIONPlusRLib.FAS_Connect(_portNo, dwBaud) == 0)
                {
                    //error connect
                    //MessageBox.Show("Error Connect!");
                    if (SuccessConnect != null)
                    {
                        //VarGlobal._portNo = 0;
                        SuccessConnect(CheckConnection.fail);
                        this.Close();
                    }
                }
                else
                {
                    for (byte i = 1; i <= 3; i++)
                    {
                        if (EziMOTIONPlusRLib.FAS_IsSlaveExist(_portNo, i) != 0)
                        {
                            int nRnt_1 = EziMOTIONPlusRLib.FAS_GetAxisStatus(_portNo, i, ref dwAxisStatus);
                            if (nRnt_1 != EziMOTIONPlusRLib.FMM_OK)
                            {
                                string strMsg;
                                strMsg = "FAS_GetAxisStatus() \nReturned: " + nRnt_1.ToString();
                                MessageBox.Show(strMsg, "Function Failed");
                                return;
                            }
                            //reset alarm if there is alarm
                            if ((dwAxisStatus & 0x00000001) != 0) // FFLAG_ERRORALL is ON
                            {
                                int nRnt_2 = EziMOTIONPlusRLib.FAS_StepAlarmReset(_portNo, i, 1);
                                if (nRnt_2 != EziMOTIONPlusRLib.FMM_OK)
                                {
                                    string strMsg;
                                    strMsg = "FAS_ServoAlarmReset() \nReturned: " + nRnt_2.ToString();
                                    MessageBox.Show(strMsg, "Function Failed");
                                    return;
                                }
                            }
                            //all servo on
                            int nRnt_3 = EziMOTIONPlusRLib.FAS_ServoEnable(_portNo, i, 1);
                            if (nRnt_3 != EziMOTIONPlusRLib.FMM_OK)
                            {
                                string strMsg;
                                strMsg = "FAS_ServoEnable() \nReturned: " + nRnt_3.ToString();
                                MessageBox.Show(strMsg, "Function Failed");
                                return;
                            }
                        }
                        VarGlobal._3AxisReady += 1;
                    }
                    if (VarGlobal._3AxisReady >= 3)
                    {
                        _mConnected = true;
                        while (_count <= 100 && _mConnected == true)
                        {
                            Thread.Sleep(100);
                            woker.ReportProgress(_count);
                            _count += 10;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Error occur!");
                    }
                }
            }
            if (SuccessConnect != null)
            {
                VarGlobal.PortNo      = _portNo;
                VarGlobal.m_Connected = _mConnected;
                VarGlobal.AdamCOM     = _adamCOM;
                SuccessConnect(CheckConnection.success);
            }
        }