void interfaceKit_SensorChange(object sender, Phidgets.Events.SensorChangeEventArgs e)
        {
            //get value in cm
            double val = e.Value * 1.296;

            //set max distance to 2m
            if (val > 200)
            {
                val = 200;
            }

            switch (e.Index)
            {
                case 0:
                    rightData.Add(val);
                    if (rightData.Count > maxDataCount)
                    {
                        rightData.RemoveAt(0);
                    }
                    labelRightAvg.Text = (rightData.Sum() / rightData.Count).ToString("0.00");
                    labelRight.Text = val.ToString("0.00");
                    progressBarRight.Value = Convert.ToInt32(val);
                    break;

                case 1:
                    leftData.Add(val);
                    if (leftData.Count > maxDataCount)
                    {
                        leftData.RemoveAt(0);
                    }
                    labelLeftAvg.Text = (leftData.Sum() / leftData.Count).ToString("0.00");
                    labelLeft.Text = val.ToString("0.00");
                    progressBarLeft.Value = Convert.ToInt32(val);
                    break;

                case 2:
                    frontData.Add(val);
                    if (frontData.Count > maxDataCount)
                    {
                        frontData.RemoveAt(0);
                    }
                    labelFrontAvg.Text = (frontData.Sum() / frontData.Count).ToString("0.00");
                    labelFront.Text = val.ToString("0.00");
                    progressBarFront.Value = Convert.ToInt32(val);

                    if (val < 50)
                    {
                        labelAllStop.BackColor = Color.Red;
                        TriggerAllStopEvent();
                    }
                    else
                    {
                        labelAllStop.BackColor = this.BackColor;
                    }

                    break;
            }
        }
示例#2
0
 public bool AddPhidget(IPhidgetViewModel viewModel)
 {
     if (viewModel.PortNumber == PortNumber)
     {
         if (!Phidgets.Any(phidget => phidget.AddPhidget(viewModel)))
         {
             Phidgets.Add(viewModel);
         }
         Phidgets.Sort((a, b) => { return(a.DeviceName.CompareTo(b.DeviceName)); });
         return(true);
     }
     return(false);
 }
示例#3
0
文件: Program.cs 项目: summy00/IHA
 static void ifkit_SensorChange(object sender, Phidgets.Events.SensorChangeEventArgs e)
 {
     //e.Index = 0 is the PIR movement sensor for detecting user entry
     if (e.Index == 0 && (e.Value > 550 || e.Value < 450))
     {
         //UserSpotted(e);
     }
     //e.Index = 7 is the medicaiton box sensor
     if (e.Index == 7 && e.Value < 125)
     {
         MedicationTaken(e);
     }
     if (e.Index == 7 && e.Value > 450)
     {
         //MedicationSetBack(e);
     }
 }
示例#4
0
 void motor_VelocityChange(object sender, Phidgets.Events.VelocityChangeEventArgs e)
 {
     screen.rows[1].DisplayString = e.Velocity.ToString();
 }
 //Error event handler...Display the description of the error to the console
 void accel_Error(object sender, Phidgets.Events.ErrorEventArgs e)
 {
     messageTextBox.Text += e.Description.ToString();
 }
示例#6
0
 void phid_Error(object sender, Phidgets.Events.ErrorEventArgs e)
 {
     Console.WriteLine("Error event: " + e.Description);
 }
 //Error event handler...display the error description string
 static void rfid_Error(object sender, Phidgets.Events.ErrorEventArgs e)
 {
     Console.WriteLine(e.Description);
 }
示例#8
0
 void PhidgitController_Attach(object sender, Phidgets.Events.AttachEventArgs e)
 {
     Debug.WriteLine("Attach {0}", e.Device.Name);
 }
示例#9
0
 void PhidgitController_SensorChange(object sender, Phidgets.Events.SensorChangeEventArgs e)
 {
     Debug.WriteLine("sensor change {0}", e.Index);
 }
示例#10
0
 void motorControl_ServerDisconnect(object sender, Phidgets.Events.ServerDisconnectEventArgs e)
 {
 }
示例#11
0
 void motorControl_SensorUpdate(object sender, Phidgets.Events.SensorUpdateEventArgs e)
 {
 }
示例#12
0
 void motorControl_InputChange(object sender, Phidgets.Events.InputChangeEventArgs e)
 {
 }
示例#13
0
 void motorControl_Error(object sender, Phidgets.Events.ErrorEventArgs e)
 {
     try
     {
         if (_motorControl != null)
         {
             if (_motorControl.Attached)
             {
                 foreach (Phidgets.MotorControlMotor motor in _motorControl.motors)
                 {
                     motor.Velocity = 0;
                 }
             }
         }
         _motorControl.close();
     }
     catch
     {
         Fatal_Error();
     }
 }
示例#14
0
 void motorControl_EncoderPositionUpdate(object sender, Phidgets.Events.EncoderPositionUpdateEventArgs e)
 {
 }
示例#15
0
        void motorControl_Detach(object sender, Phidgets.Events.DetachEventArgs e)
        {
            try
            {
                groupKeys.Enabled = false;
                groupMotor1.Enabled = false;
                groupMotor2.Enabled = false;

                this.PreviewKeyDown -= Control_KeyDown;
                this.KeyUp -= Control_KeyUp;

                Application.DoEvents();
            }
            catch
            {
                Fatal_Error();
            }
        }
示例#16
0
 void manager_ServerDisconnect(object sender, Phidgets.Events.ServerDisconnectEventArgs e)
 {
     IsConnected = false;
     data.EventLog.Insert(sender.ToString(), "ServerDisconnect", e.Device.ToString());
 }
示例#17
0
 void motorControl_VelocityChange(object sender, Phidgets.Events.VelocityChangeEventArgs e)
 {
     try
     {
         if (e.Index == 0)
         {
             labelVelocity1.Text = e.Velocity.ToString();
         }
         else if (e.Index == 1)
         {
             labelVelocity2.Text = e.Velocity.ToString();
         }
     }
     catch
     {
         Fatal_Error();
     }
 }
示例#18
0
        //a piece of laundry has been dropped into a bin, the index tells us which one
        void PhidgitController_InputChange(object sender, Phidgets.Events.InputChangeEventArgs e)
        {
            logger.Info(string.Format("input change {0}", e.Index));

            int slot = e.Index;
            if (TargetBin == null)
            {
                this.Dispatcher.Invoke(new Action(delegate()
                {
                    ClearItemFields();
                    Errormsg.Text = "Target slot unknown  ... Please rescan item";
                    ErrorTxt.Visibility = Visibility.Visible;

                }));
                return;

            }
            //is item in the right slot
            if (slot != TargetBin.PhidgetSlot)
            {

                this.Dispatcher.Invoke(new Action(delegate()
                {

                    Errormsg.Text = "Please place item in right bin";
                    ErrorTxt.Visibility = Visibility.Visible;
                }));
            }
            else
                this.Dispatcher.Invoke(new Action(delegate()
                {
                    //this event is fired multiple times 
                    if (vm.bReceivedAlready == false)
                    {
                        ErrorTxt.Visibility = Visibility.Hidden;
                        logger.Info("write possibile changes to database");
                        if (vm.BCSMode)
                        {
                            if (item.Category.ID != 11)     //do not save next day info as next time the item might NOT be next day)
                                vm.SaveItem(item);
                        }
                        else
                        {
                            GSS gssItem = new GSS() { CreationDate = DateTime.Now, bin = TargetBin.PhidgetSlot, BarCode = TargetBin.BarCode };
                            vm.SaveItemGSS(gssItem);
                        }
                        ClearItemFields();
                        CustomerName.Text = "";

                    }
                    vm.PhidgitController.outputs[TargetBin.PhidgetSlot] = false;
                    vm.bReceivedAlready = true;

                }));

        }
示例#19
0
        void spatial_Attach(object sender, Phidgets.Events.AttachEventArgs e)
        {
            Spatial attached = (Spatial)sender;
            attachedTxt.Text = attached.Attached.ToString();
            nameTxt.Text = attached.Name;
            serialTxt.Text = attached.SerialNumber.ToString();
            versionTxt.Text = attached.Version.ToString();

            if (attached.compassAxes.Count < 3)
            {
                addMessage("You need to attach something with a compass to do anything usefull here...");
            }
            else
            {
                addMessage("Press start to begin calibration." + Environment.NewLine + "For more accuracy, you can enter the local field strength, which can be calculated for your location here: http://www.ngdc.noaa.gov/geomagmodels/IGRFWMM.jsp");
                sampleDoneButton.Enabled = true;
                spatial.DataRate = spatial.DataRateMax;

                //Do this in a seperate thread so the drawing doens't block the data event and cause errors.
                drawThread = new Thread(new ThreadStart(drawThreadFunc));
                drawThread.Start();
            }
        }
 //Error event handler...Display the error description to the console
 public void ifKit_Error(object sender, Phidgets.Events.ErrorEventArgs e)
 {
     Console.WriteLine(e.Description);
 }
示例#21
0
        void spatial_Detach(object sender, Phidgets.Events.DetachEventArgs e)
        {
            Spatial detached = (Spatial)sender;
            attachedTxt.Text = detached.Attached.ToString();
            nameTxt.Text = "";
            serialTxt.Text = "";
            versionTxt.Text = "";
            sampleDoneButton.Enabled = false;

            pictureBox1.Image = null;
            messagesTextBox.Clear();

            if (drawThread != null)
                if (drawThread.IsAlive)
                    drawThread.Abort();
        }
示例#22
0
 private void manager_Error(object sender, Phidgets.Events.ErrorEventArgs e)
 {
     Helper.Logger("HaptiQ_API.HaptiQsManager.manager_Error:: " + e.Description);
 }
示例#23
0
        void spatial_SpatialData(object sender, Phidgets.Events.SpatialDataEventArgs e)
        {
            //This displays a vector representing the measured field in red, and after calibration the calibrated field in green
            if (e.spatialData[0].MagneticField.Length == 3)
            {
                lock (p)
                {
                    if (twoAxisButton.Checked)
                    {
                        p.originalVertices[4] = new Vector3(
                            e.spatialData[0].MagneticField[0],
                            e.spatialData[0].MagneticField[1],
                            -e.spatialData[0].MagneticField[2]);
                        if (calibrated)
                        {
                            Vector3 rawData = new Vector3(e.spatialData[0].MagneticField[0], e.spatialData[0].MagneticField[1], e.spatialData[0].MagneticField[2]);
                            Vector3 calibratedData = Matrix3x3.Multiply(Vector3.Subtract(rawData, cal.offset), cal.gainAndTransform);

                            //apply local mag field - calibrate returns a unit (mag 1) field
                            calibratedData = Vector3.Multiply(double.Parse(localFieldTextBox.Text), calibratedData);

                            p.originalVertices[5] = new Vector3(
                                calibratedData.X,
                                calibratedData.Y,
                                -calibratedData.Z);
                        }
                    }
                    else
                    {
                        p.originalVertices[4] = new Vector3(
                            e.spatialData[0].MagneticField[0],
                            e.spatialData[0].MagneticField[2],
                            -e.spatialData[0].MagneticField[1]);
                        if (calibrated)
                        {
                            Vector3 rawData = new Vector3(e.spatialData[0].MagneticField[0], e.spatialData[0].MagneticField[1], e.spatialData[0].MagneticField[2]);
                            Vector3 calibratedData = Matrix3x3.Multiply(Vector3.Subtract(rawData, cal.offset), cal.gainAndTransform);

                            //apply local mag field - calibrate returns a unit (mag 1) field
                            calibratedData = Vector3.Multiply(double.Parse(localFieldTextBox.Text), calibratedData);

                            p.originalVertices[5] = new Vector3(
                                calibratedData.X,
                                calibratedData.Z,
                                -calibratedData.Y);
                        }
                    }
                }
            }

            //This samples magnetic field data
            if (sampling)
            {
                lock (compassSamples)
                {
                    if (sampling)
                    {
                        sampleCounter++;
                        if (sampleCounter >= samplesPerSample)
                        {
                            sampleCounter = 0;
                            if (e.spatialData[0].MagneticField.Length == 3)
                            {
                                compassSamples.Add(
                                    new compassDataPoint(
                                    e.spatialData[0].MagneticField[0],
                                    e.spatialData[0].MagneticField[1],
                                    e.spatialData[0].MagneticField[2]
                                    )
                                );

                                //This draws the magnetic vectors as dots
                                lock (p)
                                {
                                    if (twoAxisButton.Checked)
                                    {
                                        p.addPoint(new Vector3(
                                            e.spatialData[0].MagneticField[0],
                                            e.spatialData[0].MagneticField[1],
                                            -e.spatialData[0].MagneticField[2]), Brushes.Red);
                                    }
                                    else
                                    {
                                        p.addPoint(new Vector3(
                                            e.spatialData[0].MagneticField[0],
                                            e.spatialData[0].MagneticField[2],
                                            -e.spatialData[0].MagneticField[1]), Brushes.Red);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
示例#24
0
		//error handler...display the error description in a messagebox
		void br_Error(object sender, Phidgets.Events.ErrorEventArgs e) {
			Phidget phid = (Phidget)sender;
			DialogResult result;
			switch (e.Type) {
				case PhidgetException.ErrorType.PHIDGET_ERREVENT_BADPASSWORD:
					phid.close();
					TextInputBox dialog = new TextInputBox("Error Event",
						"Authentication error: This server requires a password.", "Please enter the password, or cancel.");
					result = dialog.ShowDialog();
					if (result == DialogResult.OK)
						openCmdLine(phid, dialog.password);
					else
						Environment.Exit(0);
					break;
				default:
					if (!errorBox.Visible)
						errorBox.Show();
					break;
			}
			errorBox.addMessage(DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString() + ": " + e.Description);
		}
        /// <summary>
        /// Updates the tram number when a new RFID tag is scanned.
        /// </summary>
        /// <param name="sender">Contains a reference to the RFID manager.</param>
        /// <param name="e">Contains the RFID tag that was scanned.</param>
        private void RFIDManager_DataReceived(object sender, Phidgets.Events.TagEventArgs e)
        {
            this.tramNumber = e.Tag;

            TextBoxUpdate textBoxUpdate = new TextBoxUpdate(this.UpdateTextBox);
            this.Invoke(textBoxUpdate);
        }
示例#26
0
 void motor_Attach(object sender, Phidgets.Events.AttachEventArgs e)
 {
     screen.rows[0].DisplayString = "motor attached";
 }
 /// <summary>
 /// Gives a message box when the RFID scanner has been detached.
 /// </summary>
 /// <param name="sender">Contains a reference to the RFID manager</param>
 /// <param name="e">Contains the detach event data.</param>
 private void RFIDManager_Detached(object sender, Phidgets.Events.DetachEventArgs e)
 {
     MessageBox.Show("An RFID reader has been detached.");
 }
示例#28
0
        void interfaceKit_SensorChange(object sender, Phidgets.Events.SensorChangeEventArgs e)
        {
            //get value in cm
            double val = e.Value * 1.296;

            //set max distance to 2m
            if (val > 200)
            {
                val = 200;
            }

            switch (e.Index)
            {
                case 0:
                    //right
                    break;

                case 1:
                    //left
                    break;

                case 2:

                    //frontData.Add(val);
                    //if (frontData.Count > 100)
                    //{
                    //    frontData.RemoveAt(0);
                    //}

                    //double d = frontData.Sum() / frontData.Count;

                    frontData = val;
                    screen.rows[0].DisplayString = val.ToString(); // + " - " + frontData.Count.ToString();

                    //if (frontData.Count > 70)
                    //{

                        if (val <= 30)
                        {
                            DeadStop();
                        }

                    //}

                    break;
            }
        }
示例#29
0
 void manager_Detach(object sender, Phidgets.Events.DetachEventArgs e)
 {
     data.EventLog.Insert(sender.ToString(), "Detach", e.Device.ToString());
 }
        void FrequencyCounter_Packet(object sender, Phidgets.Events.PacketEventArgs e)
        {
            int[] Count = new int[2];
            int[] TimeLastEvent = new int[2];

            //Read the packet
            int n = 0;
            int TimerCount = ((int)e.Packet[n++]) | ((int)e.Packet[n++] << 8);
            Count[0] = (((int)e.Packet[n++]) | ((int)e.Packet[n++] << 8) | ((int)e.Packet[n++] << 16));
            TimeLastEvent[0] = ((int)e.Packet[n++]) | ((int)e.Packet[n++] << 8);
            Count[1] = (((int)e.Packet[n++]) | ((int)e.Packet[n++] << 8) | ((int)e.Packet[n++] << 16));
            TimeLastEvent[1] = ((int)e.Packet[n++]) | ((int)e.Packet[n++] << 8);

            for (int i = 0; i < 2; i++)
            {
                long lastCount = inputs[i].totalCount;
                double lastFreq = inputs[i].frequency;
                inputs[i].totalCount += Count[i];
                inputs[i].totalTime += TimerCount;

                if (Count[i] == 0)
                {
                    if (i == 0)
                        i = 0;
                    if (inputs[i].adjust != -1) //Do not accumulate if timed out
                        inputs[i].adjust += TimerCount;
                    if (inputs[i].adjust > inputs[i].timeOut * tickspersec)
                    {
                        inputs[i].adjust = -1;
                        inputs[i].frequency = 0;
                        OnCountChange(new CountChangeEventArgs(i, (int)Count[i], (int)inputs[i].frequency, (int)TimerCount));
                    }
                }
                else if (Count[i] >= 1)
                {
                    if ((inputs[i].adjust == -1) && (Count[i] == 1))
                        inputs[i].adjust = TimerCount - TimeLastEvent[i];
                    else
                    {
                        if (inputs[i].adjust == -1)
                            inputs[i].adjust = 0;
                        inputs[i].frequency = (double)((double)Count[i] / (inputs[i].adjust + TimeLastEvent[i]) * tickspersec);
                        inputs[i].adjust = TimerCount - TimeLastEvent[i];
                    }
                }

                if(lastCount != inputs[i].totalCount)
                    OnCountChange(new CountChangeEventArgs(i, (int)Count[i], (double)inputs[i].frequency, (long)TimerCount));

            }
        }
示例#31
0
        void manager_Error(object sender, Phidgets.Events.ErrorEventArgs e)
        {
            //kill all phidgets
            manager.close();

            data.EventLog.Insert(sender.ToString(), "Error", e.Type + " - " + e.Description, true);
        }