コード例 #1
0
        //Note to self: currently not working
        public void Main(string address)
        {
            gclib gclib = new gclib();

            try
            {
                //execute any program as dictated by all buttons and given script

                //i plan to change the way we do this abit. i want to establish a connection. check for it
                // then just use this Main function to execute the intention of the comment 2 lines above this

                //calls to gclib should be in a try-catch
                textBox1.AppendText("GVersion: " + gclib.GVersion() + "\n");
                gclib.GOpen(address + " -d"); //Set an appropriate IP address here
                textBox1.AppendText("GInfo: " + gclib.GInfo() + "\n");
                textBox1.AppendText("GCommand: " + gclib.GCommand("MG TIME") + "\n");
            }
            catch (Exception ex)
            {
                textBox1.AppendText("ERROR: " + ex.Message);
            }
            finally
            {
                gclib.GClose(); //Don't forget to close!
            }
        }
コード例 #2
0
        //Runs when form loads
        private void Form1_Load(object sender, EventArgs e)
        {
            gclib             = new gclib();                                                         //constructor can throw, so SHOULD keep it in a Try block
            movementVariables = new MovementVariables();
            movementType      = new MovementType(analyzer, this, gclib /*, ref movementVariables*/); // declaring here for the sole purpose of allowing "general relative movement"

            // UPDATE 30/4/20: Set up persistent variables (used in movementVariables):
            myMmToStepper_unitAxisAB = movementVariables.mmToStepper_unitAxisAB;
            myMmToStepper_unitAxisC  = movementVariables.mmToStepper_unitAxisC;


            PrintOutput(textBox1, "Enter a FULL GOpen() address above and press Enter", PrintStyle.Instruction);
            PrintOutput(textBox1, "NOTE: This demo will attempt to move Axis A", PrintStyle.Instruction);

            //this block here to list out available connections
            //make it easier for user to refer to when typing out address
            PrintOutput(textBox1, "Available connections:");
            string[] addrs = gclib.GAddresses();
            if (addrs.Length == 0)
            {
                PrintOutput(textBox1, "None");
            }
            else
            {
                foreach (string a in addrs)
                {
                    PrintOutput(textBox1, a, PrintStyle.GclibData);
                }
            }
            //disable ability to move before a connection with controller has been established
            DisconnectStripButton.Enabled = false; groupBox1.Enabled = false;
            GeneralGroup.Enabled          = false; configBox.Enabled = false;
            originButton.Enabled          = false; returnOriginButton.Enabled = false;
        }
コード例 #3
0
        private bool InitPowerLand(string address)   //初始化powerland
        {
            gclib gclib = null;

            try
            {
                gclib = new gclib();

                PrintOutput("gclib version: ", PrintStyle.Normal, true);
                PrintOutput(gclib.GVersion(), PrintStyle.GclibData);

                PrintOutput("Opening connection to \"" + address + "\"... ", PrintStyle.Normal, true);
                gclib.GOpen(address);
                PrintOutput("Connected.", PrintStyle.Normal);
                PrintOutput("Setting AZ...", PrintStyle.Normal);
                gclib.GCommand(CommandCreate.AZCommand(""));
                PrintOutput("Complete.", PrintStyle.Normal);


                Commondata.GalilControler = new gclib();
                PrintOutput("Connectting to Controler...", PrintStyle.Normal);
                Commondata.GalilControler.GOpen(Commondata.DmcC640Ip);
                PrintOutput("Connected.Version is " + Commondata.GalilControler.GInfo(), PrintStyle.Normal);

                PrintOutput("Now TP position is " + Commondata.GalilControler.GCommand("TP"), PrintStyle.Normal);


                Commondata.IsInit = true;
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("PowerLand初始化失败!" + ex.Message);
                //MessageBox.Show(e.Message);
                return(false);
            }
        }
コード例 #4
0
        private void TheDemo(string address)
        {
            gclib gclib = null;

            try
            {
                gclib = new gclib(); //constructor can throw, so keep it in a Try block

                PrintOutput("gclib version: ", PrintStyle.Normal, true);
                PrintOutput(gclib.GVersion(), PrintStyle.GclibData);

                //*** Uncomment below for network utilities ***
                //PrintOutput("Controllers requesting IP addresses...");
                //string[] macs = gclib.GIpRequests();
                //if (macs.Length == 0)
                //    PrintOutput("None");
                //else
                //    foreach (string m in macs)
                //        PrintOutput(m);

                //gclib.GAssign("192.168.0.42", "00:50:4c:20:01:23"); //Assign an IP to an unassigned controller

                PrintOutput("Available connections:");
                string[] addrs = gclib.GAddresses();
                if (addrs.Length == 0)
                {
                    PrintOutput("None");
                }
                else
                {
                    foreach (string a in addrs)
                    {
                        PrintOutput(a, PrintStyle.GclibData);
                    }
                }

                PrintOutput("Opening connection to \"" + address + "\"... ", PrintStyle.Normal, true);
                gclib.GOpen(address);
                PrintOutput("Connected.", PrintStyle.Normal);
                PrintOutput(gclib.GInfo(), PrintStyle.GalilData);

                // gclib.GCommand("BN"); //send BN if IP address was assigned above

                PrintOutput("Sending \"MG TIME\"", PrintStyle.Normal);
                PrintOutput(gclib.GCommand("MG TIME", false), PrintStyle.GalilData);

                PrintOutput("Downloading Program... ", PrintStyle.Normal, true);
                gclib.GProgramDownload("i=0\r#A;MG i{N};i=i+1;WT10;JP#A,i<10;EN", "");

                PrintOutput("Uploading Program");
                PrintOutput(gclib.GProgramUpload(), PrintStyle.GalilData);

                PrintOutput("Blocking GMessage call");
                gclib.GCommand("XQ");
                System.Threading.Thread.Sleep(200);
                //wait a bit to queue up some messages
                PrintOutput(gclib.GMessage(), PrintStyle.GalilData);
                //get them all in one blocking read

                PrintOutput("Downloading Program... ", PrintStyle.Normal, true);
                gclib.GProgramDownload("WT 1000; MG TIME; EN", "");
                //prints a messsage after 1 second

                PrintOutput("Uploading Program");
                PrintOutput(gclib.GProgramUpload(), PrintStyle.GalilData);

                PrintOutput("Non-blocking GMessage call", PrintStyle.Normal, true);
                gclib.GCommand("XQ");
                gclib.GTimeout(0);
                //set a zero timeout for a non-blocking read
                string msg = "";
                while ((string.IsNullOrEmpty(msg)))
                {
                    msg = gclib.GMessage();
                    PrintOutput(".", PrintStyle.Normal, true);
                    System.Threading.Thread.Sleep(20);
                    //do something useful here...
                }
                PrintOutput("Message: ", PrintStyle.Normal, true);
                PrintOutput(msg.Trim(), PrintStyle.GalilData);
                gclib.GTimeout(-1);
                //put the timeout back
                //NOTE: Both GRecord and GInterrupt also have non-blocking mode with 0 timeout.

                PrintOutput("Downloading Program... ", PrintStyle.Normal, true);
                gclib.GProgramDownload("WT 1000; UI 8; EN", "");
                //fires an interrupt after 1 second

                PrintOutput("Uploading Program");
                PrintOutput(gclib.GProgramUpload(), PrintStyle.GalilData);

                PrintOutput("Non-blocking GInterrupt call", PrintStyle.Normal, true);
                gclib.GCommand("XQ");
                gclib.GTimeout(0);
                //set a zero timeout for a non-blocking read
                byte b = 0;
                while ((b == 0))
                {
                    b = gclib.GInterrupt();
                    PrintOutput(".", PrintStyle.Normal, true);
                    System.Threading.Thread.Sleep(20);
                    //do something useful here...
                }
                PrintOutput("Byte: ", PrintStyle.Normal, true);
                PrintOutput(b.ToString("X02"), PrintStyle.GalilData);
                gclib.GTimeout(-1);
                //put the timeout back

                PrintOutput("Getting some synchronous data records");
                byte[] DataRecord = null;
                for (int i = 0; i <= 10; i++)
                {
                    DataRecord = gclib.GRecord(false);
                    PrintOutput(BitConverter.ToUInt16(DataRecord, 4).ToString() + " ", PrintStyle.GalilData, true);
                    //byte 4 and 5 are typically TIME counter
                    //need help accessing the data record? Contact [email protected]
                    System.Threading.Thread.Sleep(10);
                }
                PrintOutput("");

                PrintOutput("Getting some asynchronous data records");
                gclib.GRecordRate(10);
                //set up data records every 10 ms
                for (int i = 0; i <= 10; i++)
                {
                    DataRecord = gclib.GRecord(true);
                    PrintOutput(BitConverter.ToUInt16(DataRecord, 4).ToString() + " ", PrintStyle.GalilData, true);
                    //byte 4 and 5 are typically TIME counter
                    //no need to delay, asynchronous mode is dispatched by the Galil's RTOS.
                }
                gclib.GRecordRate(0);
                //turn off data records
                PrintOutput("");

                PrintOutput("Downloading an array... ", PrintStyle.Normal, true);
                List <double> array = new List <double>();
                for (double i = 0; i <= 9; i++)
                {
                    array.Add(i * 2);
                }
                gclib.GCommand("DA *[];DM array[10]");
                //arrays must be dimensioned prior to download
                gclib.GArrayDownload("array", ref array);

                PrintOutput("Ok. Uploading array");
                array = gclib.GArrayUpload("array");
                foreach (double d in array)
                {
                    PrintOutput(d.ToString("F4") + " ", PrintStyle.GalilData, true);
                }
                PrintOutput("");

                PrintOutput("Performing a write... ", PrintStyle.Normal, true);
                gclib.GWrite("QR\r");
                //QR returns the binary data record
                PrintOutput("Ok. Reading binary data... ", PrintStyle.Normal, true);
                byte[] data = gclib.GRead();
                PrintOutput("Ok. Read " + data.Length + " bytes.");

                PrintOutput("Preparing A axis. This could cause errors if the axis is not initialized...", PrintStyle.Normal, true);
                gclib.GCommand("AB;MO;SHA");
                //compound commands are possible though typically not recommended
                PrintOutput("Ok");
                gclib.GCommand("PRA=5000");
                gclib.GCommand("SPA=5000");
                PrintOutput("Profiling a move on axis A... ", PrintStyle.Normal, true);
                gclib.GCommand("BGA");
                PrintOutput("Waiting for motion to complete... ", PrintStyle.Normal, true);
                gclib.GMotionComplete("A");
                PrintOutput("done");
                PrintOutput("Going back... ", PrintStyle.Normal, true);
                gclib.GCommand("PRA=-5000");
                gclib.GCommand("BGA");
                gclib.GMotionComplete("A");
                PrintOutput("done");
            }
            catch (Exception ex)
            {
                PrintOutput("Error: " + ex.Message, PrintStyle.Err);
            }
            finally
            {
                if (gclib != null)
                {
                    gclib.GClose(); //don't forget to close the connection
                }
            }
        }
コード例 #5
0
 public Movement_util(Form1 form, gclib gclib)
 {
     this.form  = form;
     this.gclib = gclib;
 }