Ejemplo n.º 1
0
        public Test()
        {
            InitializeComponent();

            RunConsole();

            bot = new Botnana("192.168.7.2");

            onWSOpen = new HandleMessage((IntPtr dataPtr, string str) =>
            {
                webSocketState = 2;
                BeginInvoke(new Deg(() =>
                {
                    sdoControl1.Awake();
                    driveControl1.Awake();
                    axisControl1.Awake();
                }));
                Console.WriteLine("WS connected.");
            });
            bot.SetOnOpenCB(IntPtr.Zero, onWSOpen);

            onWSError = new HandleMessage((IntPtr dataPtr, string str) =>
            {
                webSocketState = 0;
                BeginInvoke(new Deg(() =>
                {
                    sdoControl1.Sleep();
                    driveControl1.Sleep();
                    axisControl1.Sleep();
                }));
                Console.WriteLine("WS error : " + str);
            });
            bot.SetOnErrorCB(IntPtr.Zero, onWSError);

            onMessage = new HandleMessage((IntPtr dataPtr, string str) =>
            {
                Console.WriteLine("OnMessage : " + str);
            });
            bot.SetOnMessageCB(IntPtr.Zero, onMessage);

            onErrorMessage = new HandleMessage((IntPtr dataPtr, string str) =>
            {
                Console.WriteLine("Error|" + str);
            });
            bot.SetTagCB(@"error", 0, IntPtr.Zero, onErrorMessage);

            sdoControl1.InitializeBotnana(bot);
            axisControl1.InitializeBotnana(bot);
            realTimeScriptControl1.InitializeBotnana(bot);
            driveControl1.InitializeBotnana(bot);
        }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
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;
        }
Ejemplo n.º 5
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);
            onWSOpen = new HandleMessage(OnWSOpenCallback);
            bot.SetOnOpenCB(IntPtr.Zero, onWSOpen);
            onMessage = new HandleMessage(OnMessageCallback);
            bot.SetOnMessageCB(IntPtr.Zero, onMessage);

            onUserParameter = new HandleMessage(OnUserParameterCallback);
            bot.SetTagCB(@"user_parameter", 0, IntPtr.Zero, onUserParameter);
            onRTRealTorque = new HandleMessage(OnRTRealTorqueCallback);
            bot.SetTagCB(@"rt_real_torque", 0, IntPtr.Zero, onRTRealTorque);
            onSlavesResponding = new HandleMessage(OnSlavesRespondingCallback);
            bot.SetTagCB(@"slaves_responding", 0, IntPtr.Zero, onSlavesResponding);
            onSlavesState = new HandleMessage(OnSlavesStateCallback);
            bot.SetTagCB(@"al_states", 0, IntPtr.Zero, onSlavesState);
            onWaitingSDOs = new HandleMessage(OnWaitingSDOsCallback);
            bot.SetTagCB(@"waiting_sdos_len", 0, IntPtr.Zero, onWaitingSDOs);
            onPDSState = new HandleTagNameMessage(OnPDSStateCallback);
            bot.SetTagNameCB(@"pds_state", 0, IntPtr.Zero, onPDSState);
            onDriveStatus = new HandleTagNameMessage(OnDriveStatusCallback);
            bot.SetTagNameCB(@"status_word", 0, IntPtr.Zero, onDriveStatus);
            onOperationMode = new HandleTagNameMessage(OnOperationModeCallback);
            bot.SetTagNameCB(@"operation_mode", 0, IntPtr.Zero, onOperationMode);
            onHomingMethod = new HandleTagNameMessage(OnHomingMethodCallback);
            bot.SetTagNameCB(@"homing_method", 0, IntPtr.Zero, onHomingMethod);
            onHomingSpeed1 = new HandleTagNameMessage(OnHomingSpeed1Callback);
            bot.SetTagNameCB(@"homing_speed_1", 0, IntPtr.Zero, onHomingSpeed1);
            onHomingSpeed2 = new HandleTagNameMessage(OnHomingSpeed2Callback);
            bot.SetTagNameCB(@"homing_speed_2", 0, IntPtr.Zero, onHomingSpeed2);
            onHomingAcc = new HandleTagNameMessage(OnHomingAccCallback);
            bot.SetTagNameCB(@"homing_acceleration", 0, IntPtr.Zero, onHomingAcc);
            onProfileVelocity = new HandleTagNameMessage(OnProfileVelocityCallback);
            bot.SetTagNameCB(@"profile_velocity", 0, IntPtr.Zero, onProfileVelocity);
            onProfileAcc = new HandleTagNameMessage(OnProfileAccCallback);
            bot.SetTagNameCB(@"profile_acceleration", 0, IntPtr.Zero, onProfileAcc);
            onRealPosition = new HandleTagNameMessage(OnRealPositionCallback);
            bot.SetTagNameCB(@"real_position", 0, IntPtr.Zero, onRealPosition);
            onRealTorque = new HandleTagNameMessage(OnRealTorqueCallback);
            bot.SetTagNameCB(@"real_torque", 0, IntPtr.Zero, onRealTorque);
            onDigitalInputs = new HandleTagNameMessage(OnDigitalInputsCallback);
            bot.SetTagNameCB("digital_inputs", 0, IntPtr.Zero, onDigitalInputs);
            onTargetPosition = new HandleTagNameMessage(OnTargetPositionCallback);
            bot.SetTagNameCB(@"target_position", 0, IntPtr.Zero, onTargetPosition);
            onErrorMessage = new HandleMessage(OnErrorMessageCallback);
            bot.SetTagCB(@"error", 0, IntPtr.Zero, onErrorMessage);
            onAxisPosition = new HandleTagNameMessage(OnAxisPositionCallback);
            bot.SetTagNameCB(@"axis_demand_position", 0, IntPtr.Zero, onAxisPosition);
            onFeedbackPosition = new HandleTagNameMessage(OnFeedbackPositionCallback);
            bot.SetTagNameCB(@"feedback_position", 0, IntPtr.Zero, onFeedbackPosition);
            onEncoderLengthUnit = new HandleTagNameMessage(OnEncoderLengthUnitCallback);
            bot.SetTagNameCB(@"encoder_length_unit", 0, IntPtr.Zero, onEncoderLengthUnit);
            onEncoderPPU = new HandleTagNameMessage(OnEncoderPPUCallback);
            bot.SetTagNameCB(@"encoder_ppu", 0, IntPtr.Zero, onEncoderPPU);
            onDriveAlias = new HandleTagNameMessage(OnDriveAliasCallback);
            bot.SetTagNameCB(@"drive_alias", 0, IntPtr.Zero, onDriveAlias);
            onDriveSlavePosition = new HandleTagNameMessage(OnDriveSlavePositionCallback);
            bot.SetTagNameCB(@"drive_slave_position", 0, IntPtr.Zero, onDriveSlavePosition);
            onDriveChannel = new HandleTagNameMessage(OnDriveChannelCallback);
            bot.SetTagNameCB(@"drive_channel", 0, IntPtr.Zero, onDriveChannel);
            onAxisVmax = new HandleTagNameMessage(OnAxisVmaxCallback);
            bot.SetTagNameCB(@"axis_vmax", 0, IntPtr.Zero, onAxisVmax);
            onAxisAmax = new HandleTagNameMessage(OnAxisAmaxCallback);
            bot.SetTagNameCB(@"axis_amax", 0, IntPtr.Zero, onAxisAmax);
            onGroupType = new HandleTagNameMessage(OnGroupTypeCallback);
            bot.SetTagNameCB(@"group_type", 0, IntPtr.Zero, onGroupType);
            onGroupMapping = new HandleTagNameMessage(OnGroupMappingCallback);
            bot.SetTagNameCB(@"group_mapping", 0, IntPtr.Zero, onGroupMapping);
            onGroupVmax = new HandleTagNameMessage(OnGroupVmaxCallback);
            bot.SetTagNameCB(@"group_vmax", 0, IntPtr.Zero, onGroupVmax);
            onGroupAmax = new HandleTagNameMessage(OnGroupAmaxCallback);
            bot.SetTagNameCB(@"group_amax", 0, IntPtr.Zero, onGroupAmax);
            onGroupJmax = new HandleTagNameMessage(OnGroupJmaxCallback);
            bot.SetTagNameCB(@"group_jmax", 0, IntPtr.Zero, onGroupJmax);
            onTravelTime = new HandleMessage(OnTravelTimeCallback);
            bot.SetTagCB(@"travel_time", 0, IntPtr.Zero, onTravelTime);
            onDeviceInfos = new HandleMessage(OnDeviceInfos);
            bot.SetTagCB(@"device_infos", 1, IntPtr.Zero, onDeviceInfos);
            onSystemReady = new HandleMessage(OnSystemReady);
            bot.SetTagCB(@"system_ready", 0, IntPtr.Zero, onSystemReady);

            chartTorque.ChartAreas[0].AxisX.Minimum = 0;
            chartTorque.ChartAreas[0].AxisX.Maximum = QueueCapacity;

            timer1.Interval           = 10;
            timer1.Enabled            = true;
            timer2.Interval           = 500;
            timer2.Enabled            = true;
            torqueThread              = new Thread(new ThreadStart(this.getTorqueInformation));
            pauseEvent                = new ManualResetEvent(false);
            torqueThread.IsBackground = true;
            torqueThread.Start();
        }
Ejemplo n.º 6
0
        private void Form1_Load(object sender, EventArgs e)
        {
            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 = error 就呼叫 OnErrorMessageCallback
            onErrorMessage = new HandleMessage(OnErrorMessageCallback);
            bot.SetTagCB(@"error", 0, IntPtr.Zero, onErrorMessage);

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

            onAxisSectionPositions = new HandleTagNameMessage(OnAxisSectionPositions);
            bot.SetTagNameCB(@"axis_section_p", 0, IntPtr.Zero, onAxisSectionPositions);

            onAxisSectionVecloities = new HandleTagNameMessage(OnAxisSectionVecloities);
            bot.SetTagNameCB(@"axis_section_v", 0, IntPtr.Zero, onAxisSectionVecloities);

            onAxisRunnings = new HandleTagNameMessage(OnAxisRunnings);
            bot.SetTagNameCB(@"axis_running", 0, IntPtr.Zero, onAxisRunnings);

            onAxisCmds = new HandleTagNameMessage(OnAxisCmds);
            bot.SetTagNameCB(@"axis_command_position", 0, IntPtr.Zero, onAxisCmds);

            onAxisDemands = new HandleTagNameMessage(OnAxisDemands);
            bot.SetTagNameCB(@"axis_demand_position", 0, IntPtr.Zero, onAxisDemands);

            onAxisFeedbacks = new HandleTagNameMessage(OnAxisFeedbacks);
            bot.SetTagNameCB(@"feedback_position", 0, IntPtr.Zero, onAxisFeedbacks);

            onAxisReacheds = new HandleTagNameMessage(OnAxisReacheds);
            bot.SetTagNameCB(@"axis_interpolator_reached", 0, IntPtr.Zero, onAxisReacheds);

            onAxisInterpolatorEnables = new HandleTagNameMessage(OnAxisInterpolatorEnables);
            bot.SetTagNameCB(@"axis_interpolator_enabled", 0, IntPtr.Zero, onAxisInterpolatorEnables);

            onCoordinatorEnabled = new HandleMessage(OnCoordinatorEnabled);
            bot.SetTagCB(@"coordinator_enabled", 0, IntPtr.Zero, onCoordinatorEnabled);

            // 將區段位置與速度的參數元件放到一個陣列內
            textAxisSectionPositions[1, 1]  = textAxis1P1;
            textAxisSectionPositions[1, 2]  = textAxis1P2;
            textAxisSectionPositions[1, 3]  = textAxis1P3;
            textAxisSectionPositions[1, 4]  = textAxis1P4;
            textAxisSectionPositions[1, 5]  = textAxis1P5;
            textAxisSectionVecloities[1, 1] = textAxis1V1;
            textAxisSectionVecloities[1, 2] = textAxis1V2;
            textAxisSectionVecloities[1, 3] = textAxis1V3;
            textAxisSectionVecloities[1, 4] = textAxis1V4;
            textAxisSectionVecloities[1, 5] = textAxis1V5;
            textAxisSectionPositions[2, 1]  = textAxis2P1;
            textAxisSectionPositions[2, 2]  = textAxis2P2;
            textAxisSectionPositions[2, 3]  = textAxis2P3;
            textAxisSectionPositions[2, 4]  = textAxis2P4;
            textAxisSectionPositions[2, 5]  = textAxis2P5;
            textAxisSectionVecloities[2, 1] = textAxis2V1;
            textAxisSectionVecloities[2, 2] = textAxis2V2;
            textAxisSectionVecloities[2, 3] = textAxis2V3;
            textAxisSectionVecloities[2, 4] = textAxis2V4;
            textAxisSectionVecloities[2, 5] = textAxis2V5;

            timerWSCheck.Interval = 1000;
            timerWSCheck.Enabled  = true;
            timerLoop.Interval    = 50;
            timerLoop.Enabled     = true;
        }
Ejemplo n.º 7
0
        public FormApp()
        {
            InitializeComponent();

            bot = new Botnana("192.168.7.2");

            // 啟動終端機,可幫助除錯,若不使用可不啟動。
            RunConsole();

            // On WebSocket open callback.
            onWSOpen = new HandleMessage((IntPtr dataPtr, string str) =>
            {
                webSocketState = 2;
                rebooting      = false;
                BeginInvoke(new Appdeg(() =>
                {
                    buttonWSState.Text      = "WebSocket ready";
                    buttonWSState.BackColor = Color.FromArgb(0x53, 0xFF, 0x53);
                }));
                // 送出 .user-para 命令,讓為回傳的訊息去觸發 OnUserParameterCallback
                // 若重複執行從 32 開始,因為需要 .device-infos 取得周邊裝置的資訊
                // .user-para 回應的訊息範例如下:
                // user_parameter|0
                bot.EvaluateScript(@"user-para@ 32 min user-para! .user-para");
                Console.WriteLine("WebSocket connected.");
            });
            bot.SetOnOpenCB(IntPtr.Zero, onWSOpen);

            // On WebSocket error callback.
            onWSError = new HandleMessage((IntPtr dataPtr, string str) =>
            {
                webSocketState = 0;
                slavesCount    = 0;
                hasSFC         = false;
                BeginInvoke(new Appdeg(() => {
                    buttonWSState.Text          = "WebSocket not ready";
                    buttonWSState.BackColor     = Color.FromArgb(0xFF, 0x2D, 0x2D);
                    buttonECState.Text          = "EtherCAT not ready(" + slavesCount.ToString() + ")";
                    buttonECState.BackColor     = Color.FromArgb(0xFF, 0x2D, 0x2D);
                    buttonSystemReady.Text      = "System not ready";
                    buttonSystemReady.BackColor = Color.FromArgb(0xFF, 0x2D, 0x2D);
                }));
                formTorque.Reset();
                formFeeder.Reset();
                formRCON.Reset();
                Console.WriteLine("WS error : " + str);
            });
            bot.SetOnErrorCB(IntPtr.Zero, onWSError);

            // On Message callback.
            onMessage = new HandleMessage((IntPtr dataPtr, string str) =>
            {
                Console.WriteLine("OnMessage : " + str);
            });
            bot.SetOnMessageCB(IntPtr.Zero, onMessage);

            // On Error tag callback
            onErrorMessage = new HandleMessage((IntPtr dataPtr, string str) =>
            {
                if (errorsLen < 3)
                {
                    errorsLen += 1;
                    new Thread(() =>
                    {
                        System.Windows.Forms.MessageBox.Show("Error|" + str);
                        errorsLen -= 1;
                    }).Start();
                }
                Console.WriteLine("Error|" + str);
            });
            bot.SetTagCB(@"error", 0, IntPtr.Zero, onErrorMessage);

            // On user_parameter tag callback.
            onUserParameter = new HandleMessage((IntPtr dataPtr, string str) =>
            {
                switch (Int32.Parse(str))
                {
                case 0:
                    Console.WriteLine("OnUserParameterCallback 0");
                    if (webSocketState == 2 && !rebooting)
                    {
                        // 設定 user parameter 為 16,如果此範例重新執行不會再載入以下 SFC
                        bot.EvaluateScript("16 user-para!");
                        // 清除SFC 邏輯,載入 SFC 時會造成 real time cycle overrun,所以要暫時 ignore-overrun
                        bot.EvaluateScript(@"ignore-overrun 0sfc -work marker -work");
                        bot.LoadSFC(@"config.fs");
                        bot.LoadSFC(@"sdo.fs");
                        bot.LoadSFC(@"torque.fs");
                        bot.LoadSFC(@"feeder.fs");
                        bot.LoadSFC(@"rcon.fs");
                        bot.LoadSFC(@"manager.fs");
                        bot.EvaluateScript(@"marker -app .user-para");
                    }
                    break;

                case 16:
                    Console.WriteLine("OnUserParameterCallback 16");
                    // 載入後執行 `reset-overrun`
                    BotEvaluateScript(@"reset-overrun 32 user-para! .user-para");
                    break;

                case 32:
                    Console.WriteLine("OnUserParameterCallback 32");
                    formTorque.Initialize();
                    formFeeder.Initialize();
                    formRCON.Initialize();
                    BotEvaluateScript(@"+coordinator 64 user-para! .user-para");
                    break;

                case 64:
                    Console.WriteLine("OnUserParameterCallback 64");
                    hasSFC = true;
                    break;

                default:
                    break;
                }
            });
            bot.SetTagCB(@"user_parameter", 0, IntPtr.Zero, onUserParameter);

            // On ec_ready tag callback.
            onECReady = new HandleMessage((IntPtr dataPtr, string str) =>
            {
                if (str == "1")
                {
                    BeginInvoke(new Appdeg(() => {
                        buttonECState.Text      = "EtherCAT ready(" + slavesCount.ToString() + ")";
                        buttonECState.BackColor = Color.FromArgb(0x53, 0xFF, 0x53);
                    }));
                }
                else
                {
                    BeginInvoke(new Appdeg(() => {
                        buttonECState.Text      = "EtherCAT not ready(" + slavesCount.ToString() + ")";
                        buttonECState.BackColor = Color.FromArgb(0xFF, 0x2D, 0x2D);
                    }));
                }
            });
            bot.SetTagCB(@"ec_ready", 0, IntPtr.Zero, onECReady);

            // On slaves_responding tag callback.
            onSlavesResponding = new HandleMessage((IntPtr dataPtr, string str) =>
            {
                slavesCount = int.Parse(str);
            });
            bot.SetTagCB(@"slaves_responding", 0, IntPtr.Zero, onSlavesResponding);

            // On system_ready tag callback.
            onSystemReady = new HandleMessage((IntPtr dataPtr, string str) =>
            {
                if (str == "-1")
                {
                    BeginInvoke(new Appdeg(() => {
                        buttonSystemReady.Text      = "System ready";
                        buttonSystemReady.BackColor = Color.FromArgb(0x53, 0xFF, 0x53);
                    }));
                }
                else
                {
                    BeginInvoke(new Appdeg(() => {
                        buttonSystemReady.Text      = "System not ready";
                        buttonSystemReady.BackColor = Color.FromArgb(0xFF, 0x2D, 0x2D);
                    }));
                }
            });
            bot.SetTagCB(@"system_ready", 0, IntPtr.Zero, onSystemReady);

            formTorque = new FormTorque();
            formFeeder = new FormFeeder();
            formRCON   = new FormRCON();
        }
Ejemplo n.º 8
0
        private void Form1_Load(object sender, EventArgs e)
        {
            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);

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

            onCoordinatorEnabled = new HandleMessage(OnCoordinatorEnabled);
            bot.SetTagCB(@"coordinator_enabled", 0, IntPtr.Zero, onCoordinatorEnabled);

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

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

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

            onEcReady = new HandleMessage(OnEcReady);
            bot.SetTagCB(@"ec_ready", 0, IntPtr.Zero, onEcReady);

            onDeviceType = new HandleTagNameMessage(OnDeviceType);
            bot.SetTagNameCB(@"device_type", 0, IntPtr.Zero, onDeviceType);

            onDriveStatus = new HandleTagNameMessage(OnDriveStatus);
            bot.SetTagNameCB(@"status_word", 0, IntPtr.Zero, onDriveStatus);

            onAxesCmd = new HandleTagNameMessage(OnAxesCmd);
            bot.SetTagNameCB(@"axis_command_position", 0, IntPtr.Zero, onAxesCmd);

            onAxesFeedback = new HandleTagNameMessage(OnAxesFeedback);
            bot.SetTagNameCB(@"feedback_position", 0, IntPtr.Zero, onAxesFeedback);

            onAxesFollowingErr = new HandleTagNameMessage(OnAxesFollowingErr);
            bot.SetTagNameCB(@"following_error", 0, IntPtr.Zero, onAxesFollowingErr);

            onMPGEncoder = new HandleMessage(OnMPGEncoder);
            bot.SetTagCB("real_position.1.6", 0, IntPtr.Zero, onMPGEncoder);

            onMPGDis = new HandleMessage(OnMPGDisCB);
            bot.SetTagCB("din_wd.1.7", 0, IntPtr.Zero, onMPGDis);


            chartPath.ChartAreas[0].AxisX.Minimum               = -10.0;
            chartPath.ChartAreas[0].AxisX.Maximum               = 160.0;
            chartVelocity.ChartAreas[0].AxisX.Minimum           = 0;
            chartVelocity.ChartAreas[0].AxisX.Maximum           = 2000;
            chartVelocity.ChartAreas[0].AxisY.Minimum           = -500;
            chartVelocity.ChartAreas[0].AxisY.Maximum           = 2000;
            chartVelocity.Series[0].BorderWidth                 = 3;
            chartVelocity.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
            chartVelocity.ChartAreas[0].AxisX.MinorGrid.Enabled = false;
            chartVelocity.ChartAreas[0].AxisY.MajorGrid.Enabled = false;
            chartVelocity.ChartAreas[0].AxisY.MinorGrid.Enabled = false;

            pathThread              = new Thread(new ThreadStart(this.getPathInformation));
            velocityThread          = new Thread(new ThreadStart(this.getVelocityInformation));
            pauseEvent              = new ManualResetEvent(true);
            pathThread.IsBackground = true;
            pathThread.Start();
            velocityThread.IsBackground = true;
            velocityThread.Start();
            InitPathChart();
            InitVelocityChart();
        }
Ejemplo n.º 9
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;
        }
Ejemplo n.º 10
0
        public Form1()
        {
            InitializeComponent();
            bot = new Botnana("192.168.7.2");

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

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

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

            onSFCReady = new HandleMessage(OnSFCReadyCB);
            bot.SetTagCB("SFC_ready", 0, IntPtr.Zero, onSFCReady);

            onRCONReady = new HandleMessage(OnRCONReadyCB);
            bot.SetTagCB("RCON_ready", 0, IntPtr.Zero, onRCONReady);

            onPLCEnabled = new HandleMessage(OnPLCEnabledCB);
            bot.SetTagCB("PLC_enabled", 0, IntPtr.Zero, onPLCEnabled);

            onGWControl = new HandleMessage(OnGWControlCB);
            bot.SetTagCB("GW_control", 0, IntPtr.Zero, onGWControl);

            onGWStatus = new HandleMessage(OnGWStatusCB);
            bot.SetTagCB("GW_status", 0, IntPtr.Zero, onGWStatus);

            onAXControl = new HandleMessage(OnAXControlCB);
            bot.SetTagCB("AX_control", 0, IntPtr.Zero, onAXControl);

            onAXPSD = new HandleMessage(OnAXPSDCB);
            bot.SetTagCB("AX_PSD", 0, IntPtr.Zero, onAXPSD);

            onAXPW = new HandleMessage(OnAXPWCB);
            bot.SetTagCB("AX_PW", 0, IntPtr.Zero, onAXPW);

            onAXSPD = new HandleMessage(OnAXSPDCB);
            bot.SetTagCB("AX_SPD", 0, IntPtr.Zero, onAXSPD);

            onAXACDEC = new HandleMessage(OnAXACDECCB);
            bot.SetTagCB("AX_ACDEC", 0, IntPtr.Zero, onAXACDEC);

            onAXPCLV = new HandleMessage(OnAXPCLVCB);
            bot.SetTagCB("AX_PCLV", 0, IntPtr.Zero, onAXPCLV);

            onAXStatus = new HandleMessage(OnAXStatusCB);
            bot.SetTagCB("AX_status", 0, IntPtr.Zero, onAXStatus);

            onAXPPD = new HandleMessage(OnAXPPDCB);
            bot.SetTagCB("AX_PPD", 0, IntPtr.Zero, onAXPPD);

            onAXMCCV = new HandleMessage(OnAXMCCVCB);
            bot.SetTagCB("AX_MCCV", 0, IntPtr.Zero, onAXMCCV);

            onAXPSPD = new HandleMessage(OnAXPSPDCB);
            bot.SetTagCB("AX_PSPD", 0, IntPtr.Zero, onAXPSPD);

            onAXALMC = new HandleMessage(OnAXALMCCB);
            bot.SetTagCB("AX_ALMC", 0, IntPtr.Zero, onAXALMC);
        }
Ejemplo n.º 11
0
        private void Form1_Load(object sender, EventArgs e)
        {
            botnana = new Botnana("192.168.7.2");

            // 設定 callback function
            onWsErrorCallback = new HandleMessage(OnWsErrorCB);
            botnana.SetOnErrorCB(IntPtr.Zero, onWsErrorCallback);

            onWsOpenCallback = new HandleMessage(OnWsOpenCB);
            botnana.SetOnOpenCB(IntPtr.Zero, onWsOpenCallback);

            onErrorMessage = new HandleMessage(OnErrorMessageCB);
            botnana.SetTagCB("error", 0, IntPtr.Zero, onErrorMessage);

            onEcReady = new HandleMessage(OnEcReadyCB);
            botnana.SetTagCB("ec_ready", 0, IntPtr.Zero, onEcReady);

            onSlavesLen = new HandleMessage(OnSlavesLenCB);
            botnana.SetTagCB("slaves_responding", 0, IntPtr.Zero, onSlavesLen);

            onMPGEncoder = new HandleMessage(OnMPGEncoderCB);
            botnana.SetTagCB("real_position.1.3", 0, IntPtr.Zero, onMPGEncoder);

            onMPGDis = new HandleMessage(OnMPGDisCB);
            botnana.SetTagCB("din_wd.1.4", 0, IntPtr.Zero, onMPGDis);

            onDriveRealPosition = new HandleMessage(OnDriveRealPositionCB);
            botnana.SetTagCB("real_position.1.1", 0, IntPtr.Zero, onDriveRealPosition);

            onDriveTargetPosition = new HandleMessage(OnDriveTargetPositionCB);
            botnana.SetTagCB("target_position.1.1", 0, IntPtr.Zero, onDriveTargetPosition);

            onDriveStatus = new HandleMessage(OnDriveStatusCB);
            botnana.SetTagCB("status_word.1.1", 0, IntPtr.Zero, onDriveStatus);

            onDriveMode = new HandleMessage(OnDriveModeCB);
            botnana.SetTagCB("operation_mode.1.1", 0, IntPtr.Zero, onDriveMode);

            onCoordinatorEnabled = new HandleMessage(OnCoordinatorEnabledCB);
            botnana.SetTagCB("coordinator_enabled", 0, IntPtr.Zero, onCoordinatorEnabled);

            onAxisEnabled = new HandleMessage(OnAxisEnabledCB);
            botnana.SetTagCB("axis_interpolator_enabled.1", 0, IntPtr.Zero, onAxisEnabled);

            onAxisReached = new HandleMessage(OnAxisReachedCB);
            botnana.SetTagCB("axis_interpolator_reached.1", 0, IntPtr.Zero, onAxisReached);

            onAxisFeedback = new HandleMessage(OnAxisFeedbackCB);
            botnana.SetTagCB("feedback_position.1", 0, IntPtr.Zero, onAxisFeedback);

            onAxisDemand = new HandleMessage(OnAxisDemandCB);
            botnana.SetTagCB("axis_demand_position.1", 0, IntPtr.Zero, onAxisDemand);

            onAxisCommand = new HandleMessage(OnAxisCommandCB);
            botnana.SetTagCB("axis_command_position.1", 0, IntPtr.Zero, onAxisCommand);

            onAxisFollowingError = new HandleMessage(OnAxisFollowingErrorCB);
            botnana.SetTagCB("following_error.1", 0, IntPtr.Zero, onAxisFollowingError);

            onUserParameter = new HandleMessage(OnUserParameterCB);
            botnana.SetTagCB("user_parameter", 0, IntPtr.Zero, onUserParameter);

            onMpgSelected = new HandleMessage(OnMpgSelectedCB);
            botnana.SetTagCB("mpg_selected", 0, IntPtr.Zero, onMpgSelected);

            onMpgSfcRate = new HandleMessage(OnMpgSfcRateCB);
            botnana.SetTagCB("mpg_rate", 0, IntPtr.Zero, onMpgSfcRate);

            onSfcCondition = new HandleMessage(OnSfcConditionCB);
            botnana.SetTagCB("condition_ok", 0, IntPtr.Zero, onSfcCondition);

            timer1.Interval    = 50;
            timer1.Enabled     = true;
            timerSlow.Interval = 1000;
            timerSlow.Enabled  = true;
        }
Ejemplo n.º 12
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 + ")";
        }
Ejemplo n.º 13
0
        private void Form1_Load(object sender, EventArgs e)
        {
            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);

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

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

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

            onEcReady = new HandleMessage(OnEcReady);
            bot.SetTagCB(@"ec_ready", 0, IntPtr.Zero, onEcReady);

            onSystemReady = new HandleMessage(OnSystemReady);
            bot.SetTagCB(@"system_ready", 0, IntPtr.Zero, onSystemReady);

            onFeederReady = new HandleMessage(OnFeederReady);
            bot.SetTagCB(@"feeder_ready", 0, IntPtr.Zero, onFeederReady);

            onEncoderPosition = new HandleTagNameMessage(OnEncoderPosition);
            bot.SetTagNameCB(@"real_position", 0, IntPtr.Zero, onEncoderPosition);

            onTargetPosition = new HandleTagNameMessage(OnTargetPosition);
            bot.SetTagNameCB(@"target_position", 0, IntPtr.Zero, onTargetPosition);

            onDriveStatus = new HandleTagNameMessage(OnDriveStatus);
            bot.SetTagNameCB(@"status_word", 0, IntPtr.Zero, onDriveStatus);

            onOperationMode = new HandleTagNameMessage(OnOperationMode);
            bot.SetTagNameCB(@"operation_mode", 0, IntPtr.Zero, onOperationMode);

            onDriveDigitalInputs = new HandleTagNameMessage(OnDriveDigitalInputs);
            bot.SetTagNameCB(@"digital_inputs", 0, IntPtr.Zero, onDriveDigitalInputs);

            onTouchProbe = new HandleTagNameMessage(OnTouchProbe);
            bot.SetTagNameCB(@"touch_probe_function", 0, IntPtr.Zero, onTouchProbe);

            onCylinder = new HandleTagNameMessage(OnCylinder);
            bot.SetTagNameCB(@"dout", 0, IntPtr.Zero, onCylinder);

            onTPLatchPosition1 = new HandleTagNameMessage(OnTPLatchPosition1);
            bot.SetTagNameCB(@"tp_position_value_1", 0, IntPtr.Zero, onTPLatchPosition1);

            onTPLatchPosition2 = new HandleTagNameMessage(OnTPLatchPosition2);
            bot.SetTagNameCB(@"tp_position_value_2", 0, IntPtr.Zero, onTPLatchPosition2);

            onCylinderOnMs = new HandleMessage(OnCylinderOnMs);
            bot.SetTagCB(@"cylinder_on_duration", 0, IntPtr.Zero, onCylinderOnMs);

            onCylinderOffMs = new HandleMessage(OnCylinderOffMs);
            bot.SetTagCB(@"cylinder_off_duration", 0, IntPtr.Zero, onCylinderOffMs);

            onRotationDistance = new HandleMessage(OnRotationDistance);
            bot.SetTagCB(@"feeder_rotation_distance", 0, IntPtr.Zero, onRotationDistance);

            onRotationSpeed = new HandleMessage(OnRotationSpeed);
            bot.SetTagCB(@"feeder_rotation_speed", 0, IntPtr.Zero, onRotationSpeed);

            onSettlingDuration = new HandleMessage(OnSettlingDuration);
            bot.SetTagCB(@"feeder_settling_duration", 0, IntPtr.Zero, onSettlingDuration);

            onRetryCountMax = new HandleMessage(OnRetryCountMax);
            bot.SetTagCB(@"feeder_retry_count_max", 0, IntPtr.Zero, onRetryCountMax);

            onDriveDeviceSlave = new HandleMessage(OnDriveDeviceSlave);
            bot.SetTagCB(@"drive_device_slave", 1, IntPtr.Zero, onDriveDeviceSlave);

            onDriveDeviceChannel = new HandleMessage(OnDriveDeviceChannel);
            bot.SetTagCB(@"drive_device_channel", 1, IntPtr.Zero, onDriveDeviceChannel);

            onCylinderDeviceSlave = new HandleMessage(OnCylinderDeviceSlave);
            bot.SetTagCB(@"cylinder_device_slave", 1, IntPtr.Zero, onCylinderDeviceSlave);

            onCylinderDeviceChannel = new HandleMessage(OnCylinderDeviceChannel);
            bot.SetTagCB(@"cylinder_device_channel", 1, IntPtr.Zero, onCylinderDeviceChannel);

            onFeederRunning = new HandleMessage(OnFeederRunning);
            bot.SetTagCB(@"feeder_running", 0, IntPtr.Zero, onFeederRunning);

            onFeederEMS = new HandleMessage(OnFeederEMS);
            bot.SetTagCB(@"feeder_ems", 0, IntPtr.Zero, onFeederEMS);

            onFeederOperationMs = new HandleMessage(OnFeederOperationMs);
            bot.SetTagCB(@"feeder_operation_ms", 0, IntPtr.Zero, onFeederOperationMs);

            onTPStatus = new HandleTagNameMessage(OnTPStatus);
            bot.SetTagNameCB(@"sdo_0_24761", 0, IntPtr.Zero, onTPStatus);

            onTPDetected1 = new HandleMessage(OnTPDetected1);
            bot.SetTagCB(@"tp_detected_1", 0, IntPtr.Zero, onTPDetected1);

            onTPDetected2 = new HandleMessage(OnTPDetected2);
            bot.SetTagCB(@"tp_detected_2", 0, IntPtr.Zero, onTPDetected2);

            onTPDetectedPosition1 = new HandleMessage(OnTPDetectedPosition1);
            bot.SetTagCB(@"tp_detected_position_1", 0, IntPtr.Zero, onTPDetectedPosition1);

            onTPDetectedPosition2 = new HandleMessage(OnTPDetectedPosition2);
            bot.SetTagCB(@"tp_detected_position_2", 0, IntPtr.Zero, onTPDetectedPosition2);

            timerSlow.Enabled = true;
            timerPoll.Enabled = true;
            timer1s.Enabled   = true;
        }
Ejemplo n.º 14
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;
        }