コード例 #1
0
        private void initUART()
        {
            if (Convert.ToBoolean(_cf.STORAGE[ConfigTitles.USE_HARDWARE_UART]))
            {
                if (EZBManager.EZBs[0].IsConnected)
                {
                    UInt32 baud     = 115200;
                    int    uartPort = Convert.ToInt16(_cf.STORAGE[ConfigTitles.HARDWARE_PORT]);

                    Invokers.SetAppendText(tbLog, true, "UART {0} @ {1}bps",
                                           uartPort,
                                           baud);

                    EZBManager.EZBs[0].Uart.UARTExpansionInit(uartPort, baud);
                }
                else
                {
                    Invokers.SetAppendText(tbLog, true, "Not connected to ez-b");
                }
            }

            if (Convert.ToBoolean(_cf.STORAGE[ConfigTitles.USE_COM_PORT]))
            {
                if (_serialPort.IsOpen)
                {
                    _serialPort.Close();
                }

                _serialPort.BaudRate = 115200;
                _serialPort.PortName = _cf.STORAGE[ConfigTitles.COM_PORT].ToString();

                _serialPort.Open();
            }
        }
コード例 #2
0
        public override void SendCommand(string windowCommand, params string[] values)
        {
            var cmd = GetRoombaCommand(windowCommand);

            if (cmd == RoombaCmdEnum.Init)
            {
                init();
            }
            else if (cmd == RoombaCmdEnum.DisableSensorStream)
            {
                Invokers.SetChecked(cbSensorStream, false);

                cbSensorStream_CheckedChanged(null, null);
            }
            else if (cmd == RoombaCmdEnum.EnableSensorStream)
            {
                Invokers.SetChecked(cbSensorStream, true);

                cbSensorStream_CheckedChanged(null, null);
            }
            else if (cmd == RoombaCmdEnum.PowerOff)
            {
                _robotController.SetMode(Create2OI.Types.OperatingMode.OFF);
            }
            else if (cmd == RoombaCmdEnum.SeekDockingStation)
            {
                _robotController.Execute(Create2OI.Types.OpCode.FORCE_SEEKING_DOCK);
            }
            else if (cmd == RoombaCmdEnum.Clean)
            {
                _robotController.Execute(Create2OI.Types.OpCode.CLEAN);
            }
            else if (cmd == RoombaCmdEnum.MaxClean)
            {
                _robotController.Execute(Create2OI.Types.OpCode.MAX_CLEAN);
            }
            else if (cmd == RoombaCmdEnum.SpotClean)
            {
                _robotController.Execute(Create2OI.Types.OpCode.SPOT);
            }
            else
            {
                base.SendCommand(windowCommand, values);
            }

            //else if (cmd == RoombaCmdEnum.DisableAllBrushes)
            //  _roomba.DisableAllBrushes();
            //else if (cmd == RoombaCmdEnum.MainBrushOff)
            //  _roomba.SetMainBrush(false);
            //else if (cmd == RoombaCmdEnum.MainBrushOn)
            //  _roomba.SetMainBrush(true);
            //else if (cmd == RoombaCmdEnum.SideBrushOff)
            //  _roomba.SetSideBrush(false);
            //else if (cmd == RoombaCmdEnum.SideBrushOn)
            //  _roomba.SetSideBrush(true);
            //else if (cmd == RoombaCmdEnum.VacuumOff)
            //  _roomba.SetVacuum(false);
            //else if (cmd == RoombaCmdEnum.VacuumOn)
            //  _roomba.SetVacuum(true);
        }
コード例 #3
0
        public override void SetConfiguration(PluginV1 cf)
        {
            if (!ARC.Scripting.ScriptManager.DoesExecutorExist(Text))
            {
                var s = ARC.Scripting.ScriptManager.GetExecutor(Text);
                s.OnDone   += S_OnDone;
                s.OnError  += S_OnError;
                s.OnResult += S_OnResult;
                s.OnStart  += S_OnStart;
            }

            cf.SCRIPTS.AddIfNotExist(Config.ConfigTitles.SCRIPT_BUTTON_PRESSED, new ARC.Config.Sub.Reusable.ScriptDefinition());

            cf.STORAGE.AddIfNotExist(Config.ConfigTitles.BAUD_RATE_SERIAL, EZ_B.Uart.BAUD_RATE_ENUM.Baud_115200);
            cf.STORAGE.AddIfNotExist(Config.ConfigTitles.BAUD_RATE_UART, 115200);
            cf.STORAGE.AddIfNotExist(Config.ConfigTitles.BAUD_RATE_PC, 115200);
            cf.STORAGE.AddIfNotExist(Config.ConfigTitles.EZB_SERIAL_PORT, EZ_B.Digital.DigitalPortEnum.D0);
            cf.STORAGE.AddIfNotExist(Config.ConfigTitles.EZB_UART_PORT, 0);
            cf.STORAGE.AddIfNotExist(Config.ConfigTitles.PC_COM_PORT, string.Empty);
            cf.STORAGE.AddIfNotExist(Config.ConfigTitles.CONNECTION_TYPE, Config.ConfigTitles.PortTypeEnum.HW_UART);
            cf.STORAGE.AddIfNotExist(Config.ConfigTitles.SENSOR_POLL_TIME_MS, 500);
            cf.STORAGE.AddIfNotExist(Config.ConfigTitles.NMS_POSITION_DATA, true);

            try {
                init();
            } catch (Exception ex) {
                Invokers.SetAppendText(tbLog, true, ex.Message);
            }

            base.SetConfiguration(cf);
        }
コード例 #4
0
        private void Servo_OnServoGetPosition(Servo.ServoPortEnum servoPort, EZ_B.Classes.GetServoValueResponse getServoResponse)
        {
            if (getServoResponse.Success)
            {
                return;
            }

            if (!_customConfig.VirtualPorts.Contains(servoPort))
            {
                getServoResponse.ErrorStr = "No matching lewansoul servo specified";
                getServoResponse.Success  = false;

                return;
            }

            Invokers.SetAppendText(tbLog, true, "Reading position from {0}", servoPort);

            if (Convert.ToBoolean(_cf.STORAGE[ConfigTitles.USE_COM_PORT]))
            {
                getServoPositionComSerial(servoPort, getServoResponse);
            }

            if (!getServoResponse.Success && Convert.ToBoolean(_cf.STORAGE[ConfigTitles.USE_HARDWARE_UART]))
            {
                getServoPositionEZBUART(servoPort, getServoResponse);
            }
        }
コード例 #5
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            detach();

            string trainedObjectDataFile = EZ_Builder.Common.CombinePath(
                EZ_Builder.Constants.PLUGINS_FOLDER,
                _cf._pluginGUID,
                "Trained Object Data.xml");

            if (!File.Exists(trainedObjectDataFile))
            {
                MessageBox.Show("Unable to find the trained object data file required for this plugin. Closing...");

                Close();

                return;
            }

            try {
                using (FileStream fs = new FileStream(trainedObjectDataFile, FileMode.Open, FileAccess.Read)) {
                    System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(EZ_B.AVM.TrainedObjectsContainer));

                    _trainedObjects = (EZ_B.AVM.TrainedObjectsContainer)xs.Deserialize(fs);

                    AssociativeMemory.ReadPackedData(_trainedObjects.Data);
                }
            } catch (Exception ex) {
                Invokers.SetAppendText(tbLog, true, "Error loading trained object data: {0}", ex);
            }
        }
コード例 #6
0
        private void PrimaryEZB_OnConnectionChange2(EZB sender, bool isConnected)
        {
            var portType = (Config.ConfigTitles.PortTypeEnum)_cf.STORAGE[Config.ConfigTitles.CONNECTION_TYPE];

            if (portType == ConfigTitles.PortTypeEnum.PC_COM)
            {
                return;
            }

            try {
                if (isConnected)
                {
                    init();
                }
                else
                {
                    if (_robotController != null)
                    {
                        _robotController.Dispose();

                        _robotController = null;
                    }

                    Invokers.SetAppendText(tbLog, true, "Disconnected");
                }
            } catch (Exception ex) {
                Invokers.SetAppendText(tbLog, true, "Connection change: {0}", ex);
            }
        }
コード例 #7
0
 private void button12_Click(object sender, EventArgs e)
 {
     try {
         init();
     } catch (Exception ex) {
         Invokers.SetAppendText(tbLog, true, ex.Message);
     }
 }
コード例 #8
0
        private void _robotController_OnStreamPacketCnt(object sender, int e)
        {
            if (IsClosing)
            {
                return;
            }

            Invokers.SetText(lblStreamCnt, $"{e:###,###}");
        }
コード例 #9
0
        private void S_OnDone(string compilerName, TimeSpan timeTook)
        {
            if (IsClosing)
            {
                return;
            }

            Invokers.SetAppendText(tbLog, true, $"Done {timeTook}");
        }
コード例 #10
0
        private void S_OnError(string compilerName, string errorMessage)
        {
            if (IsClosing)
            {
                return;
            }

            Invokers.SetAppendText(tbLog, true, $"> {errorMessage}");
        }
コード例 #11
0
        private void S_OnStart(string compilerName)
        {
            if (IsClosing)
            {
                return;
            }

            Invokers.SetAppendText(tbLog, true, "Pressed");
        }
コード例 #12
0
        private void _lidarService_OnLog(object sender, string e)
        {
            if (IsClosing)
            {
                return;
            }

            Invokers.SetAppendText(tbLog, true, e);
        }
コード例 #13
0
        private void _lidarParser_OnWarning(object sender, string e)
        {
            if (IsClosing || !_debugging)
            {
                return;
            }

            Invokers.SetAppendText(tbLog, true, $"Parser: {e}");
        }
コード例 #14
0
        private void _robotController_OnLog(object sender, string e)
        {
            if (IsClosing)
            {
                return;
            }

            Invokers.SetAppendText(tbLog, true, e);
        }
コード例 #15
0
        private void S_OnResult(string compilerName, string resultTxt)
        {
            if (IsClosing)
            {
                return;
            }

            Invokers.SetAppendText(tbLog, true, $"> {resultTxt}");
        }
コード例 #16
0
        private void MovementManager_OnSpeedChanged(int speedLeft, int speedRight)
        {
            if (IsClosing)
            {
                return;
            }

            Invokers.SetValue(tbSpeedLeft, speedLeft);
            Invokers.SetValue(tbSpeedRight, speedRight);
        }
コード例 #17
0
        private void _robotController_OnError(object sender, Exception txt)
        {
            if (IsClosing)
            {
                return;
            }

            Invokers.SetChecked(cbSensorStream, false);

            Invokers.SetAppendText(tbLog, true, txt.ToString());
        }
コード例 #18
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text.Trim();

            if (textBox1.Text == string.Empty)
            {
                return;
            }

            AIMLbot.Request req = new AIMLbot.Request(textBox1.Text, _user, _bot);

            tbLog.AppendText("You> " + textBox1.Text);
            tbLog.AppendText(Environment.NewLine);

            AIMLbot.Result r = _bot.Chat(req);

            string unfilteredResp = r.Output;

            string resp = string.Empty;

            string[] cmds = Common.GetTextBetween(unfilteredResp, out resp, '[', ']');

            resp = resp.Replace("\r", string.Empty);
            resp = resp.Replace("\n", string.Empty);
            resp = EZ_Builder.Scripting.VariableManager.SubsituteWithValues(resp);
            resp = resp.Replace("\"", "");
            resp = Regex.Replace(resp, @"\s+", " ");

            tbLog.AppendText("Bot> " + resp);
            tbLog.AppendText(Environment.NewLine);

            EZ_Builder.Scripting.VariableManager.SetVariable(
                _cf.STORAGE[ConfigTitles.RESPONSE_VARIABLE].ToString(),
                resp);

            if (_cf.STORAGE[ConfigTitles.RESPONSE_SCRIPT].ToString() != string.Empty)
            {
                EZ_Builder.Scripting.EZScriptManager.GetExecutor(_EXECUTOR_NAME).StartScriptASync(_cf.STORAGE[ConfigTitles.RESPONSE_SCRIPT].ToString());
            }

            foreach (string cmd in cmds)
            {
                Invokers.SetAppendText(tbLog, true, 50, "Exec: {0}", cmd);

                string response = EZ_Builder.Scripting.EZScriptManager.GetExecutor(_EXECUTOR_NAME + "_embedded").ExecuteScriptSingleLine(cmd);

                if (response != string.Empty)
                {
                    Invokers.SetAppendText(tbLog, true, 50, response);
                }
            }

            textBox1.Clear();
        }
コード例 #19
0
        internal override void Configure(long codeRegistration, long metadataRegistration)
        {
            base.Configure(codeRegistration, metadataRegistration);

            if (Image is MachOReader)
            {
                // fix method pointer in mach-o (always +1, don't know why)
                MethodPointers  = MethodPointers.Select(ptr => ptr - 1).ToArray();
                ManagedToNative = ManagedToNative.Select(ptr => ptr - 1).ToArray();
                Invokers        = Invokers.Select(ptr => ptr - 1).ToArray();
            }
        }
コード例 #20
0
        public FormMain()
        {
            InitializeComponent();

            // Bind to the events for moving a servo and changing connection state
            EZBManager.EZBs[0].OnConnectionChange       += FormMain_OnConnectionChange;
            EZBManager.EZBs[0].Servo.OnServoMove        += Servo_OnServoMove;
            EZBManager.EZBs[0].Servo.OnServoGetPosition += Servo_OnServoGetPosition;
            EZBManager.EZBs[0].Servo.OnServoRelease     += Servo_OnServoRelease;

            Invokers.SetAppendText(tbLog, true, "Connected Events");
        }
コード例 #21
0
        void Camera_OnNewFrame()
        {
            if (_isClosing)
            {
                return;
            }

            try {
                Bitmap image = _cameraControl.Camera.GetCurrentBitmap;

                var found = GetDetectedImage(image);

                if (found == UCProgramItem.ProgramItemEnum.NA)
                {
                }
                else if (_lastDetectedItem != found && found == UCProgramItem.ProgramItemEnum.Start)
                {
                    say("Running your program");

                    _currentRunningIndex = 0;

                    flowLayoutPanel1.Invoke(new Action(() => {
                        var item = (UCProgramItem)flowLayoutPanel1.Controls[_currentRunningIndex];

                        item.BackColor = Color.Green;

                        _executor.StartScriptASync(item.GetCode());
                    }));
                }
                else if (_lastDetectedItem != found)
                {
                    flowLayoutPanel1.Invoke(new Action(() => Invokers.AddControl(flowLayoutPanel1, new UCProgramItem(found))));

                    say(string.Format("Added {0} command", found));
                }

                _lastDetectedItem = found;

                // Rather than creating a new bitmap for the picturebox, we simply overwrite the bitmap data with the bmTmp data
                // This way, when the bmpTmp is destroyed from the using, the picturebox has the brand new image data
                pictureBox1.Invoke(new Action(() => EZ_B.Camera.CopyBitmapMemory(image, (Bitmap)pictureBox1.Image)));

                Invokers.SetRefresh(pictureBox1);
            } catch (Exception ex) {
                Invokers.SetAppendText(tbLog, true, ex.ToString());

                Invokers.SetEnabled(btnAttachCamera, true);
            }
        }
コード例 #22
0
        private bool disposedValue = false; // 要检测冗余调用

        /// <summary>
        /// 释放资源。
        /// </summary>
        /// <param name="disposing">全部释放。</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                Routers.Clear();
                Invokers.Clear();

                if (disposing)
                {
                    GC.SuppressFinalize(this);
                }

                disposedValue = true;
            }
        }
コード例 #23
0
 private void btnConnect_Click(object sender, EventArgs e)
 {
     try {
         if (_lidarService.IsRunning)
         {
             stop();
         }
         else
         {
             start();
         }
     } catch (Exception ex) {
         Invokers.SetAppendText(tbLog, true, ex.Message);
     }
 }
コード例 #24
0
        private void _lidarService_OnStart()
        {
            if (IsClosing)
            {
                return;
            }

            Invokers.SetText(btnConnect, "Stop");
            Invokers.SetBackColor(btnConnect, Color.Red);
            Invokers.SetForeColor(btnConnect, Color.White);
            Invokers.SetEnabled(groupBox3, false);

            ARC.Scripting.VariableManager.SetVariable(_cf.STORAGE[ConfigTitles.IS_LIDAR_RUNNING_VARIABLE].ToString(), true);

            _stopWatch.Restart();
        }
コード例 #25
0
ファイル: java.lang.invoke.cs プロジェクト: moayyaed/ikvm
    internal static T GetDelegateForInvokeExact <T>(MethodHandle mh)
        where T : class
    {
        MethodType type = mh.type();

        if (mh._invokeExactDelegate == null)
        {
            if (type._invokeExactDynamicMethod == null)
            {
                type._invokeExactDynamicMethod = DynamicMethodBuilder.CreateInvokeExact(type);
            }
            mh._invokeExactDelegate = type._invokeExactDynamicMethod.CreateDelegate(GetDelegateTypeForInvokeExact(type), mh);
            T del = mh._invokeExactDelegate as T;
            if (del != null)
            {
                return(del);
            }
        }
        throw Invokers.newWrongMethodTypeException(GetDelegateMethodType(typeof(T)), type);
    }
コード例 #26
0
        void detach()
        {
            if (_cameraControl != null)
            {
                if (!_isClosing)
                {
                    EZ_Builder.EZBManager.Log("Detaching from {0}", _cameraControl.Text);
                }

                _cameraControl.Camera.OnNewFrame -= Camera_OnNewFrame;

                _cameraControl = null;
            }

            if (!_isClosing)
            {
                Invokers.SetEnabled(btnAttachCamera, true);
                Invokers.SetText(btnAttachCamera, "Attach Camera");
            }
        }
コード例 #27
0
        private void cbSensorStream_CheckedChanged(object sender, EventArgs e)
        {
            try {
                if (_robotController == null || IsClosing)
                {
                    return;
                }

                if (cbSensorStream.Checked)
                {
                    _robotController.StartStreaming();
                }
                else
                {
                    _robotController.StopStreaming();
                }
            } catch (Exception ex) {
                Invokers.SetAppendText(tbLog, true, ex.Message);
            }
        }
コード例 #28
0
        private void initUART()
        {
            if (Convert.ToBoolean(_cf.STORAGE[ConfigTitles.USE_HARDWARE_UART]) && EZBManager.PrimaryEZB.Firmware.IsCapabilitySupported(EZ_B.Firmware.XMLFirmwareSimulator.CAP_HARDWARE_UART_TX_RX_WITH_DMA_BUFFER))
            {
                if (EZBManager.EZBs[0].IsConnected)
                {
                    UInt32 baud     = 1000000;
                    int    uartPort = Convert.ToInt16(_cf.STORAGE[ConfigTitles.HARDWARE_PORT]);

                    Invokers.SetAppendText(tbLog, true, "UART {0} @ {1}bps",
                                           uartPort,
                                           baud);

                    EZBManager.EZBs[0].Uart.UARTExpansionInit(uartPort, baud);
                }
            }

            if (Convert.ToBoolean(_cf.STORAGE[ConfigTitles.USE_COM_PORT]))
            {
                if (_serialPort.IsOpen)
                {
                    _serialPort.Close();
                }

                _serialPort.BaudRate = 1000000;
                _serialPort.PortName = _cf.STORAGE[ConfigTitles.COM_PORT].ToString();

                Invokers.SetAppendText(tbLog, true, "{0} @ {1}bps",
                                       _serialPort.PortName,
                                       _serialPort.BaudRate);

                try {
                    _serialPort.Open();
                } catch (Exception ex) {
                    Invokers.SetAppendText(tbLog, true, ex.Message);
                }
            }
        }
コード例 #29
0
        void attach()
        {
            detach();

            Control[] cameras = EZ_Builder.EZBManager.FormMain.GetControlByType(typeof(EZ_Builder.UCForms.FormCameraDevice));

            if (cameras.Length == 0)
            {
                MessageBox.Show("There are no camera controls in this project.");

                return;
            }

            foreach (EZ_Builder.UCForms.FormCameraDevice camera in cameras)
            {
                if (camera.Camera.IsActive)
                {
                    this.Invoke(new Action(() => {
                        pictureBox1.Image = new Bitmap(camera.Camera.CaptureWidth, camera.Camera.CaptureHeight, EZ_B.Camera.PixelFormat);

                        _cameraControl = camera;

                        Invokers.SetAppendText(tbLog, true, "Attached to: {0}", _cameraControl.Text);

                        btnAttachCamera.Enabled = true;

                        btnAttachCamera.Text = "Detach Camera";

                        _cameraControl.Camera.OnNewFrame += Camera_OnNewFrame;
                    }));

                    return;
                }
            }

            MessageBox.Show("There are no active cameras in this project. This control will connect to the first active camera that it detects in the project");
        }
コード例 #30
0
 /// <summary>
 /// 添加指定目标类型工厂(同种目标类型第一次配置生效)。
 /// </summary>
 /// <typeparam name="TResult">目标类型。</typeparam>
 /// <param name="invoke">将任意类型转为目标类型的工厂。</param>
 /// <returns>返回真代表注册成功,返回假代表注册失败(目标类型已被指定其他调用器)。</returns>
 public bool Use <TResult>(Func <T, Type, Func <object, TResult> > invoke) => Invokers.TryAdd(typeof(TResult), new Invoker <TResult>(invoke));