Beispiel #1
0
def main(portNum):
    if (len(nanoPorts) > 0):

        ser = serial.Serial(
        port= nanoPorts[portNum],\
        baudrate=baudRate,\
        parity  =serial.PARITY_NONE,\
        stopbits=serial.STOPBITS_ONE,\
        bytesize=serial.EIGHTBITS,\
        timeout=0)

        print(" ")
        print("Connected to: " + ser.portstr)
        print(" ")

        #this will store the line
        line = []

        while True:
            # try:
            for c in ser.read():
                line.append(chr(c))
                if chr(c) == '~':
                    dataString = (''.join(line))
                    dataStringPost = dataString.replace('~', '')
                    print("================")
                    print(dataStringPost)
                    mSR.dataSplit(dataStringPost, datetime.datetime.now())
                    line = []
                    break
            # except:
            #     print("Incomplete String Read")
            #     line = []
        ser.close()
Beispiel #2
0
def readPort(port):
    ser = serial.Serial(port=port,
                        baudrate=2400,
                        parity=serial.PARITY_NONE,
                        stopbits=serial.STOPBITS_ONE,
                        bytesize=serial.EIGHTBITS,
                        timeout=0)

    print("Connected to: {0}".format(ser.portstr))

    line = []  # used to store a line of data
    while True:  # continuously check for data
        try:
            for c in ser.read():
                line.append(chr(c))  # add character to line
                if chr(c) == '\n':  # line ends at newline character
                    dataString = ''.join(line)
                    dataString = dataString.replace('\n', '')
                    # make the dataString take the proper mints format
                    dataString = formatForDeviceType(dataString, ser)
                    #print(dataString)
                    dt = datetime.datetime.now()
                    mSR.dataSplit(dataString, dt)
                    line = []
        except:
            print("Incomplete read. Something may be wrong with {0}".format(
                port))
            line = []
Beispiel #3
0
def main():
    if (len(nanoPorts) > 0):

        ser = serial.Serial(
        port= nanoPorts[0],\
        baudrate=9600,\
        parity  =serial.PARITY_NONE,\
        stopbits=serial.STOPBITS_ONE,\
        bytesize=serial.EIGHTBITS,\
        timeout=0)

        print("connected to: " + ser.portstr)

        #this will store the line
        line = []

        while True:

            for c in ser.read():
                line.append(chr(c))
                if chr(c) == '~':
                    dataString = (''.join(line))
                    dataStringPost = dataString.replace('~', '')
                    print(dataStringPost)
                    dt = datetime.datetime.now()
                    mSR.dataSplit(dataStringPost, dt)
                    line = []

        ser.close()
Beispiel #4
0
def main():
    if(licorPort[0]):
        ser = serial.Serial(
            port = licorPort[1],
            baudrate = 9600,
            parity = serial.PARITY_NONE,
            stopbits = serial.STOPBITS_ONE,
            bytesize = serial.EIGHTBITS,
            timeout = 0)

        print("Connection successful!")
        ser.write("<li850><rs232><strip>true</strip></rs232></li850>".encode('utf-8'))
        time.sleep(5)
        line = []
        while True:
            try:
                for c in ser.read():
                    line.append(chr(c))
                    if(chr(c)=='\n'):
                        dataString     = (''.join(line))
                        # get rid of end line and carriage return characters if they exist
                        dataString = dataString.replace('\n', '')
                        dataString = dataString.replace('\r', '')
                        dataString = "~#mints0!LICOR>" + dataString
                        dt = datetime.datetime.now()
                        mSR.dataSplit(dataString, dt)
                        line = []
            except:
                print("Incomplete string read. Something may be wrong with the Licor sensor")
                line = []