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);
            }
        }
Esempio n. 2
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();
            }
        }
Esempio n. 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);
        }
Esempio n. 4
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);
            }
        }
        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);
            }
        }
Esempio n. 6
0
 private void button12_Click(object sender, EventArgs e)
 {
     try {
         init();
     } catch (Exception ex) {
         Invokers.SetAppendText(tbLog, true, ex.Message);
     }
 }
Esempio n. 7
0
        private void S_OnResult(string compilerName, string resultTxt)
        {
            if (IsClosing)
            {
                return;
            }

            Invokers.SetAppendText(tbLog, true, $"> {resultTxt}");
        }
Esempio n. 8
0
        private void S_OnStart(string compilerName)
        {
            if (IsClosing)
            {
                return;
            }

            Invokers.SetAppendText(tbLog, true, "Pressed");
        }
        private void _lidarService_OnLog(object sender, string e)
        {
            if (IsClosing)
            {
                return;
            }

            Invokers.SetAppendText(tbLog, true, e);
        }
        private void _lidarParser_OnWarning(object sender, string e)
        {
            if (IsClosing || !_debugging)
            {
                return;
            }

            Invokers.SetAppendText(tbLog, true, $"Parser: {e}");
        }
Esempio n. 11
0
        private void S_OnDone(string compilerName, TimeSpan timeTook)
        {
            if (IsClosing)
            {
                return;
            }

            Invokers.SetAppendText(tbLog, true, $"Done {timeTook}");
        }
Esempio n. 12
0
        private void S_OnError(string compilerName, string errorMessage)
        {
            if (IsClosing)
            {
                return;
            }

            Invokers.SetAppendText(tbLog, true, $"> {errorMessage}");
        }
Esempio n. 13
0
        private void _robotController_OnLog(object sender, string e)
        {
            if (IsClosing)
            {
                return;
            }

            Invokers.SetAppendText(tbLog, true, e);
        }
Esempio n. 14
0
        private void _robotController_OnError(object sender, Exception txt)
        {
            if (IsClosing)
            {
                return;
            }

            Invokers.SetChecked(cbSensorStream, false);

            Invokers.SetAppendText(tbLog, true, txt.ToString());
        }
Esempio n. 15
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();
        }
        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");
        }
        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);
            }
        }
 private void btnConnect_Click(object sender, EventArgs e)
 {
     try {
         if (_lidarService.IsRunning)
         {
             stop();
         }
         else
         {
             start();
         }
     } catch (Exception ex) {
         Invokers.SetAppendText(tbLog, true, ex.Message);
     }
 }
Esempio n. 19
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);
            }
        }
        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);
                }
            }
        }
        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");
        }
Esempio n. 22
0
        private void init()
        {
            if (InvokeRequired)
            {
                Invoke(new Action(() => init()));

                return;
            }

            tbLog.Clear();

            if (_robotController != null)
            {
                _robotController.OnError           -= _robotController_OnError;
                _robotController.OnButtonPressed   -= _robotController_OnButtonPressed;
                _robotController.OnLog             -= _robotController_OnLog;
                _robotController.OnStreamPacketCnt -= _robotController_OnStreamPacketCnt;

                _robotController.Dispose();

                _robotController = null;
            }

            var portType = (Config.ConfigTitles.PortTypeEnum)_cf.STORAGE[Config.ConfigTitles.CONNECTION_TYPE];

            IOCommunicator comm;

            if (portType == Config.ConfigTitles.PortTypeEnum.Software_Serial)
            {
                if (!EZBManager.PrimaryEZB.IsConnected)
                {
                    throw new Exception("Not connected to EZB Index #0");
                }

                var digitalPort = (Digital.DigitalPortEnum)_cf.STORAGE[Config.ConfigTitles.EZB_SERIAL_PORT];
                var baudrate    = (Uart.BAUD_RATE_ENUM)_cf.STORAGE[Config.ConfigTitles.BAUD_RATE_SERIAL];

                tbLog.AppendText(string.Format("Connecting software serial port {0} @ {1}...", digitalPort, baudrate));

                comm = new EZBDigitalIOCommunicator(digitalPort, baudrate);
            }
            else if (portType == Config.ConfigTitles.PortTypeEnum.HW_UART)
            {
                if (!EZBManager.PrimaryEZB.IsConnected)
                {
                    throw new Exception("Not connected to EZB Index #0");
                }

                var uartPort = Convert.ToInt16(_cf.STORAGE[Config.ConfigTitles.EZB_UART_PORT]);
                var baudRate = Convert.ToInt32(_cf.STORAGE[Config.ConfigTitles.BAUD_RATE_UART]);

                tbLog.AppendText(string.Format("Connecting HW UART {0} @ {1}...", uartPort, baudRate));

                comm = new EZBUARTIOCommunicator(uartPort, baudRate);
            }
            else
            {
                var comPort  = _cf.STORAGE[Config.ConfigTitles.PC_COM_PORT].ToString();
                var baudRate = Convert.ToInt32(_cf.STORAGE[Config.ConfigTitles.BAUD_RATE_PC]);

                tbLog.AppendText(string.Format("Connecting {0} @ {1}...", comPort, baudRate));

                comm = new SerialPortIOCommunicator(comPort, baudRate);
            }

            _robotController = new Create(
                comm,
                Convert.ToInt32(_cf.STORAGE[Config.ConfigTitles.SENSOR_POLL_TIME_MS]),
                Convert.ToBoolean(_cf.STORAGE[Config.ConfigTitles.NMS_POSITION_DATA]));

            _robotController.OnError           += _robotController_OnError;
            _robotController.OnButtonPressed   += _robotController_OnButtonPressed;
            _robotController.OnLog             += _robotController_OnLog;
            _robotController.OnStreamPacketCnt += _robotController_OnStreamPacketCnt;

            _robotController.SetMode(Create2OI.Types.OperatingMode.FULL);

            cbSensorStream_CheckedChanged(null, null);

            doMotors();

            Invokers.SetAppendText(tbLog, true, "Connected");
        }
        private void _lidarService_OnLidarDataReady1(object sender, byte[] lidarData)
        {
            if (IsClosing)
            {
                return;
            }

            var scanPoints = _lidarParser.ParseRawSensorPacket(lidarData);

            if (scanPoints.Length != 360)
            {
                if (_debugging)
                {
                    Invokers.SetAppendText(tbLog, true, $"Expecting 360 degrees, received {scanPoints.Length} degrees");
                }

                return;
            }

            ARC.MessagingService.Navigation2DV1.Messenger.UpdateScan(scanPoints);

            List <PointF> points = new List <PointF>();

            var sensorMin = new ARC.MessagingService.Navigation2DV1.ScanPoint(999999, 0, 0);
            var sensorMax = new ARC.MessagingService.Navigation2DV1.ScanPoint(0, 0, 0);

            int[] distanceArray = new int[scanPoints.Length];

            int degreesOffset = Convert.ToInt32(_cf.STORAGE[ConfigTitles.OFFSET_DEGREES]);

            for (int x = 0; x < scanPoints.Length; x++)
            {
                var sensorValue = scanPoints[x];

                sensorValue.Degree = sensorValue.Degree + degreesOffset % 360;

                if (sensorValue.Distance > 0 && sensorValue.Distance < sensorMin.Distance)
                {
                    sensorMin = sensorValue;
                }

                if (sensorValue.Distance > sensorMax.Distance)
                {
                    sensorMax = sensorValue;
                }

                if (sensorValue.Distance > 0)
                {
                    points.Add(new PointF(
                                   (float)((IMAGE_WIDTH / 2) + EZ_B.Functions.DegX2(sensorValue.Degree, sensorValue.Distance / 4)),
                                   (float)((IMAGE_HEIGHT / 2) + EZ_B.Functions.DegY2(sensorValue.Degree, sensorValue.Distance / 4))));
                }

                distanceArray[x] = sensorValue.Distance;
            }

            ARC.Scripting.VariableManager.SetVariable(_cf.STORAGE[ConfigTitles.NEAREST_DISTANCE_VAR].ToString(), sensorMin.Distance);
            ARC.Scripting.VariableManager.SetVariable(_cf.STORAGE[ConfigTitles.NEAREST_DEGREE_VAR].ToString(), sensorMin.Degree);

            ARC.Scripting.VariableManager.SetVariable(_cf.STORAGE[ConfigTitles.FURTHEST_DISTANCE_VAR].ToString(), sensorMax.Distance);
            ARC.Scripting.VariableManager.SetVariable(_cf.STORAGE[ConfigTitles.FURTHEST_DEGREE_VAR].ToString(), sensorMax.Degree);

            // Update image twice a second
            if (_stopWatch.ElapsedMilliseconds > 500)
            {
                _stopWatch.Restart();

                using (Bitmap bmRealtime = new Bitmap(IMAGE_WIDTH, IMAGE_HEIGHT)) {
                    using (Graphics gRealtime = Graphics.FromImage(bmRealtime)) {
                        gRealtime.Clear(Color.Black);

                        Pen p = new Pen(Color.Red, 7);

                        gRealtime.FillPolygon(Brushes.Silver, points.ToArray());
                        gRealtime.DrawLines(p, points.ToArray());

                        List <Point> triangle = new List <Point>();
                        triangle.Add(new Point((IMAGE_WIDTH / 2) - 5, (IMAGE_HEIGHT / 2) + 5));
                        triangle.Add(new Point((IMAGE_WIDTH / 2) + 5, (IMAGE_HEIGHT / 2) + 5));
                        triangle.Add(new Point((IMAGE_WIDTH / 2), (IMAGE_HEIGHT / 2) - 10));

                        gRealtime.FillPolygon(Brushes.Green, triangle.ToArray());
                        gRealtime.DrawPolygon(Pens.Black, triangle.ToArray());
                    }

                    this.Invoke(new Action(() => {
                        using (Graphics gRealTime = Graphics.FromImage(pbRealtime.Image))
                            gRealTime.DrawImage(bmRealtime, 0, 0, pbRealtime.Image.Width, pbRealtime.Image.Height);

                        pbRealtime.Refresh();

                        lblMinDistance.Text = sensorMin.Distance.ToString();
                        lblMinDegree.Text   = sensorMin.Degree.ToString();

                        lblMaxDistance.Text = sensorMax.Distance.ToString();
                        lblMaxDegree.Text   = sensorMax.Degree.ToString();
                    }));
                }
            }
        }
 private void _executor_OnCmdExec(string compilerName, int lineNumber, string execTxt)
 {
     Invokers.SetAppendText(tbLog, true, execTxt);
 }
Esempio n. 25
0
        void doit(SearchTypeEnum searchType)
        {
            if (_isRunning)
            {
                Invokers.SetAppendText(textBox1, true, 100, "Already running!");

                return;
            }

            _isRunning = true;

            try {
                string twitterUsername = Common.GetRegistryEntry(Constants.RegistryKeys.TwitterScreenName, string.Empty);

                if (twitterUsername == string.Empty)
                {
                    Invokers.SetAppendText(textBox1, true, 100, "Twitter Username must not be blank");

                    EZ_Builder.Scripting.VariableManager.SetVariable("$TwitterScreenName", string.Empty);
                    EZ_Builder.Scripting.VariableManager.SetVariable("$TwitterMessage", string.Empty);
                    EZ_Builder.Scripting.VariableManager.SetVariable("$TwitterSuccess", false);

                    return;
                }

                if (!twitterUsername.StartsWith("@"))
                {
                    twitterUsername = "******" + twitterUsername;
                }

                Invokers.SetAppendText(textBox1, true, 100, "Polling {0}", twitterUsername);

                OAuthTokens token = new OAuthTokens {
                    AccessToken       = Common.GetRegistryEntry(Constants.RegistryKeys.TwitterAccessToken, string.Empty),
                    AccessTokenSecret = Common.GetRegistryEntry(Constants.RegistryKeys.TwitterAccessTokenSecret, string.Empty),
                    ConsumerKey       = Constants.TwitterConsumerKey,
                    ConsumerSecret    = Constants.TwitterConsumerSecret
                };

                TwitterResponse <TwitterStatusCollection> timeline;

                if (searchType == SearchTypeEnum.Tweets)
                {
                    timeline = TwitterTimeline.UserTimeline(token, new UserTimelineOptions {
                        Count           = 10,
                        ScreenName      = twitterUsername,
                        IncludeRetweets = false
                    });
                }
                else
                {
                    timeline = TwitterTimeline.Mentions(token, new TimelineOptions()
                    {
                        Count           = 10,
                        IncludeRetweets = false
                    });
                }

                if (timeline.Result != RequestResult.Success)
                {
                    Invokers.SetAppendText(textBox1, true, 100, timeline.ErrorMessage);

                    EZ_Builder.Scripting.VariableManager.SetVariable("$TwitterScreenName", string.Empty);
                    EZ_Builder.Scripting.VariableManager.SetVariable("$TwitterMessage", string.Empty);
                    EZ_Builder.Scripting.VariableManager.SetVariable("$TwitterSuccess", false);

                    return;
                }

                for (int i = 0; i < timeline.ResponseObject.Count; i++)
                {
                    TwitterStatus message = timeline.ResponseObject[i];

                    if (searchType == SearchTypeEnum.Tweets)
                    {
                        if (message.CreatedDate <= _lastTweetDateTime)
                        {
                            EZ_Builder.Scripting.VariableManager.SetVariable("$TwitterScreenName", string.Empty);
                            EZ_Builder.Scripting.VariableManager.SetVariable("$TwitterMessage", string.Empty);
                            EZ_Builder.Scripting.VariableManager.SetVariable("$TwitterSuccess", false);

                            continue;
                        }

                        _lastTweetDateTime = message.CreatedDate;
                    }
                    else
                    {
                        if (message.CreatedDate <= _lastMentionDateTime)
                        {
                            EZ_Builder.Scripting.VariableManager.SetVariable("$TwitterScreenName", string.Empty);
                            EZ_Builder.Scripting.VariableManager.SetVariable("$TwitterMessage", string.Empty);
                            EZ_Builder.Scripting.VariableManager.SetVariable("$TwitterSuccess", false);

                            continue;
                        }

                        _lastMentionDateTime = message.CreatedDate;
                    }

                    // remove the tagged twitter name from the message
                    string messageText = Regex.Replace(message.Text, twitterUsername, string.Empty, RegexOptions.IgnoreCase);

                    // remove double spaces
                    while (messageText.Contains("  "))
                    {
                        messageText = messageText.Replace("  ", " ");
                    }

                    // remove start and ending white spaces
                    messageText = messageText.Trim();

                    Invokers.SetAppendText(textBox1, true, 100, "{0} - {1}", message.User.ScreenName, messageText);

                    EZ_Builder.Scripting.VariableManager.SetVariable("$TwitterScreenName", message.User.ScreenName);
                    EZ_Builder.Scripting.VariableManager.SetVariable("$TwitterMessage", messageText);
                    EZ_Builder.Scripting.VariableManager.SetVariable("$TwitterSuccess", true);

                    return;
                }
            } catch (Exception ex) {
                Invokers.SetAppendText(textBox1, true, 100, "Error: {0}", ex.Message);
            } finally {
                Invokers.SetAppendText(textBox1, true, 100, "Done");

                _isRunning = false;
            }
        }