Exemplo n.º 1
0
        int timeSelectedIndex = 1; //min

        #endregion Fields

        #region Constructors

        public PromptScriptEdit(SmartButton SmartIn)
        {
            InitializeComponent();
            this.SmartButtonToEdit = SmartIn;
            this.ScriptToEdit = SmartIn.storedScript;
            populateCurrentAttributes();
            this.Show();
        }
Exemplo n.º 2
0
 public void addScript(ScriptRunner scriptToAdd)
 {
     this.storedScript = scriptToAdd;
 }
Exemplo n.º 3
0
 private bool loadScript(Boolean fromFile)
 {
     try
     {
         serialScript = new ScriptRunner(toggleTime);
         serialScript.clearCurrentScript();
         if (fromFile)
         {
             if (serialScript.loadScriptFromFile())
             {
                 return true;
             }
         }
     }
     catch (Exception)
     {
         return false;
     }
     return false;
 }
Exemplo n.º 4
0
        private void CleanClose(object sender, EventArgs e)
        {
            //close the serial port on close
            try
            {
                this.currentConnection.closeSerialPort();
            }
            catch { }

            //close any results window
            try
            {
                ResultWindow.Close();
                ResultWindow.Dispose();
                ResultWindow = null;
            }
            catch { }

            //close any scripts that are running
            try
            {
                this.serialScript = null;
            }
            catch { }

            this.AllWindowsClosed = true;
        }
Exemplo n.º 5
0
        private void scriptHandleFunction(ArrayList currentItem, ScriptRunner RunningScript)
        {
            //ArrayList format:
            //"FUNCTION"
            //"**functionName"
            //{"arguments1"}
            //{"arguments2"}
            object[] currentItemToRun = currentItem.ToArray();
            int length = currentItemToRun.Length;
            string functionName = "";
            object[] arguments = null;
            //populate the funciton name and arguments, if any
            if (length >= 2)  //FUNCTION , **functionname
            {
                functionName = (string)currentItemToRun[1];
            }
            if (length >= 3) //FUNCTION , **functionname, arguments
            {
                arguments = new Object[length - 2];
                Array.Copy(currentItemToRun, 2, arguments, 0, length - 2);
            }
            //case statement to handle functions
            switch (functionName.ToLower())
            {
                case "ymodem":
                    if (arguments != null)
                    {
                        initTransfer();
                        YModemSendFile((string)arguments[0]);
                    }
                    break;

                case "delay":
                    if (arguments != null)
                    {
                        int newDelay = 1000;
                        if (int.TryParse((string)arguments[0], out newDelay))
                        {
                            RunningScript.changeDelay(newDelay);
                        }
                    }
                    break;

                case "sleep":
                    if (arguments != null)
                    {
                        int newSleep = 1000;
                        if (int.TryParse((string)arguments[0], out newSleep))
                        {
                            safeSleep(newSleep);
                        }
                    }
                    break;

                case "serialbreak":
                    currentConnection.serialBreak();
                    break;

                case "sbreak":
                    if (arguments != null)
                    {
                        bool serialtermval = false;

                        try
                        {
                            serialtermval = Convert.ToBoolean((string)arguments[0]);
                        }
                        catch
                        {
                        }
                        setSBREAK(serialtermval);
                    }
                    break;

                case "rts":
                    if (arguments != null)
                    {
                        bool serialtermval = false;

                        try
                        {
                            serialtermval = Convert.ToBoolean((string)arguments[0]);
                        }
                        catch
                        {
                        }
                        setRTS(serialtermval);
                    }
                    break;

                case "dtr":
                    if (arguments != null)
                    {
                        setDTRandParseInput((string)arguments[0]);
                    }
                    break;

                case "settings":
                    //usage:
                    //function name {tab} baud {tab} ASCIIorHEX {tab} DTR {tab}  PortReadTime
                    //**settings   9600   ASCII   True  30
                    ScriptSetCometSettings(arguments);
                    break;

                case "response_str":
                    //usage:
                    //function name {tab} timeout ms {tab} command {tab} expected response
                    //**response_str   2000 qdver   rqdver
                    ScriptCheckForResponse(arguments, "string");
                    break;

                case "response_int_between":
                    //usage:
                    //function name {tab} timeout ms {tab} command {tab} parsetext {tab} low int {tab} high int
                    //**response_int_between {tab} 2000 {tab} QDAIN,1 {tab} RQDAIN,1, Ain[1] (VBAT) = {tab}7000 {tab} 8000
                    ScriptCheckForResponse(arguments, "between");
                    break;

                case "response_log":
                    //usage:
                    //function name {tab} timeout ms {tab} command {tab} expected response / parseout string
                    //**response_log   500 qdain,1   RQDAIN,1, Ain[1] (VBAT) =
                    ScriptLogResponse(arguments, "time");
                    break;

                default:
                    break;
            }
        }
Exemplo n.º 6
0
        private void runScript(ScriptRunner scriptToRun)
        {
            //single threaded at this point....
            try
            {
                if (scriptToRun != null)
                {
                    //tell the script that it is going to run
                    scriptToRun.stop = false;
                    SetProgress(true, false);
                    var commandArray = scriptToRun.currentScript.ToArray();
                    ArrayList currentItem = new ArrayList();
                    string typeOfCommand = "";

                    //looping - must be initialized before the script runs
                    int loopIteration = 0;
                    int loopdelay = scriptToRun.getLoopTime();
                    int loopcount = scriptToRun.getLoopCount();

                    for (loopIteration = 0; loopIteration < loopcount; loopIteration++)
                    {
                        //check to see if the script to stop
                        if (scriptToRun.stop) break;

                        //add on the loop delay AFTER the first time the loop is run
                        if (loopIteration > 0) safeSleep(loopdelay);
                        //The Script
                        for (int current = 0; current < commandArray.Length; current++)
                        {
                            transferProgressChanged((int)(100 * ((float)current / (float)commandArray.Length)));
                            if (!stopThread)
                            {
                                //get each instruction
                                //if it is a serial instruction, just send over active serial port
                                currentItem = (ArrayList)commandArray[current];
                                typeOfCommand = (string)currentItem[0];

                                switch (typeOfCommand)
                                {
                                    case "SERIAL":
                                        sendDataToSerialConnectionBasic((string)currentItem[1]);
                                        //wait
                                        safeSleep(scriptToRun.getDelay());
                                        break;

                                    case "FUNCTION":
                                        scriptHandleFunction(currentItem, scriptToRun);
                                        //wait
                                        safeSleep(scriptToRun.getDelay());
                                        break;

                                    default:
                                        break;
                                }
                            }
                        }
                    }

                }
            }
            catch (Exception)
            {
                Console.WriteLine("Error Running Script");
            }
            SetProgress(false, false);
        }