def cb_enumerate(uid, connected_uid, position, hardware_version, 
                 firmware_version, device_identifier, enumeration_type):
    
    if connected_uid == '0':
        print 'Master Brick UID: \t%s' % (uid)
    
    #print 'UID: %s' % uid
    #print 'connected_uid: %s' % connected_uid
    #print 'position: %s' % position
    #print 'hardware_version: %i.%i.%i' % hardware_version
    #print 'firmware_version: %i.%i.%i' % firmware_version
    #print 'device_identifier: %d' % device_identifier
    #print 'enumeration_type: %d' % enumeration_type
    
    
    if enumeration_type == IPConnection.ENUMERATION_TYPE_CONNECTED or \
       enumeration_type == IPConnection.ENUMERATION_TYPE_AVAILABLE:
        
        # Enumeration is for IMU Brick
        if device_identifier == IMU.DEVICE_IDENTIFIER:
            
            print 'IMU Brick UID: \t\t%s' % (uid)
            
            # Create imu device object
            imu = IMU(uid, ipcon) 
            imu.set_all_data_period(100)
            imu.register_callback(imu.CALLBACK_ALL_DATA, cb_imudynamic)
            
            
        # Enumeration is for GPS Bricklet
        if device_identifier == GPS.DEVICE_IDENTIFIER:
            
            print 'GPS Bricklet UID: \t%s' % (uid)
            
            # Create imu device object
            gps = GPS(uid, ipcon) 
            gps.set_coordinates_callback_period(100)
            gps.register_callback(gps.CALLBACK_COORDINATES, cb_coordinates)
Esempio n. 2
0
PORT = 4223
UID = "ABC"  # Change to your UID

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_gps import GPS


# Callback function for coordinates
def cb_coordinates(latitude, ns, longitude, ew, pdop, hdop, vdop, epe):
    print('Latitude: ' + str(latitude / 1000000.0) + '° ' + ns)
    print('Longitude: ' + str(longitude / 1000000.0) + '° ' + ew)


if __name__ == "__main__":
    ipcon = IPConnection()  # Create IP connection
    gps = GPS(UID, ipcon)  # Create device object

    ipcon.connect(HOST, PORT)  # Connect to brickd
    # Don't use device before ipcon is connected

    # Set Period for coordinates callback to 1s (1000ms)
    # Note: The callback is only called every second if the
    #       coordinates have changed since the last call!
    gps.set_coordinates_callback_period(1000)

    # Register coordinates callback to function cb_coordinates
    gps.register_callback(gps.CALLBACK_COORDINATES, cb_coordinates)

    raw_input('Press key to exit\n')  # Use input() in Python 3
    ipcon.disconnect()
Esempio n. 3
0
HOST = "localhost"
PORT = 4223
UID = "ABC" # Change to your UID

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_gps import GPS

# Callback function for coordinates
def cb_coordinates(latitude, ns, longitude, ew, pdop, hdop, vdop, epe):
    print('Latitude: ' + str(latitude/1000000.0) + '° ' + ns)
    print('Longitude: ' + str(longitude/1000000.0) + '° ' + ew)

if __name__ == "__main__":
    ipcon = IPConnection() # Create IP connection
    gps = GPS(UID, ipcon) # Create device object

    ipcon.connect(HOST, PORT) # Connect to brickd
    # Don't use device before ipcon is connected

    # Set Period for coordinates callback to 1s (1000ms)
    # Note: The callback is only called every second if the 
    #       coordinates have changed since the last call!
    gps.set_coordinates_callback_period(1000)

    # Register coordinates callback to function cb_coordinates
    gps.register_callback(gps.CALLBACK_COORDINATES, cb_coordinates)

    raw_input('Press key to exit\n') # Use input() in Python 3
    ipcon.disconnect()