Ejemplo n.º 1
0
 public void changeQSBResolution(int value)
 {
     foreach (IDevice QSBDevice in mDeviceManager.Devices)
     {
         QSB_S aQSB = (QSB_S)QSBDevice;
         aQSB.SetResolution((uint)value * 100);
     }
 }
 static QuadratureEncoderDataProvider()
 {
     try
     {
         mDeviceManager = new DeviceManager();
         mDeviceManager.Initialize();
         mQSB                = (QSB_S)mDeviceManager.GetDeviceOfType(0, typeof(QSB_S));
         pollTimer           = new System.Timers.Timer(100);
         pollTimer.Enabled   = false;
         pollTimer.AutoReset = false;
         pollTimer.Elapsed  += PollTimer_Elapsed;
     }
     catch (Exception exc)
     {
         Logging.Logger.Log(exc);
     }
 }
        /*private static void MQSB_OnRegisterValueChanged(object sender, RegisterChangeEventArgs args)
         * {
         *  DirectionOfRotation oldDirection = DirectionOfRotation;
         *
         *  if (args.Register == (byte)QSB.Register.ReadEncoder)
         *  {
         *      double timeDiffBetweenReadsInMinutes = Math.Abs(args.TimeStamp - lastCountTimeStamp) *
         *                                             QSB.TIMESTAMP_INTERVAL_IN_MINUTES;
         *      lastCountTimeStamp = args.TimeStamp;
         *
         *      double countDelta = Math.Abs(args.Value - (long)lastCount);
         *
         *      bool pos = false;
         *
         *      pos = (args.Value > lastCount);
         *      lastCount = args.Value;
         *
         *      if (DirectionOfRotation == DirectionOfRotation.Stopped && countDelta < STOP_CHANGE_THRESHOLD)
         *      {
         *          DirectionOfRotation = DirectionOfRotation.Stopped;
         *      }
         *      else
         *      {
         *          uint countsPerRevolution = ENCODER_PRESET + 1;
         *          if (timeDiffBetweenReadsInMinutes > 0)
         *          {
         *              //VELOCITY IS VELOCITY IN RPMs
         *              var velocity = (countDelta / countsPerRevolution) / timeDiffBetweenReadsInMinutes;
         *              double acceleration = Math.Abs(velocity - lastVelocity) / timeDiffBetweenReadsInMinutes;
         *              lastVelocity = velocity;
         *
         *              //ONLY CONSIDER THE SHAFT TO BE MOVING IF THE VELOCITY IS ABOVE CERTAIN NUMBER OF RPMS
         *              if (pos && velocity > MIN_RPM_THRESHOLD)
         *                  DirectionOfRotation = DirectionOfRotation.RotatingClockwise;
         *              else if (velocity > MIN_RPM_THRESHOLD)
         *                  DirectionOfRotation = DirectionOfRotation.RotatingCounterClockwise;
         *              else
         *                  DirectionOfRotation = DirectionOfRotation.Stopped;
         *          }
         *      }
         *
         *      if (oldDirection != DirectionOfRotation)
         *          FireStateChange();
         *  }
         * }*/

        private static void MDeviceManager_OnConnectionChanged(DeviceManager.DeviceConnectionEventArgs args)
        {
            var qsb = args.Device as QSB_S;

            if (qsb != null)
            {
                if (args.IsConnected && (mQSB == null))
                {
                    mQSB = qsb;
                    ConfigQsb();
                }
                else if (args.Device == mQSB)
                {
                    mQSB = null;
                }
            }
        }
Ejemplo n.º 4
0
        void aQSB_OnRegisterValueChanged(object sender, RegisterChangeEventArgs args)
        {
            QSB_S aQSB = (QSB_S)sender;

            if (m_recordData)
            {
                dataChart.Invoke((MethodInvoker) delegate { // Running on the UI thread
                    dataChart.Series["QSB " + aQSB.Connection].Points.AddXY(1.95 * args.TimeStamp, args.Value);
                    stringData.Add("QSB-D on " + aQSB.Connection + "\t" + (1.95 * args.TimeStamp).ToString() + "\t" + args.Value.ToString());
                });
            }
            else
            {
                deviceTableRef[2, deviceRowInTable[aQSB.Connection]].Value = args.Value.ToString();
                deviceTableRef[4, deviceRowInTable[aQSB.Connection]].Value = (1.95 * args.TimeStamp).ToString();
            }
        }
Ejemplo n.º 5
0
        public override void connectDevice(string port, DataGridView deviceTable, TextBox debugText, int inputDeviceType)
        {
            if (mDeviceManager == null)
            {
                mDeviceManager = new DeviceManager();
                mDeviceManager.Initialize();
            }
            QSB_S           aQSB = null;
            IList <IDevice> deviceManagerDevices = mDeviceManager.Devices;

            for (int i = 0; i < deviceManagerDevices.Count; i++)
            {
                QSBDeviceList.Add((QSB_S)deviceManagerDevices[i]);
            }
            for (int i = 0; i < QSBDeviceList.Count; i++)
            {
                if (QSBDeviceList[i].GetType().FullName.Contains("QSB"))
                {
                    aQSB = QSBDeviceList[i];
                    // Updated 10/31/2016 sys: Set the response format to include the device timestamp.
                    aQSB.SetResponseFormat(false, false, true, false);
                    var itemX = deviceTable.Rows.Add(aQSB.Connection, "QSB " + aQSB.SerialNumber.ToString(), "unknown", "count", "unknown");
                    for (int j = 0; j < deviceTable.Rows.Count; j++)
                    {
                        if (deviceTable[0, j].Value.ToString() == aQSB.Connection)
                        {
                            deviceRowInTable.Add(aQSB.Connection, j); //associate port with row #
                        }
                    }
                    var count = aQSB.StreamEncoderCount(0, 0);
                    aQSB.OnRegisterValueChanged += aQSB_OnRegisterValueChanged;
                    aQSB.SetResolution((uint)100 * 100);
                    debugText.AppendText("QSB connected on port " + aQSB.Connection + ".\n");
                }
            }
            // Configure QSB to stream count on timer interval. Each interval equal to apx. 1.95 ms.
            debugText.AppendText(deviceManagerDevices.Count.ToString() + " devices found\n");
            deviceType = inputDeviceType;
            this.setPort(port);
            deviceTableRef = deviceTable;
        }