예제 #1
0
 private void FormApp_Load(object sender, EventArgs e)
 {
     tabPageTorque.Controls.Add(formTorque);
     tabPageFeeder.Controls.Add(formFeeder);
     tabPageRCON.Controls.Add(formRCON);
     formTorque.Awake();
     bot.Connect();
     timer1s.Enabled = true;
 }
예제 #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Process thisProc = Process.GetCurrentProcess();

            thisProc.PriorityClass = ProcessPriorityClass.RealTime;

            bot.Connect();
            Thread.Sleep(500);

            timer1.Interval = 50;
            timer1.Enabled  = true;
        }
예제 #3
0
 private void button2_Click(object sender, EventArgs e)
 {
     bot.Connect();
     if (wsState != 2)
     {
         wsState      = 1;
         hasSlaveInfo = false;
     }
 }
예제 #4
0
 // WS 連線控制
 private void buttonWS_Click(object sender, EventArgs e)
 {
     if (wsState == 2)
     {
         bot.Disconnect();
     }
     else if (wsState == 0)
     {
         bot.Connect();
     }
     wsState = 1;
 }
예제 #5
0
        private void Form1_Load(object sender, EventArgs e)
        {
            bot = new Botnana("192.168.7.2");

            onWsErrorCallback = new HandleMessage(OnWsErrorCB);
            bot.SetOnErrorCB(IntPtr.Zero, onWsErrorCallback);

            onMessageCallback = new HandleMessage(HandleMessageCB);
            bot.SetOnMessageCB(IntPtr.Zero, onMessageCallback);

            slavesRespondingCallback = new HandleMessage(SlavesRespondingCB);
            bot.SetTagCB("slaves_responding", 0, IntPtr.Zero, slavesRespondingCallback);

            statusWordCallback = new HandleMessage(StatusWordCB);
            bot.SetTagCB("status_word.1.1", 0, IntPtr.Zero, statusWordCallback);

            realPositionCallback = new HandleMessage(RealPositionCB);
            bot.SetTagCB("real_position.1.1", 0, IntPtr.Zero, realPositionCallback);

            targetPositionCallback = new HandleMessage(TargetPositionCB);
            bot.SetTagCB("target_position.1.1", 0, IntPtr.Zero, targetPositionCallback);

            opModeCallback = new HandleMessage(OpModeCB);
            bot.SetTagCB("operation_mode.1.1", 0, IntPtr.Zero, opModeCallback);

            digitalInputsCallback = new HandleMessage(DigitalInputsCB);
            bot.SetTagCB("digital_inputs.1.1", 0, IntPtr.Zero, digitalInputsCallback);

            profileVelocityCallback = new HandleMessage(ProfileVelocityCB);
            bot.SetTagCB("profile_velocity.1.1", 0, IntPtr.Zero, profileVelocityCallback);

            profileAccelerationCallback = new HandleMessage(ProfileAccelerationCB);
            bot.SetTagCB("profile_acceleration.1.1", 0, IntPtr.Zero, profileAccelerationCallback);

            deployedCallback = new HandleMessage(DeployedCB);
            bot.SetTagCB("deployed", 0, IntPtr.Zero, deployedCallback);

            endOfProgramCallback = new HandleMessage(EndOfProgramCB);
            bot.SetTagCB("end-of-program", 0, IntPtr.Zero, endOfProgramCallback);

            errorCallback = new HandleMessage(ErrorCB);
            bot.SetTagCB("error", 0, IntPtr.Zero, errorCallback);

            bot.Connect();
            Thread.Sleep(1000);

            bot.EvaluateScript(".ec-links");
            bot.EvaluateScript("1 .slave");
            timer1.Interval = 50;
            timer1.Enabled  = true;
        }
예제 #6
0
        private void timerSlow_Tick(object sender, EventArgs e)
        {
            // 處理 WebSocket 的連線狀態
            if (wsState == 2)
            {
                buttonWs.BackColor = Color.SpringGreen;
            }
            else if (wsState == 1)
            {
                buttonWs.BackColor = Color.Gold;
            }
            else
            {
                // 自動連線
                bot.Connect();
                wsState            = 1;
                buttonWs.BackColor = Color.IndianRed;
            }


            if (ecReady)
            {
                buttonEtherCAT.BackColor = Color.SpringGreen;
            }
            else
            {
                buttonEtherCAT.BackColor = Color.IndianRed;
            }
            buttonEtherCAT.Text = @"ECAT(" + slavesLen.ToString() + @")";

            // 當有錯誤發生時,需要 Acked 才會顯示下一個錯誤訊息
            if (errorsLen == 0)
            {
                buttonError.BackColor = Color.SpringGreen;
                buttonError.Text      = "Acked";
            }
            else
            {
                buttonError.BackColor = Color.IndianRed;
                buttonError.Text      = "Error";
            }

            if (systemReady)
            {
                buttonSystemReady.BackColor = Color.SpringGreen;
            }
            else
            {
                buttonSystemReady.BackColor = Color.IndianRed;
            }
        }
예제 #7
0
        private void timerWSCheck_Tick(object sender, EventArgs e)
        {
            // 處理 WebSocket 的連線狀態
            if (wsState == 2)
            {
                buttonWS.BackColor = Color.SpringGreen;
            }
            else if (wsState == 1)
            {
                buttonWS.BackColor = Color.Gold;
            }
            else
            {
                // 自動連線
                bot.Connect();
                wsState            = 1;
                buttonWS.BackColor = Color.IndianRed;
            }

            // 當有錯誤發生時,需要 Acked 才會顯示下一個錯誤訊息
            if (hasAcked)
            {
                buttonErrorAck.BackColor = Color.SpringGreen;
                buttonErrorAck.Text      = "Acked";
            }
            else
            {
                buttonErrorAck.BackColor = Color.IndianRed;
                buttonErrorAck.Text      = "Error";
            }

            // 顯示同動是否有啟動
            if (coordinatorEnabled)
            {
                buttonCoordinator.BackColor = Color.SpringGreen;
            }
            else
            {
                buttonCoordinator.BackColor = Color.IndianRed;
            }

            if (hasSFC)
            {
                buttonSFCReload.BackColor = Color.SpringGreen;
            }
            else
            {
                buttonSFCReload.BackColor = Color.IndianRed;
            }
        }
예제 #8
0
        private void Form1_Load(object sender, EventArgs e)
        {
            bot = new Botnana("192.168.7.2");

            onWsErrorCallback = new HandleMessage(OnWsErrorCB);
            bot.SetOnErrorCB(IntPtr.Zero, onWsErrorCallback);

            sdoIndexCallback = new HandleMessage(SdoIndexCB);
            bot.SetTagCB("sdo_index.1", 0, IntPtr.Zero, sdoIndexCallback);

            sdoSubindexCallback = new HandleMessage(SdoSubindexCB);
            bot.SetTagCB("sdo_subindex.1", 0, IntPtr.Zero, sdoSubindexCallback);

            sdoErrorCallback = new HandleMessage(SdoErrorCB);
            bot.SetTagCB("sdo_error.1", 0, IntPtr.Zero, sdoErrorCallback);

            sdoBusyCallback = new HandleMessage(SdoBusyCB);
            bot.SetTagCB("sdo_busy.1", 0, IntPtr.Zero, sdoBusyCallback);

            sdoDataCallback = new HandleMessage(SdoDataCB);
            bot.SetTagCB("sdo_data.1", 0, IntPtr.Zero, sdoDataCallback);

            realPositionCallback = new HandleMessage(RealPositionCB);
            bot.SetTagCB("real_position.1.1", 0, IntPtr.Zero, realPositionCallback);

            digitalInputsCallback = new HandleMessage(DigitalInputsCB);
            bot.SetTagCB("digital_inputs.1.1", 0, IntPtr.Zero, digitalInputsCallback);

            opModeCallback = new HandleMessage(OpModeCB);
            bot.SetTagCB("operation_mode.1.1", 0, IntPtr.Zero, opModeCallback);

            statusWordCallback = new HandleMessage(StatusWordCB);
            bot.SetTagCB("status_word.1.1", 0, IntPtr.Zero, statusWordCallback);

            errorCallback = new HandleMessage(ErrorCB);
            bot.SetTagCB("error", 0, IntPtr.Zero, errorCallback);

            homingCallback = new HandleMessage(HomingCB);
            bot.SetTagCB("homing", 0, IntPtr.Zero, homingCallback);

            slavesRespondingCallback = new HandleMessage(SlavesRespondingCB);
            bot.SetTagCB("slaves_responding", 1, IntPtr.Zero, slavesRespondingCallback);
            bot.Connect();
            Thread.Sleep(1000);
            bot.EvaluateScript(".ec-links 0 $60B8 1 sdo-upload-i16 1 .slave");

            timer1.Interval = 50;
            timer1.Enabled  = true;
        }
예제 #9
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            switch (webSocketState)
            {
            case 0:
                bot.Connect();
                webSocketState = 1;
                Console.WriteLine("Trying to connect to Botnana.");
                break;

            case 2:
                // Do something after ready.
                break;

            default:
                break;
            }
        }
예제 #10
0
 private void timerSlow_Tick(object sender, EventArgs e)
 {
     textErrorCount.Text = errorMessageLen.ToString();
     // 設定 WebSocket 連線狀態的顏色
     if (wsState == 2)
     {
         buttonWebSocket.BackColor = Color.SpringGreen;
     }
     else if (wsState == 1)
     {
         buttonWebSocket.BackColor = Color.Gold;
     }
     else
     {
         // 嘗試重新連線
         buttonWebSocket.BackColor = Color.IndianRed;
         botnana.Connect();
         wsState = 1;
     }
 }
예제 #11
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Process thisProc = Process.GetCurrentProcess();

            thisProc.PriorityClass = ProcessPriorityClass.RealTime;

            bot = new Botnana("192.168.7.2");

            onWSOpen = new HandleMessage(OnWSOpenCallback);
            bot.SetOnOpenCB(IntPtr.Zero, onWSOpen);

            onWSError = new HandleMessage(OnWSErrorCallback);
            bot.SetOnErrorCB(IntPtr.Zero, onWSError);

            onMessage = new HandleMessage(OnMessageCallback);
            bot.SetOnMessageCB(IntPtr.Zero, onMessage);

            onDiWord = new HandleMessage(OnDiWordCallback);
            bot.SetTagCB("din_wd.1.3", 0, IntPtr.Zero, onDiWord);

            onDoWord = new HandleMessage(OnDoWordCallback);
            bot.SetTagCB("dout_wd.1.2", 0, IntPtr.Zero, onDoWord);

            onSlavesResponding = new HandleMessage(OnSlavesRespondingCallback);
            bot.SetTagCB(@"slaves_responding", 0, IntPtr.Zero, onSlavesResponding);

            onSlavesState = new HandleMessage(OnSlavesStateCallback);
            bot.SetTagCB(@"al_states", 0, IntPtr.Zero, onSlavesState);

            bot.Connect();

            timer1.Interval = 50;
            timer1.Enabled  = true;

            timer2.Interval = 1000;
            timer2.Enabled  = true;
        }
예제 #12
0
        private void timer2_Tick(object sender, EventArgs e)
        {
            string cmd = null;

            if (hasSFC)
            {
                cmd += @" poll";
            }

            // ".ec-links" 此命令會只回傳 EtherCAT 的連線狀態
            // slaves_responding|5|al_states|8|link_up|1|input_wc|2|output_wc|2|input_wc_state|1
            // |output_wc_state|1|input_wc_error|179|output_wc_error|213|waiting_sdos_len|0
            //
            // slaves_responding 表示有多少從站連線
            // al_states: 8 表示所有從站都是在 Operation 狀態
            cmd += @" .ec-links";

            bot.EvaluateScript(cmd);

            if (!homingMethodAccessed)
            {
                textHomingMethod.Text = homingMethod.ToString();
            }
            if (!homingSpeed1Accessed)
            {
                textHomingSpeed1.Text = homingSpeed1.ToString();
            }
            if (!homingSpeed2Accessed)
            {
                textHomingSpeed2.Text = homingSpeed2.ToString();
            }

            if (!homingAccAccessed)
            {
                textHomingAcc.Text = homingAcc.ToString();
            }

            if (!encoderPPUAccessed)
            {
                textEncoderPPU.Text = encoderPPU.ToString("F1");
            }
            labelEncoderResolution.Text = "pulse/" + encoderLengthUnit.Substring(0, 1).ToLower();

            if (!axisVmaxAccessed)
            {
                textAxisVmax.Text = axisVmax.ToString("F1");
            }
            if (!axisAmaxAccessed)
            {
                textAxisAmax.Text = axisAmax.ToString("F1");
            }
            if (!driveAliasAccessed)
            {
                textDriveAlias.Text = driveAlias.ToString();
            }
            if (!driveSlavePositionAccessed)
            {
                textDriveSlavePosition.Text = driveSlavePosition.ToString();
            }
            if (!driveChannelAccessed)
            {
                textDriveChannel.Text = driveChannel.ToString();
            }

            textGroupType.Text = groupType;

            if (!groupMappingAccessed)
            {
                textGroupMapping.Text = groupMapping;
            }
            if (!groupVmaxAccessed)
            {
                textGroupVmax.Text = groupVmax.ToString("F1");
            }
            if (!groupAmaxAccessed)
            {
                textGroupAmax.Text = groupAmax.ToString("F1");
            }
            if (!groupJmaxAccessed)
            {
                textGroupJmax.Text = groupJmax.ToString("F1");
            }

            // 處理 WebSocket 的連線狀態
            if (wsState == 2)
            {
                buttonWSState.BackColor = Color.LightGreen;
            }
            else if (wsState == 1)
            {
                buttonWSState.BackColor = Color.Gold;
            }
            else
            {
                // 自動連線
                bot.Connect();
                wsState = 1;
                buttonWSState.BackColor = Color.IndianRed;
            }

            // 處理 System Ready 狀態顯示
            if (systemReady)
            {
                buttonSystemState.BackColor = Color.LightGreen;
            }
            else
            {
                buttonSystemState.BackColor = Color.IndianRed;
            }

            switch (pdsState)
            {
            case "Operation Enabled":
                buttonDriveOn.BackColor    = Color.LightGreen;
                buttonDriveOff.BackColor   = SystemColors.Control;
                buttonResetFault.BackColor = SystemColors.Control;
                break;

            case "Fault":
                buttonDriveOn.BackColor    = SystemColors.Control;
                buttonDriveOff.BackColor   = Color.IndianRed;
                buttonResetFault.BackColor = Color.IndianRed;
                break;

            default:
                buttonDriveOn.BackColor    = SystemColors.Control;
                buttonDriveOff.BackColor   = Color.IndianRed;
                buttonResetFault.BackColor = SystemColors.Control;
                break;
            }
        }
예제 #13
0
        private void timerWs_Tick(object sender, EventArgs e)
        {
            bot.EvaluateScript(@".ec-links");

            // 處理 WebSocket 的連線狀態
            if (wsState == 2)
            {
                buttonWs.BackColor = Color.SpringGreen;
            }
            else if (wsState == 1)
            {
                buttonWs.BackColor = Color.Gold;
            }
            else
            {
                // 自動連線
                bot.Connect();
                wsState            = 1;
                buttonWs.BackColor = Color.IndianRed;
            }

            // 顯示同動是否有啟動
            if (coordinatorEnabled)
            {
                buttonCoordinator.BackColor = Color.SpringGreen;
            }
            else
            {
                buttonCoordinator.BackColor = Color.IndianRed;
            }

            // 當有錯誤發生時,需要 Acked 才會顯示下一個錯誤訊息
            if (hasAcked)
            {
                buttonErrorAck.BackColor = Color.SpringGreen;
                buttonErrorAck.Text      = "Acked";
            }
            else
            {
                buttonErrorAck.BackColor = Color.IndianRed;
                buttonErrorAck.Text      = "Error";
            }

            if (hasSFC)
            {
                buttonReloadSfc.BackColor = Color.SpringGreen;
            }
            else
            {
                buttonReloadSfc.BackColor = Color.IndianRed;
            }

            textSlaves.Text = slavesLen.ToString();
            if (ecReady)
            {
                textSlaves.BackColor = Color.SpringGreen;
            }
            else
            {
                textSlaves.BackColor = Color.IndianRed;
            }

            Boolean allDriveOn = true;

            for (int i = 1; i <= 4; i++)
            {
                if (!isDriveOns[i])
                {
                    allDriveOn = false;
                    break;
                }
            }
            if (allDriveOn && !coordinatorEnabled)
            {
                bot.EvaluateScript(@"+coordinator");
            }

            if (isDriveOns[1])
            {
                buttonOn1.Text      = @"ON";
                buttonOn1.BackColor = Color.SpringGreen;
            }
            else
            {
                buttonOn1.Text      = @"OFF";
                buttonOn1.BackColor = Color.Gold;
            }
            if (isDriveOns[2])
            {
                buttonOn2.Text      = @"ON";
                buttonOn2.BackColor = Color.SpringGreen;
            }
            else
            {
                buttonOn2.Text      = @"OFF";
                buttonOn2.BackColor = Color.Gold;
            }
            if (isDriveOns[3])
            {
                buttonOn3.Text      = @"ON";
                buttonOn3.BackColor = Color.SpringGreen;
            }
            else
            {
                buttonOn3.Text      = @"OFF";
                buttonOn3.BackColor = Color.Gold;
            }
            if (isDriveOns[4])
            {
                buttonOn4.Text      = @"ON";
                buttonOn4.BackColor = Color.SpringGreen;
            }
            else
            {
                buttonOn4.Text      = @"OFF";
                buttonOn4.BackColor = Color.Gold;
            }

            if (isDriveFaults[1])
            {
                buttonFault1.BackColor = Color.IndianRed;
            }
            else
            {
                buttonFault1.BackColor = Color.SpringGreen;
            }
            if (isDriveFaults[2])
            {
                buttonFault2.BackColor = Color.IndianRed;
            }
            else
            {
                buttonFault2.BackColor = Color.SpringGreen;
            }
            if (isDriveFaults[3])
            {
                buttonFault3.BackColor = Color.IndianRed;
            }
            else
            {
                buttonFault3.BackColor = Color.SpringGreen;
            }
            if (isDriveFaults[4])
            {
                buttonFault4.BackColor = Color.IndianRed;
            }
            else
            {
                buttonFault4.BackColor = Color.SpringGreen;
            }
        }
예제 #14
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Process thisProc = Process.GetCurrentProcess();

            thisProc.PriorityClass = ProcessPriorityClass.RealTime;

            bot = new Botnana("192.168.7.2");

            onWSError = new HandleMessage(OnWSErrorCallback);
            bot.SetOnErrorCB(IntPtr.Zero, onWSError);

            onMessage = new HandleMessage(OnMessageCallback);
            bot.SetOnMessageCB(IntPtr.Zero, onMessage);

            onUserParameter = new HandleMessage(OnUserParameterCallback);
            bot.SetTagCB(@"user_parameter", 0, IntPtr.Zero, onUserParameter);

            onError = new HandleMessage(OnErrorCallback);
            bot.SetTagCB(@"error", 0, IntPtr.Zero, onError);
            onPr3411 = new HandleMessage(OnPr3411Callback);
            bot.SetTagCB(@"pr3411 ", 0, IntPtr.Zero, onPr3411);
            onPr3444 = new HandleMessage(OnPr3444Callback);
            bot.SetTagCB(@"pr3444 ", 0, IntPtr.Zero, onPr3444);
            onPr3445 = new HandleMessage(OnPr3445Callback);
            bot.SetTagCB(@"pr3445 ", 0, IntPtr.Zero, onPr3445);
            onPr3447 = new HandleMessage(OnPr3447Callback);
            bot.SetTagCB(@"pr3447 ", 0, IntPtr.Zero, onPr3447);
            onPr3448 = new HandleMessage(OnPr3448Callback);
            bot.SetTagCB(@"pr3448 ", 0, IntPtr.Zero, onPr3448);
            onPr3449 = new HandleMessage(OnPr3449Callback);
            bot.SetTagCB(@"pr3449 ", 0, IntPtr.Zero, onPr3449);
            onPr3450 = new HandleMessage(OnPr3450Callback);
            bot.SetTagCB(@"pr3450 ", 0, IntPtr.Zero, onPr3450);
            onPr3451 = new HandleMessage(OnPr3451Callback);
            bot.SetTagCB(@"pr3451 ", 0, IntPtr.Zero, onPr3451);
            onPr3452 = new HandleMessage(OnPr3452Callback);
            bot.SetTagCB(@"pr3452 ", 0, IntPtr.Zero, onPr3452);
            onPr3453 = new HandleMessage(OnPr3453Callback);
            bot.SetTagCB(@"pr3453 ", 0, IntPtr.Zero, onPr3453);
            onPr3454 = new HandleMessage(OnPr3454Callback);
            bot.SetTagCB(@"pr3454 ", 0, IntPtr.Zero, onPr3454);
            onPr3455 = new HandleMessage(OnPr3455Callback);
            bot.SetTagCB(@"pr3455 ", 0, IntPtr.Zero, onPr3455);
            onPr3456 = new HandleMessage(OnPr3456Callback);
            bot.SetTagCB(@"pr3456 ", 0, IntPtr.Zero, onPr3456);
            onPr3457 = new HandleMessage(OnPr3457Callback);
            bot.SetTagCB(@"pr3457 ", 0, IntPtr.Zero, onPr3457);

            onSlavesResponding = new HandleMessage(OnSlavesRespondingCallback);
            bot.SetTagCB(@"slaves_responding", 0, IntPtr.Zero, onSlavesResponding);

            onWaitingSDOs = new HandleMessage(OnWaitingSDOsCallback);
            bot.SetTagCB(@"waiting_sdos_len", 0, IntPtr.Zero, onWaitingSDOs);

            onOperationMode = new HandleMessage(OnOperationModeCallback);
            bot.SetTagCB(@"operation_mode.1.1", 0, IntPtr.Zero, onOperationMode);

            onHomingMethod = new HandleMessage(OnHomingMethodCallback);
            bot.SetTagCB(@"homing_method.1.1", 0, IntPtr.Zero, onHomingMethod);

            onHomingSpeed2 = new HandleMessage(OnHomingSpeed2Callback);
            bot.SetTagCB(@"homing_speed_2.1.1", 0, IntPtr.Zero, onHomingSpeed2);

            onProfileVelocity = new HandleMessage(OnProfileVelocityCallback);
            bot.SetTagCB(@"profile_velocity.1.1", 0, IntPtr.Zero, onProfileVelocity);

            onProfileAcc = new HandleMessage(OnProfileAccCallback);
            bot.SetTagCB(@"profile_acceleration.1.1", 0, IntPtr.Zero, onProfileAcc);

            onRealPosition = new HandleMessage(OnRealPositionCallback);
            bot.SetTagCB(@"real_position.1.1", 0, IntPtr.Zero, onRealPosition);

            onTargetPosition = new HandleMessage(OnTargetPositionCallback);
            bot.SetTagCB(@"target_position.1.1", 0, IntPtr.Zero, onTargetPosition);

            onPDSState = new HandleMessage(OnPDSStateCallback);
            bot.SetTagCB(@"pds_state.1.1", 0, IntPtr.Zero, onPDSState);

            bot.Connect();

            timer1.Interval = 50;
            timer1.Enabled  = true;
            timer2.Interval = 200;
            timer2.Enabled  = true;
        }
예제 #15
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Process thisProc = Process.GetCurrentProcess();

            thisProc.PriorityClass = ProcessPriorityClass.RealTime;

            bot = new Botnana("192.168.7.2");

            // WS 連線錯誤就呼叫 OnWSErrorCallback
            onWSError = new HandleMessage(OnWSErrorCallback);
            bot.SetOnErrorCB(IntPtr.Zero, onWSError);

            // WS 連線成功就呼叫 OnWSOpenCallback
            onWSOpen = new HandleMessage(OnWSOpenCallback);
            bot.SetOnOpenCB(IntPtr.Zero, onWSOpen);

            // 收到 tag = slaves_responding 就呼叫 OnSlavesRespondingCallback
            onSlavesResponding = new HandleMessage(OnSlavesRespondingCallback);
            bot.SetTagCB(@"slaves_responding", 0, IntPtr.Zero, onSlavesResponding);

            // 收到 tag = al_states 就呼叫 OnSlavesStateCallback
            onSlavesState = new HandleMessage(OnSlavesStateCallback);
            bot.SetTagCB(@"al_states", 0, IntPtr.Zero, onSlavesState);

            // 收到 tag = error 就呼叫 OnErrorMessageCallback
            onErrorMessage = new HandleMessage(OnErrorMessageCallback);
            bot.SetTagCB(@"error", 0, IntPtr.Zero, onErrorMessage);

            // 收到 tag = ain.1.4 就呼叫 OnAin1Callback
            // ain.1.4 表示第 4 個從站第 1 管道的 AIN
            onAins[1] = new HandleMessage(OnAin1Callback);
            bot.SetTagCB(@"ain.1." + DeltaAinSlavePosStr, 0, IntPtr.Zero, onAins[1]);
            onAins[2] = new HandleMessage(OnAin2Callback);
            bot.SetTagCB(@"ain.2." + DeltaAinSlavePosStr, 0, IntPtr.Zero, onAins[2]);
            onAins[3] = new HandleMessage(OnAin3Callback);
            bot.SetTagCB(@"ain.3." + DeltaAinSlavePosStr, 0, IntPtr.Zero, onAins[3]);
            onAins[4] = new HandleMessage(OnAin4Callback);
            bot.SetTagCB(@"ain.4." + DeltaAinSlavePosStr, 0, IntPtr.Zero, onAins[4]);

            // 收到 tag = aout.1.4 就呼叫 OnAout1Callback
            // aout.1.5 表示第 5 個從站第 1 管道的 Aout
            onAouts[1] = new HandleMessage(OnAout1Callback);
            bot.SetTagCB(@"aout.1." + DeltaAoutSlavePosStr, 0, IntPtr.Zero, onAouts[1]);
            onAouts[2] = new HandleMessage(OnAout2Callback);
            bot.SetTagCB(@"aout.2." + DeltaAoutSlavePosStr, 0, IntPtr.Zero, onAouts[2]);
            onAouts[3] = new HandleMessage(OnAout3Callback);
            bot.SetTagCB(@"aout.3." + DeltaAoutSlavePosStr, 0, IntPtr.Zero, onAouts[3]);
            onAouts[4] = new HandleMessage(OnAout4Callback);
            bot.SetTagCB(@"aout.4." + DeltaAoutSlavePosStr, 0, IntPtr.Zero, onAouts[4]);

            // 收到 tag = ain_enabled.1.4 就呼叫 OnAin1EnabledCallback
            // ain_enabled.1.4 表示第 4 個從站第 1 管道的 AIN Enabled
            onAinsEnabled[1] = new HandleMessage(OnAin1EnabledCallback);
            bot.SetTagCB(@"ain_enabled.1." + DeltaAinSlavePosStr, 0, IntPtr.Zero, onAinsEnabled[1]);
            onAinsEnabled[2] = new HandleMessage(OnAin2EnabledCallback);
            bot.SetTagCB(@"ain_enabled.2." + DeltaAinSlavePosStr, 0, IntPtr.Zero, onAinsEnabled[2]);
            onAinsEnabled[3] = new HandleMessage(OnAin3EnabledCallback);
            bot.SetTagCB(@"ain_enabled.3." + DeltaAinSlavePosStr, 0, IntPtr.Zero, onAinsEnabled[3]);
            onAinsEnabled[4] = new HandleMessage(OnAin4EnabledCallback);
            bot.SetTagCB(@"ain_enabled.4." + DeltaAinSlavePosStr, 0, IntPtr.Zero, onAinsEnabled[4]);

            // 收到 tag = aout_enabled.1.5 就呼叫 OnAout1EnabledCallback
            // aout_enabled.1.5 表示第 5 個從站第 1 管道的 AOUT Enabled
            onAoutsEnabled[1] = new HandleMessage(OnAout1EnabledCallback);
            bot.SetTagCB(@"aout_enabled.1." + DeltaAoutSlavePosStr, 0, IntPtr.Zero, onAoutsEnabled[1]);
            onAoutsEnabled[2] = new HandleMessage(OnAout2EnabledCallback);
            bot.SetTagCB(@"aout_enabled.2." + DeltaAoutSlavePosStr, 0, IntPtr.Zero, onAoutsEnabled[2]);
            onAoutsEnabled[3] = new HandleMessage(OnAout3EnabledCallback);
            bot.SetTagCB(@"aout_enabled.3." + DeltaAoutSlavePosStr, 0, IntPtr.Zero, onAoutsEnabled[3]);
            onAoutsEnabled[4] = new HandleMessage(OnAout4EnabledCallback);
            bot.SetTagCB(@"aout_enabled.4." + DeltaAoutSlavePosStr, 0, IntPtr.Zero, onAoutsEnabled[4]);

            // 收到 tag = aout1_mode 就呼叫 OnAout1ModeCallback
            onAoutsMode[1] = new HandleMessage(OnAout1ModeCallback);
            bot.SetTagCB(@"aout1_mode", 0, IntPtr.Zero, onAoutsMode[1]);
            onAoutsMode[2] = new HandleMessage(OnAout2ModeCallback);
            bot.SetTagCB(@"aout2_mode", 0, IntPtr.Zero, onAoutsMode[2]);
            onAoutsMode[3] = new HandleMessage(OnAout3ModeCallback);
            bot.SetTagCB(@"aout3_mode", 0, IntPtr.Zero, onAoutsMode[3]);
            onAoutsMode[4] = new HandleMessage(OnAout4ModeCallback);
            bot.SetTagCB(@"aout4_mode", 0, IntPtr.Zero, onAoutsMode[4]);
            onAinMode = new HandleMessage(OnAinModeCallback);
            bot.SetTagCB(@"ain_mode", 0, IntPtr.Zero, onAinMode);

            // 收到 tag = user_parameter 就呼叫 OnUserParameterCallback
            onUserParameter = new HandleMessage(OnUserParameterCallback);
            bot.SetTagCB(@"user_parameter", 0, IntPtr.Zero, onUserParameter);

            // 進行連線
            wsState = 1;
            bot.Connect();

            timer1.Interval = 50;
            timer1.Enabled  = true;
            timer2.Interval = 1000;
            timer2.Enabled  = true;

            radioAin1Enabled.AutoCheck   = false;
            radioAin2Enabled.AutoCheck   = false;
            radioAin3Enabled.AutoCheck   = false;
            radioAin4Enabled.AutoCheck   = false;
            radioAout1Enabled.AutoCheck  = false;
            radioAout2Enabled.AutoCheck  = false;
            radioAout3Enabled.AutoCheck  = false;
            radioAout4Enabled.AutoCheck  = false;
            comboAout1Mode.SelectedIndex = 0;
            comboAout2Mode.SelectedIndex = 0;
            comboAout3Mode.SelectedIndex = 0;
            comboAout4Mode.SelectedIndex = 0;
            comboAinMode.SelectedIndex   = 0;
            groupAinStatus.Text          = "AIN Status (Slave " + DeltaAinSlavePosStr + ")";
            groupAoutStatus.Text         = "AOUT Status (Slave " + DeltaAoutSlavePosStr + ")";
        }
예제 #16
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Process thisProc = Process.GetCurrentProcess();

            thisProc.PriorityClass = ProcessPriorityClass.RealTime;
            mcsPositions           = new double[3];
            pcsPositions           = new double[3];
            pva               = new double[3];
            axisHomed         = new int[3];
            axisRealPositions = new double[3];
            axisHomingV1      = new UInt32[3];
            axisHomingV2      = new UInt32[3];
            axisHomingMethod  = new UInt32[3];

            // 首先要連線到 Botnana Control, 當收到 WS 連線錯誤, 就呼叫 on_error_callback
            bot = new Botnana("192.168.7.2");
            bot.SetOnErrorCB(IntPtr.Zero, onWSError);

            // 當收到 Botnana Control 的訊息, 就呼叫 on_message_callback
            bot.SetOnMessageCB(IntPtr.Zero, onMessage);
            // 定義收到信息中指定的 Tag 時,所要呼叫的 callback 信息
            bot.SetTagCB("MCS.1", 0, IntPtr.Zero, onMcs);
            bot.SetTagCB("PCS.1", 0, IntPtr.Zero, onPcs);
            bot.SetTagCB("pva.1", 0, IntPtr.Zero, onPva);
            bot.SetTagCB("move_length.1", 0, IntPtr.Zero, onMoveLength);
            bot.SetTagCB("path_id.1", 0, IntPtr.Zero, onPathId);
            bot.SetTagCB("servo_on", 0, IntPtr.Zero, onServoOn);
            bot.SetTagCB("motion_state", 0, IntPtr.Zero, onMotionState);
            bot.SetTagCB("axis_corrected_position.1", 0, IntPtr.Zero, onAxisRealPositionX);
            bot.SetTagCB("axis_corrected_position.2", 0, IntPtr.Zero, onAxisRealPositionY);
            bot.SetTagCB("axis_corrected_position.3", 0, IntPtr.Zero, onAxisRealPositionZ);
            bot.SetTagCB("axis_homed.1", 0, IntPtr.Zero, onAxisHomedX);
            bot.SetTagCB("axis_homed.2", 0, IntPtr.Zero, onAxisHomedY);
            bot.SetTagCB("axis_homed.3", 0, IntPtr.Zero, onAxisHomedZ);
            bot.SetTagCB("nc_owner", 0, IntPtr.Zero, onNcOwner);
            bot.SetTagCB("nc_suspended", 0, IntPtr.Zero, onNcSuspended);
            bot.SetTagCB("devices_ok", 0, IntPtr.Zero, onDevicesOk);
            bot.SetTagCB("monitor_failed", 0, IntPtr.Zero, onMonitorFailed);
            bot.SetTagCB("rapid_travels_rate", 0, IntPtr.Zero, onRapidTravelsRate);
            bot.SetTagCB("machining_rate", 0, IntPtr.Zero, onMachiningRate);
            bot.SetTagCB("axis_homing_v1.1", 0, IntPtr.Zero, onAxisHomingV1X);
            bot.SetTagCB("axis_homing_v1.2", 0, IntPtr.Zero, onAxisHomingV1Y);
            bot.SetTagCB("axis_homing_v1.3", 0, IntPtr.Zero, onAxisHomingV1Z);
            bot.SetTagCB("axis_homing_v2.1", 0, IntPtr.Zero, onAxisHomingV2X);
            bot.SetTagCB("axis_homing_v2.2", 0, IntPtr.Zero, onAxisHomingV2Y);
            bot.SetTagCB("axis_homing_v2.3", 0, IntPtr.Zero, onAxisHomingV2Z);
            bot.SetTagCB("axis_homing_method.1", 0, IntPtr.Zero, onAxisHomingMethodX);
            bot.SetTagCB("axis_homing_method.2", 0, IntPtr.Zero, onAxisHomingMethodY);
            bot.SetTagCB("axis_homing_method.3", 0, IntPtr.Zero, onAxisHomingMethodZ);
            bot.SetTagCB("error", 0, IntPtr.Zero, onError);
            bot.SetTagCB("log", 0, IntPtr.Zero, onLog);
            bot.SetTagCB("user_parameter", 0, IntPtr.Zero, onUserParameter);
            bot.SetTagCB("deployed", 0, IntPtr.Zero, onDeployed);

            bot.Connect();
            Thread.Sleep(1000);
            // 要求  Botnana Control 送出 user parameter 訊息
            bot.EvaluateScript(".user-para");

            // 初始化 NC program 內容
            DataGridViewRowCollection rows = ncProgram.Rows;

            rows.Add(new Object[] { "1", "92", "0.0", "0.0", "0.0", "900.0" });
            rows.Add(new Object[] { "2", "01", "10", null, null, "500" });
            rows.Add(new Object[] { "3", "01", "20", null, null, "500" });
            rows.Add(new Object[] { "4", "01", "30", null, null, "500" });
            rows.Add(new Object[] { "5", "01", "40", null, null, "500" });
            rows.Add(new Object[] { "6", "01", "50", null, null, "600" });
            rows.Add(new Object[] { "7", "01", "60", null, null, "700" });
            rows.Add(new Object[] { "8", "01", "70", null, null, "800" });
            rows.Add(new Object[] { "9", "01", "80", null, null, "900" });
            rows.Add(new Object[] { "10", "01", "90", null, null, "1000" });

            // 設置 timer
            timer1.Interval = 50;
            timer1.Enabled  = true;
            timer2.Interval = 500;
            timer2.Enabled  = true;
        }