コード例 #1
0
ファイル: SingleTact.cs プロジェクト: SingleTact/NETInterface
        /// <summary>
        /// Reset baseline of all elements
        /// </summary>
        /// <returns>true if successful; false otherwise.</returns>
        public bool Tare()
        {
            ushort scaling = Settings.Scaling;

            if (lastFrame_ == null)
            {
                return(false);
            }

            Settings.Baselines = new UInt16[lastFrame_.nSensors]; //Zeros
            Settings.Scaling   = 100;

            PushSettingsToHardware();

            Thread.Sleep(10); // Give it time to capture a new frame

            SingleTactFrame newFrame = ReadSensorData();

            UInt16[] newBaselines = new UInt16[newFrame.SensorDataRaw.Length];
            for (int i = 0; i < newFrame.SensorDataRaw.Length; i++)
            {
                newBaselines[i] = (UInt16)(newFrame.SensorDataRaw[i] - 0xFF);
            }

            Settings.Baselines = newBaselines;
            Settings.Scaling   = scaling;
            PushSettingsToHardware();

            return(true);
        }
コード例 #2
0
        public SingleTactFrame DeepClone()
        {
            SingleTactFrame toReturn = new SingleTactFrame();
            toReturn.nSensors_ = this.nSensors;
            toReturn.timeStamp_ = this.timeStamp_;
            toReturn.sensorData_ = new double[nSensors_];

            for (int i = 0; i < sensorData_.Length; i++)
            toReturn.sensorData_[i] = sensorData_[i];

            return toReturn;
        }
コード例 #3
0
        public SingleTactFrame DeepClone()
        {
            SingleTactFrame toReturn = new SingleTactFrame();

            toReturn.nSensors_   = this.nSensors;
            toReturn.timeStamp_  = this.timeStamp_;
            toReturn.sensorData_ = new double[nSensors_];

            for (int i = 0; i < sensorData_.Length; i++)
            {
                toReturn.sensorData_[i] = sensorData_[i];
            }

            return(toReturn);
        }
コード例 #4
0
ファイル: SingleTact.cs プロジェクト: SingleTact/NETInterface
        /// <summary>
        /// Read sensor for new pressure measurement
        /// </summary>
        /// <returns>New frame if one is available</returns>
        public SingleTactFrame ReadSensorData()
        {
            //Sample read code - reading sensor data
            byte[] newByteData = arduino_.ReadFromMainRegister(128, 6, i2cAddress_);  //Read 6 bytes of sensor from location 128 in main register
            if (null != newByteData)
            {
                UInt16 itr = (UInt16)((newByteData[0 + ArduinoSingleTactDriver.TIMESTAMP_SIZE] << 8) + newByteData[1 + ArduinoSingleTactDriver.TIMESTAMP_SIZE]);

                if (itr_ == itr && lastFrame_ != null)
                {
                    return(lastFrame_);
                }
                itr_ = itr;

                UInt32 timeStampRaw = (UInt32)((newByteData[0] << 24) + (newByteData[1] << 16) + (newByteData[2] << 8) + newByteData[3]);
                if (isFirst == true)
                {
                    isFirst   = false;
                    startTime = timeStampRaw;
                }
                timeStampRaw -= startTime;
                double timeStamp = (double)timeStampRaw / 10000.0; //10kHz clock

                UInt16[] sensorData = new UInt16[(int)(newByteData.Length - ArduinoSingleTactDriver.TIMESTAMP_SIZE - 4) / 2];

                //Do it manually to avoid confusion with Endianess - Windows is little, sensor is big.
                //ToDo find a more elegent solution!
                for (int i = 0; i < sensorData.Length; i++)
                {
                    sensorData[i] = (UInt16)((newByteData[2 * i + 4 + ArduinoSingleTactDriver.TIMESTAMP_SIZE] << 8) + newByteData[2 * i + 5 + ArduinoSingleTactDriver.TIMESTAMP_SIZE]);
                }

                SingleTactFrame toReturn = new SingleTactFrame(sensorData, timeStamp);
                lastFrame_ = toReturn.DeepClone(); // keep a local copy of the last frame, used in taring
                return(toReturn);
            }
            else  // USB has been unplugged
            {
                return(null);
            }
        }
コード例 #5
0
ファイル: USBDevice.cs プロジェクト: SingleTact/NETInterface
 /// <summary>
 /// Add frame to frame list
 /// </summary>
 public void addFrame(SingleTactFrame frame)
 {
     _frameList.Add(frame);
 }
コード例 #6
0
ファイル: SingleTact.cs プロジェクト: SingleTact/NETInterface
        /// <summary>
        /// Read sensor for new pressure measurement
        /// </summary>
        /// <returns>New frame if one is available</returns>
        public SingleTactFrame ReadSensorData()
        {
            //Sample read code - reading sensor data
            byte[] newByteData = arduino_.ReadFromMainRegister(128, 6, i2cAddress_);  //Read 6 bytes of sensor from location 128 in main register
            if (null != newByteData)
            {
                UInt16 itr = (UInt16)((newByteData[0 + ArduinoSingleTactDriver.TIMESTAMP_SIZE] << 8) + newByteData[1 + ArduinoSingleTactDriver.TIMESTAMP_SIZE]);

                if (itr_ != itr)
                {
                    itr_ = itr;

                    UInt32 timeStampRaw = (UInt32)((newByteData[0] << 24) + (newByteData[1] << 16) + (newByteData[2] << 8) + newByteData[3]);
                    double timeStamp = (double)timeStampRaw / 10000.0; //10kHz clock

                    UInt16[] sensorData = new UInt16[(int)(newByteData.Length - ArduinoSingleTactDriver.TIMESTAMP_SIZE - 4) / 2];

                    //Do it manually to avoid confusion with Endianess - Windows is little, sensor is big.
                    //ToDo find a more elegent solution!
                    for (int i = 0; i < sensorData.Length; i++)
                    {
                        sensorData[i] = (UInt16)((newByteData[2 * i + 4 + ArduinoSingleTactDriver.TIMESTAMP_SIZE] << 8) + newByteData[2 * i + 5 + ArduinoSingleTactDriver.TIMESTAMP_SIZE]);
                    }

                    SingleTactFrame toReturn = new SingleTactFrame(sensorData, timeStamp);
                    lastFrame_ = toReturn.DeepClone();
                    return toReturn;
                }
                else
                {
                    return null;
                }
            }

            return null;
        }