예제 #1
0
        static void Main(string[] args)
        {
            //string tekApiUserPath = @"D:\EPFL\thesis\Tekscan\myClient\TekAPI";

            string tekApiUserPath = @"/home/paul/thesis/Tekscan/myClient/TekAPI";

            /* Load a calibration/equilibration (optional)
             * Return types are CTekEquilibration and CTekCalibration objects,
             * respectively. These objects provide a function allowing for calibration
             * and equilibration of arrays of captured frame data and can also be passed
             * as parameters to functions that save recordings or apply calibrations and
             * equilibrations to .fsx files.
             */

            string mapFileDirectory = tekApiUserPath + @"/Samples"; // must set map file directory to load a calibration

            Console.WriteLine(mapFileDirectory);
            CTekAPI.TekSetMapFileDirectory(mapFileDirectory);
            string            equilibrationFilePath = tekApiUserPath + @"/Samples/SampleEquil.equ";
            string            calibrationFilePath   = tekApiUserPath + @"/Samples/SampleCal.cal";
            CTekEquilibration equilibration         = CTekAPI.TekLoadEquilibration(equilibrationFilePath);
            CTekCalibration   calibration           = CTekAPI.TekLoadCalibration(calibrationFilePath);

            // Find and claim available hardware
            // Required as first step before any hardware will be recognized.
            CTekAPI.TekInitializeHardware();

            // Get list of available serial numbers, returned as System.String[].
            String[] availableSerialNumbers;
            int      errorCode = CTekAPI.TekEnumerateHandles(out availableSerialNumbers);

            // Get lowest serial number to use as an identifier for future calls.
            string serialNumber = availableSerialNumbers[0]; // sensor with lowest serial number

            // The map file used here should match the type of sensor you are using.
            string mapFilePath = tekApiUserPath + @"/Samples/null.mp";

            CTekAPI.TekClaimSensor(ref availableSerialNumbers, mapFilePath);

            // Set up the selected sensor
            long framePeriod = 10000;                               // controls the period in microseconds of data collection (1/frequency)

            CTekAPI.TekInitializeSensor(serialNumber, framePeriod); // framePeriod in microseconds: 10000 microseconds = 100 Hz

            // Sensitivity can  be set using an integer 1-40 (matching IScan
            // slider levels)
            CTekAPI.TekSetSensitivityLevel(serialNumber, 20);

            /* OR
             * Sensitivity can also be set to match a calibration file's setting. This
             * method is highly recommended if you plan to apply calibrations to collected
             * data. While these operations will complete even if the sensitivity of the
             * recording and calibration do not match, an error code will be produced
             * when saving recordings with calibration or applying calibrations to recordings.
             */
            //CTekAPI.TekSetCalibratedSensitivity(serialNumber, calibration);

            // Get details about the sensor (optional)
            int    rows, columns;
            double rowSpacing, columnSpacing;

            errorCode     = CTekAPI.TekGetSensorRows(serialNumber, out rows);
            errorCode     = CTekAPI.TekGetSensorColumns(serialNumber, out columns);
            rowSpacing    = CTekAPI.TekGetSensorRowSpacing(serialNumber, out rowSpacing);
            columnSpacing = CTekAPI.TekGetSensorColumnSpacing(serialNumber, out columnSpacing);

            // Get frame data in real time
            int timeOut = 25000; // time-out in milliseconds

            byte[] frameData;
            errorCode = CTekAPI.TekCaptureDataFrame(serialNumber, timeOut, out frameData);
            string lastError = CTekAPI.TekGetLastError();


            // Print frame to console in space-delimited format
            // The array returned when capturing a frame contains columns from the sensor appended in sequence
            while (CTekAPI.TekCaptureHSDataFrame(serialNumber, out frameData) == 0)
            {
                for (int i = 0; i < frameData.Length; i++)
                {
                    // Write data to console
                    Console.Write(frameData[i] + " ");

                    // If next element is the start of a new column, start a new line
                    if ((i + 1) % columns == 0)
                    {
                        Console.WriteLine();
                    }
                }
            }

            // Apply calibration and equilibration to frame data (optional)
            equilibration.TekEquilibrate(frameData); // passed by reference, data is now equilibrated

            double[] frameDataCalibrated;
            errorCode = calibration.TekCalibrate(frameData, out frameDataCalibrated);

            // Take a recording
            CTekAPI.TekStartRecording(5); // 5 second recording
            Console.WriteLine("Recording...");

            // Total number frames that will be collected
            int framesToRecord;

            errorCode = CTekAPI.TekGetFramesToRecord(serialNumber, out framesToRecord);

            // Wait until the recording is complete
            int framesRecorded;

            while (CTekAPI.TekIsRecording( ) == 0)
            {
                // Can also get the number of frames recorded so far
                errorCode = CTekAPI.TekGetFramesRecorded(serialNumber, out framesRecorded);
                System.Threading.Thread.Sleep(100);
            }
            Console.WriteLine("Recording complete.");

            // Or, can manually stop the recording at any point
            CTekAPI.TekStopRecording();

            // Save the recording
            string recordingPath = tekApiUserPath + @"/Samples/MySampleRecording.fsx";

            CTekAPI.TekSaveRecording(serialNumber, ref recordingPath);
            Console.WriteLine("Recording saved.");
            // OR
            // Recordings can also be saved with calibrations and equilibrations
            // CTekAPI.TekSaveRecording(serialNumber, ref recordingPath, equilibration);
            // CTekAPI.TekSaveRecording(serialNumber, ref recordingPath, calibration);
            // CTekAPI.TekSaveRecording(serialNumber, ref recordingPath, equilibration, calibration);

            /* IMPORTANT: Release hardware resources
             * Failure to do this could leave hardware in an unusable state, requiring
             * the handle/hub to be disconnected and reconnected to cycle power. Placing
             * this code in the catch block of a try-catch can ensure that errors in
             * other parts of the program do not prevent these statements from executing.
             */
            CTekAPI.TekReleaseSensor(serialNumber);
            CTekAPI.TekDeinitializeHardware();
        }
예제 #2
0
        static void Main(string[] args)
        {
            // Open .FSX file
            // Set the location to look for .mp files
            string mapFileDirectory = @"C:\Tekscan\TekAPI\Samples";

            CTekAPI.TekSetMapFileDirectory(mapFileDirectory);

            string   recordingPath = @"C:\Tekscan\TekAPI\Samples\SampleRecording.fsx";
            CTekFile recording     = CTekAPI.TekLoadRecording(recordingPath);

            // Get data from file
            int frameNumber = 0; // 0-based frame counting (first frame of the recording)

            byte[] recordingData, peakFrameData;
            int    errorCode = recording.TekGetRawFrameData(out recordingData, frameNumber);

            errorCode = recording.TekGetPeakFrameData(out peakFrameData);

            /* Will only return calibrated data if recording has a calibration applied.
             * Both raw and calibrated data will be equilibrated if an equilibration is
             * applied to the recording.
             */
            double[] calibratedRecordingData;
            errorCode = recording.TekGetCalibratedFrameData(out calibratedRecordingData, frameNumber);

            // Get details about the recording
            int    rows           = recording.TekGetRows();
            int    columns        = recording.TekGetColumns();
            int    numberOfFrames = recording.TekGetFrameCount();
            double rowSpacing     = recording.TekGetRowSpacing();
            double columnSpacing  = recording.TekGetColumnSpacing();

            // Print frame to console in space-delimited format
            // The array returned from the recording contains columns from the sensor appended in sequence
            for (int i = 0; i < recordingData.Length; i++)
            {
                // Write data to console
                Console.Write(recordingData[i] + " ");

                // If next element is the start of a new column, start a new line
                if ((i + 1) % columns == 0)
                {
                    Console.WriteLine();
                }
            }

            /* Load a calibration/equilibration (optional)
             * Return types are CTekEquilibration and CTekCalibration objects,
             * respectively. These objects provide a function allowing for calibration
             * and equilibration of arrays of captured frame data and can also be passed
             * as parameters to functions that save recordings or apply calibrations and
             * equilibrations to .fsx files.
             */
            string            equilibrationFilePath = @"C:\Tekscan\TekAPI\Samples\SampleEquil.equ";
            string            calibrationFilePath   = @"C:\Tekscan\TekAPI\Samples\SampleCal.cal";
            CTekEquilibration equilibration         = CTekAPI.TekLoadEquilibration(equilibrationFilePath);
            CTekCalibration   calibration           = CTekAPI.TekLoadCalibration(calibrationFilePath);

            /* Apply calibrations and equilibrations to files
             * While these operations will complete even if the sensitivity of the
             * recording and calibration do not match (not recommended), an error code
             * will be produced when saving recordings or applying calibrations to recordings.
             */
            //recording.TekApplyCalibration(calibration);
            //recording.TekApplyEquilibration(equilibration);

            // Undo calibrations and equilibrations in files
            recording.TekClearCalibration();
            recording.TekClearEquilibration();
        }