def open_comms(COM_PORT):
    try:
        # create a Serial Connection with the specified COM Port, default baud rate of 921600
        connection = mscl.Connection.Serial(COM_PORT)

        # create a BaseStation with the connection
        baseStation = mscl.BaseStation(connection)

        if not baseStation.ping():
            print("Failed to ping the Base Station")
        else:
            print("Base Station is active")
            print("Attempting to enable the beacon...")
            # enable the beacon on the Base Station using the PC time
            startTime = baseStation.enableBeacon()
            print("Successfully enabled the beacon on the Base Station")
            print("Beacon's initial Timestamp:", startTime)
            print("Beacon is active")
            print("Sleeping for 3 seconds...")
            sleep(3)
            baseStation.disableBeacon()
            # if we got here, no exception was thrown, so disableBeacon was successful
            print("Successfully disabled the beacon on the Base Station")
            return connection, baseStation

    except Exception as e:
        print("Error: ", e)
        print('Check that ' + COM_PORT +
              ' is not in use and nodes are not connect to Sensor Connect')
        close_comms(connection)
Beispiel #2
0
# import the mscl library
import sys
sys.path.append("../../dependencies/Python")
import mscl

# TODO: change these constants to match your setup
COM_PORT = "COM3"
NODE_ADDRESS = 31849

try:
    # create a Serial Connection with the specified COM Port, default baud rate of 921600
    connection = mscl.Connection.Serial(COM_PORT)

    # create a BaseStation with the connection
    baseStation = mscl.BaseStation(connection)
    
    # create a WirelessNode with the BaseStation we created
    node = mscl.WirelessNode(NODE_ADDRESS, baseStation)

    # call the set to idle function and get the resulting SetToIdleStatus object
    status = node.setToIdle()

    print "Setting Node to Idle",

    # using the SetToIdleStatus object, check if the Set to Idle operation is complete.
    # Note: we are specifying a timeout of 300 milliseconds here which is the maximum
    #   amount of time that the complete function will block if the Set to Idle
    #   operation has not finished. Leaving this blank defaults to a timeout of 10ms.
    while not status.complete(300):
        # Note: the Set to Idle operation can be canceled by calling status.cancel()
Beispiel #3
0
def connectToBaseStation(com_port, baud_rate):
    conn = mscl.Connection.Serial(com_port, int(baud_rate))
    bs = mscl.BaseStation(conn)
    print("Connect base station: " + com_port + " " + baud_rate)
    return bs