示例#1
0
def send_wait_serial(data):
    app.logger.info(f'Sending {data} to PLC')
    if app.use_flask_serial:
        plc_ser.on_send(data + '\r\n')
    else:
        plc_ser.send_data(data)
        socketio.start_background_task(wait_for_start)
示例#2
0
def handle_message(msg):
    senddata = msg.decode("utf-8").strip()
    app.logger.info(senddata[0])
    if (senddata in ('G2')):
        socketio.emit('plc-message', senddata, namespace=Laser.NAMESPACE)
    elif (senddata in ('G1', 'G3')):
        socketio.emit('plc-message', senddata, namespace=Cartridge.NAMESPACE)
    elif (senddata in ('R')):
        socketio.emit('plc-message', senddata, namespace=Laser.NAMESPACE)
        socketio.emit('plc-message', senddata, namespace=Cartridge.NAMESPACE)
    elif (senddata in ('H0', 'E')):
        socketio.emit('plc-message', senddata, namespace=Laser.NAMESPACE)
        socketio.emit('plc-message', senddata, namespace=Cartridge.NAMESPACE)
        socketio.emit('plc-message', senddata, namespace='/home/api')
    elif (senddata[0] == 'P'):
        socketio.emit('position', senddata, namespace=Manual.NAMESPACE)
        app.logger.info(senddata)
        if (senddata[0:2] == 'P1'):
            plc_ser.on_send('P2\r\n')
        elif (senddata[0:2] == 'P2'):
            plc_ser.on_send('P3\r\n')
示例#3
0
def read_1dbarcodes():
    app.logger.info('Reading 1d barcode')
    # Get Rack ID
    barcode_ser.purge()
    barcode_ser.send_data("LON")

    errno = 0
    start = timer()
    while True:
        if barcode_ser.data_ready:
            tdata = barcode_ser.get().strip()
            if (',' in tdata):
                cartridge_id, work_order = tdata.split(',')
                if (get_folder_count(cartridge_id) >=
                        configfile.cartridge_assembly_QC['Max Retry']):
                    errno = -3
            else:
                cartridge_id = ''
                work_order = ''
                errno = -2

            break
        else:
            end = timer()
            if end - start > 2.0:
                app.logger.warn('Timeout getting barcode')
                cartridge_id = ''
                work_order = ''
                errno = -2
                break
            else:
                sleep(0.1)

    # TODO: Check whether it has exceeded max retry

    session[Cartridge.CARTRIDGE_ID] = cartridge_id
    session[Cartridge.WORK_ORDER] = work_order
    session[Cartridge.ERRORCODE] = errno

    if (errno == 0):
        plc_ser.on_send('G3\r\n')
        plc_ser.on_send('S\r\n')
        emit('get_cartridge_id', {'Cart_ID': cartridge_id, 'Error_No': errno})
    else:
        plc_ser.on_send('GB\r\n')
        session[Cartridge.DATA] = []
        logdata = (cartridge_id, 'FAIL',
                   work_order) + ('', ) * Cartridge.ITEM_QTY
        Log_file.write_file(configfile.cartridge_assembly_QC['LogFile'],
                            logdata, 0)
        app.logger.info('Redirecting page to cartridge-process')
        emit('redirect', url_for('cartridge_process'))
示例#4
0
def write_pos(cmd):
    app.logger.info(cmd)
    plc_ser.on_send(cmd + '\r\n')
示例#5
0
def send_wait_serial(data):
    app.logger.info(f'Sending {data} to PLC')
    plc_ser.on_send(data + '\r\n')
示例#6
0
def manual_connect():
    app.logger.info('Connected to Manual client interface')
    plc_ser.on_send('P1\r\n')
    session['position'] = 'P1'
    emit('response', 'Connected to Manual api')
示例#7
0
def read_barcodes():
    # Get Rack ID
    barcode_ser.purge()
    barcode_ser.send_data("LON")

    errno = 0
    start = timer()
    sdata = None
    while True:
        if barcode_ser.data_ready:
            sdata = barcode_ser.get().strip()
            break
        else:
            end = timer()
            if end - start > 2.0:
                app.logger.warn('Timeout getting barcode')
                errno = -2
                break
            else:
                sleep(0.1)

    # TODO: Handle sdata error

    if sdata:
        session[Laser.RACK_ID] = sdata
        app.logger.info('Rack ID: ' + sdata)
        if (sdata == 'ERROR'):
            app.logger.error('Error reading Rack ID barcode')
            errno = -3
        else:
            # Check the prefix
            if (sdata[:2] not in configfile.laser_etch_QC['Prefix']):
                errno = -4
                app.logger.error('Invalid Rack ID')
    else:
        session[Laser.RACK_ID] = ''
        errno = -1

    if (errno == 0):
        # Get barcodes
        items = tcpclient.send('T1')
        items.pop(0)
        totalitem = int(len(items) / 2)
        masklen = -len(session[Laser.MASK])
        newdata = []

        if (session[Laser.RACK_TYPE] == Laser.RACK_TYPE.TROUGH):
            if (totalitem != Laser.ITEM_QTY.TROUGH):
                errno = -6
        elif (session[Laser.RACK_TYPE] == Laser.RACK_TYPE.TUBE):
            if (totalitem != Laser.ITEM_QTY.TUBE):
                errno = -6

        if (errno == 0):
            for i in range(totalitem):

                if (items[i * 2] == '0'):  #success
                    # app.logger.info('ok barcode')
                    if (items[i * 2 + 1][masklen:] == session[Laser.MASK]):
                        newdata.append('0')
                        newdata.append(items[i * 2 + 1])
                    else:
                        newdata.append('1')
                        newdata.append(items[i * 2 + 1])
                        # app.logger.info(newdata)
                        errno = -5
                else:
                    newdata.append('1')
                    newdata.append(items[i * 2 + 1])
                    errno = -7
            app.logger.info(newdata)
            session[Laser.DATA] = newdata
        else:
            if (session[Laser.RACK_TYPE] == Laser.RACK_TYPE.TROUGH):
                session[Laser.DATA] = ['1', ''] * 4
            else:
                session[Laser.DATA] = ['1', ''] * 24

    else:
        if (session[Laser.RACK_TYPE] == Laser.RACK_TYPE.TROUGH):
            session[Laser.DATA] = ['1', ''] * 4
        else:
            session[Laser.DATA] = ['1', ''] * 24

        # data = b'T1,0,MS3092555-RMF,0,TG2003637-RMF,0,MS3007019-TMP,0,TG2003671-RMF,0,TG2003667-RMF,0,TG2003626-RMF,0,TG2003657-RMF,0,TG2003660-RMF,0,MS6754129-LMX2,0,TG2003642-RMF,0,MS2929572-AMS1,0,MS6999347-LMX1,0,MS6324325-NULL,0,MS5357075-PW1,0,MS3085936-LPM,0,MS3247197-HP11,0,MS6262931-NULL,0,MS5342413-PW1,0,TG2003635-RMF,0,TG2003630-RMF,0,MS3040982-HP12,0,TG2003661-RMF,0,MS6675922-LDR,0,TG2003640-RMF'

    session[Laser.ERRORCODE] = errno
    # writing to log file
    logdata = (session[Laser.WORK_ORDER], session[Laser.PART_NUMBER],
               session[Laser.INSTRUMENT], session[Laser.RACK_ID])
    if (errno == 0):  # pass
        logdata = logdata + (
            'TRUE',
            'TRUE',
            'TRUE',
            'PASS',
        )
    else:
        if (errno > -5):
            logdata = logdata + (
                'TRUE',
                'FALSE',
                'FALSE',
                'FAIL',
            )
        else:
            logdata = logdata + (
                'TRUE',
                'TRUE',
                'FALSE',
                'FAIL',
            )

    Log_file.write_file(configfile.laser_etch_QC['LogFile'], logdata, 1)
    app.logger.info("Go to home position")
    plc_ser.on_send('GB\r\n')
    app.logger.info('Redirecting page to laser_process')
    emit('redirect', url_for('laser_process'))
示例#8
0
def laser_confirm(laser_instrument):
    app.logger.info(
        f'Laser Etch QC confirm, laser instrument: {laser_instrument}')
    errno = 0  # Default no error

    # Save variables
    session[Laser.INSTRUMENT] = laser_instrument

    if app.use_flask_serial:
        plc_ser.on_send('S\r\n')
    else:
        plc_ser.purge()
        plc_ser.send_data("S")
        start = timer()
        while True:
            if plc_ser.data_ready:
                sdata = plc_ser.get()
                if sdata[:2] == "G2":  # Reach the scan location
                    break
            else:
                end = timer()
                if end - start > 7.0:
                    app.logger.warning('Timeout, going to scan position')
                    break
                else:
                    sleep(0.1)

        # Get Rack ID
        barcode_ser.purge()
        barcode_ser.send_data("LON")
        start = timer()

        sdata = None

        while True:
            if barcode_ser.data_ready:
                sdata = barcode_ser.get()
                break
            else:
                end = timer()
                if end - start > 3.0:
                    app.logger.warning('Timeout getting barcode')
                    break
                else:
                    sleep(0.1)

        # TODO: Handle sdata error

        if sdata:
            session[Laser.RACK_ID] = sdata[:-2]
            app.logger.info('Laser Etch QC received ' + session[Laser.RACK_ID])
            if (sdata[:5] == 'ERROR'):
                app.logger.warn('Can not read 1D barcode')
                errno = -2
            else:
                if (sdata[:2] not in configfile.laser_etch_QC['Prefix']):
                    errno = -3
                    app.logger.warn('Invalid Rack ID')
        else:
            errno = -1

        app.logger.warn(errno)

        if (errno == 0):
            # Get barcodes
            data = tcpclient.send('T1').pop(0)
            session[Laser.DATA] = data

            app.logger.info('Redirecting page to laser_process')
        else:
            session[Laser.DATA] = ['1', ''] * 24
            # data = b'T1,0,MS3092555-RMF,0,TG2003637-RMF,0,MS3007019-TMP,0,TG2003671-RMF,0,TG2003667-RMF,0,TG2003626-RMF,0,TG2003657-RMF,0,TG2003660-RMF,0,MS6754129-LMX2,0,TG2003642-RMF,0,MS2929572-AMS1,0,MS6999347-LMX1,0,MS6324325-NULL,0,MS5357075-PW1,0,MS3085936-LPM,0,MS3247197-HP11,0,MS6262931-NULL,0,MS5342413-PW1,0,TG2003635-RMF,0,TG2003630-RMF,0,MS3040982-HP12,0,TG2003661-RMF,0,MS6675922-LDR,0,TG2003640-RMF'

        session[Laser.ERRORCODE] = errno
        plc_ser.send_data('GB')
        app.logger.info("Sending GB")
        emit('redirect', url_for('laser_process'))
示例#9
0
def read_2dbarcodes():
    app.logger.info('Reading 2d barcode')

    # Get barcodes
    items = tcpclient.send('T1')
    items.pop(0)
    totalitem = int(len(items) / 2)

    newdata = []
    errno = 0
    cartridge_id = session[Cartridge.CARTRIDGE_ID]
    if ('-' in cartridge_id):
        a, section = cartridge_id.split('-')

        if (totalitem != Cartridge.ITEM_QTY):
            errno = -6
            session[Cartridge.DATA] = ['1', ''] * 23
            # data = b'T1,0,MS3092555-RMF,0,TG2003637-RMF,0,MS3007019-TMP,0,TG2003671-RMF,0,TG2003667-RMF,0,TG2003626-RMF,0,TG2003657-RMF,0,TG2003660-RMF,0,MS6754129-LMX2,0,TG2003642-RMF,0,MS2929572-AMS1,0,MS6999347-LMX1,0,MS6324325-NULL,0,MS5357075-PW1,0,MS3085936-LPM,0,MS3247197-HP11,0,MS6262931-NULL,0,MS5342413-PW1,0,TG2003635-RMF,0,TG2003630-RMF,0,MS3040982-HP12,0,TG2003661-RMF,0,MS6675922-LDR,0,TG2003640-RMF'

        else:
            sections = configfile.cartridge_assembly_QC_config.sections()
            app.logger.info(section)
            if (section not in sections):  # Invalid rack id
                app.logger.warn('Invalid cartridge id: ' + section)
                errno = -4
                for i in range(totalitem):
                    newdata.append('1')
                    newdata.append('')
                    newdata.append(items[i * 2 + 1])

                session[Cartridge.DATA] = newdata
            else:
                i = 1
                masks = []
                for j in range(21):
                    if (i == 3):
                        i = 4
                    keyword = 'Position_' + str(i)
                    masks.append(
                        configfile.cartridge_assembly_QC_config.get(
                            section, keyword))
                    i += 1

                for i in range(totalitem):
                    if (items[i * 2] == '0'):  #success
                        masklen = -len(masks[i])
                        if (items[i * 2 + 1][masklen:] == masks[i]):
                            newdata.append('0')
                            newdata.append(masks[i])
                            newdata.append(items[i * 2 + 1])
                        else:
                            newdata.append('1')
                            newdata.append(masks[i])
                            newdata.append(items[i * 2 + 1])
                            # app.logger.info(newdata)
                            errno = -5
                    else:
                        newdata.append('1')
                        newdata.append(masks[i])
                        newdata.append(items[i * 2 + 1])
                        errno = -7
                app.logger.info(newdata)
                session[Cartridge.DATA] = newdata
    else:  # Invalid cartridge id
        app.logger.info('Invalid cartridge id: ' +
                        session[Cartridge.CARTRIDGE_ID])
        errno = -4
        for i in range(Cartridge.ITEM_QTY):
            newdata.append('1')
            newdata.append('')  # mask
            newdata.append(items[i * 2 + 1])
        session[Cartridge.DATA] = newdata

    # writing to log file
    if (errno == 0):  # pass
        logdata = (cartridge_id, 'PASS', session[Cartridge.WORK_ORDER])
    else:
        logdata = (cartridge_id, 'FAIL', session[Cartridge.WORK_ORDER])

    tmpdata = session[Cartridge.DATA]
    for i in range(int(len(tmpdata) / 3)):
        logdata = logdata + (tmpdata[i * 3 + 2], )

    Log_file.write_file(configfile.cartridge_assembly_QC['LogFile'], logdata,
                        0)
    session[Cartridge.ERRORCODE] = errno
    app.logger.info("Go to home position")
    plc_ser.on_send('GB\r\n')
    app.logger.info('Redirecting page to cartridge-process')
    emit('redirect', url_for('cartridge_process'))
示例#10
0
def laser_connect():
    app.logger.info('Connected to Home client interface')
    plc_ser.on_send('H\r\n')
    emit('connect', 'Connected to Home api')