Beispiel #1
0
        private Aid waitingAid; //aid waiting to be lasered

        #endregion Fields

        #region Constructors

        private LaserMarker()
        {
            this.laserHardware = null;
            this.state = LaserMarkerState.WaitingForWork;
            //handle AidsQueueUpdated event
            AidQueue aidQueue = AidQueue.Instance;
            aidQueue.AidAdded += new EventHandler(AidsQueueUpdated);
            this.waitingAid = null;
        }
        public LaserSelectDialog(ILaserHardware[] hardware)
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            //InitializeComponent() should do this but doesn't
            this.buttonSelect.DialogResult = System.Windows.Forms.DialogResult.OK;

            this.laserHardware = hardware;
            this.selectedHardware = null;
            this.SelectedHead = 0;

            this.PopulateList();
        }
Beispiel #3
0
 /// <summary>
 /// Set up the laser
 /// Event only handled once
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void MainFormActivated(object sender, System.EventArgs e)
 {
     //don't need to handle this event more than once
     this.Activated -= new System.EventHandler(this.MainFormActivated);
     //Select laser
     ILaserHardware synrad = null;
     try
     {
         synrad = new LaserSynrad(this);
     }
     catch (System.Runtime.InteropServices.COMException ex)
     {
         //synrad com control not availible
         ex.ToString();
         MessageBox.Show("Synrad com control failed to load." , "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     ILaserHardware[] hardware;
     if (synrad == null)
     {
         //synrad com control not availible, only use sim
         hardware = new ILaserHardware[1];
         hardware[0] = new LaserSim(this);
     }
     else
     {
         //synrad com control availible, load both synrad and sim
         hardware = new ILaserHardware[2];
         hardware[0] = synrad;
         hardware[1] = new LaserSim(this);
     }
     //show laser selection dialog
     LaserSelectDialog lsd = new LaserSelectDialog(hardware);
     if (lsd.ShowDialog() != DialogResult.OK)
     {
         Application.Exit();
         return;
     }
     //connect selected head
     ILaserHardware laserHardware = lsd.Hardware;
     if (laserHardware == null)
     {
         MessageBox.Show("No laser selected.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
         Application.Exit();
         return;
     }
     //retry connection until it succeeds or user click ignore or abort
     DialogResult dialogResult = DialogResult.Retry;
     HeadConnectResult headConnectResult = laserHardware.ConnectToHead(lsd.HeadIndex);
     while (headConnectResult != HeadConnectResult.AlreadyConnected && headConnectResult != HeadConnectResult.Ok
            && dialogResult == DialogResult.Retry)
     {
         string msg = "Failed to connect to marking head.\n\n";
         msg += headConnectResult.ToString();
         dialogResult = MessageBox.Show(msg, "Error!", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
         if (dialogResult != DialogResult.Abort && dialogResult != DialogResult.Ignore)
         {
             headConnectResult = laserHardware.ConnectToHead(lsd.HeadIndex);
         }
     }
     if (dialogResult == DialogResult.Abort)
     {
         Application.Exit();
         return;
     }
     LaserMarker.Instance.LaserHardware = laserHardware;
     //load model files
     Models models = Models.Instance;
     if (File.Exists(Settings.ModelsFile))
     {
         models.LoadModels(Settings.ModelsFile);
     }
     //enable input text box
     this.input.Enabled = true;
 }
        /// <summary>
        /// Populates the listbox and markHeads array with mark heads
        /// from the laserHardware instances
        /// </summary>
        private void PopulateList()
        {
            this.listBoxHeads.Items.Clear();
            this.selectedHardware = null;

            //get total number of heads
            int totalHeads = 0;
            foreach (ILaserHardware hardware in this.laserHardware)
            {
                totalHeads += hardware.GetHeadList().Length;
            }
            //
            this.markHeads = new MarkHead[totalHeads];
            int markHeadsIndex = 0;
            for (int hardwareIndex = 0; hardwareIndex < this.laserHardware.Length; hardwareIndex++)
            {
                //get list of heads for this laser hardware instance
                string[] heads = this.laserHardware[hardwareIndex].GetHeadList();
                int headIndex = 0;
                foreach (string head in heads)
                {
                    //add head to the markHeads array
                    this.markHeads[markHeadsIndex] = new MarkHead();
                    this.markHeads[markHeadsIndex].Hardware = this.laserHardware[hardwareIndex];
                    this.markHeads[markHeadsIndex].Name = head;
                    this.markHeads[markHeadsIndex].Index = headIndex;
                    //add head to listbox
                    this.listBoxHeads.Items.Add(head);
                    headIndex ++;
                    markHeadsIndex ++;
                }

            }

            if (this.listBoxHeads.Items.Count > 0)
            {
                this.listBoxHeads.SelectedIndex = 0;
            }
        }
 void ListBoxHeadsSelectedIndexChanged(object sender, System.EventArgs e)
 {
     //get the required head from the mark heads array
     MarkHead head = this.markHeads[this.listBoxHeads.SelectedIndex];
     this.selectedHardware = head.Hardware;
     this.SelectedHead = head.Index;
 }