示例#1
0
def open_device():
    log.info('attempting to connect over USB')
    try:
        gdx.open_usb()
    except OSError as _:
        gdx.devices = []
        pass
    if not gdx.devices:
        log.info('attempting to connect over BLE')
        try:
            gdx.open_ble(config['device_id'])
        except OSError as _:
            return False
    # select sensors for GDX-RB 0K1007T6 BLE -41
    # 1: Force (N)
    # 2: Respiration Rate (bpm)
    # 4: Steps (steps)
    # 5: Step Rate (spm)
    gdx.select_sensors([1,2])
    gdx.start(int(config['sampling_period_ms']))
    return True
示例#2
0
def simulation(q):

    import time
    from gdx import gdx  #The gdx function calls are from a gdx.py file inside the gdx folder, which must be with this program.

    gdx = gdx.gdx()

    time_between_readings_in_seconds = 0.2
    number_of_readings = 500
    digits_of_precision = 2

    gdx.open_usb()
    gdx.select_sensors(
        [1]
    )  # You will be asked to select the sensors to be used. You can select up to three.

    sensor_times = []
    sensor_readings = []
    period_in_ms = time_between_readings_in_seconds * 1000

    gdx.start(period_in_ms)

    # Data Collection:

    collection_complete = False
    while not collection_complete:
        try:
            time = 0
            print('Starting...')

            for i in range(0, number_of_readings):

                # This is where we are reading the list of measurements from the sensors.
                measurements = gdx.read()
                if measurements == None:
                    break

                q.put([time, measurements[0]])

                # Update the time variable with the new time for the next data point
                time = time + time_between_readings_in_seconds

            # The data collection loop is finished
            collection_complete = True
            print('Data collection complete.')

            #stop sensor readings and disconnect device
            gdx.stop()
            gdx.close()

            q.put('Q')
            exit()

        except KeyboardInterrupt:
            collection_complete = True
            gdx.stop()  #Stop sensor readings
            gdx.close()  #Disconnect the device
            print('data  collection stopped by keypress')
            print('Number of readings: ', i + 1)
            q.put('Q')
            exit()
示例#3
0
'''
In this example we are saving the data to a csv file to be opened with Excel.

'''

from gdx import gdx
gdx = gdx.gdx()

import csv

myFile = open('csvexample.csv', 'w', newline='')
writer = csv.writer(myFile)

gdx.open_usb()
gdx.select_sensors([1, 2])
gdx.start(period=500)
column_headers = gdx.enabled_sensor_info()
writer.writerow(column_headers)

for i in range(0, 5):
    measurements = gdx.read()
    if measurements == None:
        break
    writer.writerow(measurements)
    print(measurements)

gdx.stop()
gdx.close()