Example #1
0
def SubmitWeight(workOrderNumber, weight, testingMode):
    """submit weight to web api"""
    # make some fake apiResult data if we're testing
    if (testingMode):
        result = ApiResponse(200, "everything is awesome!")
        return result

    try:
        h = httplib2.Http('.cache')

        url = 'http://incomtek3-test/api/partWeights/records/scale/' + workOrderNumber + "/" + weight
        
        response, content = h.request(url, "POST", headers={'content-length':'0'} )
    
        responseStatus = response.status
        data = content.decode("utf-8")  # convert byte to string

        result = ApiResponse(responseStatus, data)
        return result

    except Exception as e:
        import LcdStuff as lcd
        lcd.setText(e.args[0])
        import LedConfig as leds
        leds.blinkNoGoLeds()
    finally:
        pass
Example #2
0
def SubmitWeight(workOrderNumber, weight, testingMode):
    """submit weight to web api"""
    # make some fake apiResult data if we're testing
    if (testingMode):
        pass
        #result = ApiResponse(200, "everything is awesome!")
        #return result

    try:
        h = httplib2.Http('.cache')

        url = 'http://incomtek3/api/partWeights/records/scale/' + workOrderNumber + "/" + weight

        response, content = h.request(url,
                                      "POST",
                                      headers={'content-length': '0'})

        responseStatus = response.status
        data = content.decode("utf-8")  # convert byte to string

        result = ApiResponse(responseStatus, data)
        return result

    except Exception as e:
        import LcdStuff as lcd
        # lcd.setText(e.args[0])
        lcd.setText("There was an error sending the weight")
        import LedConfig as leds
        leds.blinkNoGoLeds()
    finally:
        pass
Example #3
0
def exitPiScale(args):
    global time_stamp
    a = False
    b = False
    c = False

    x = 0
    while (btns.btnExit.state == GPIO.HIGH):
        time.sleep(0.1)
        x = x + 0.1
        if (x < 5):
            if (a == False):
                lcd.setText("release button to", "resume part weight",
                            "continue to hold for", "more options")
                a = True
        if (x >= 5 and x < 10):
            if (b == False):
                a = False
                lcd.setText("release button to", "restart",
                            "continue to hold for", "more options")
                b = True

        if (x >= 10 and x < 15):
            if (c == False):
                b = False
                lcd.setText("release button to", "shutdown",
                            "continue to hold for", "more options")
                c = True
        if (x >= 15):
            lcd.setText("system ready", "  ", "You can release",
                        "the button now!")
            a = True
            b = False
            c = False

    if (a):
        lcd.setText("system ready")
    else:
        if (b):
            lcd.setText("rebooting")
            GPIO.cleanup()
            reboot()
        if (c):
            lcd.setText("shutting down...")
            halt()
Example #4
0
            halt()


def reboot():
    import os
    os.system("sudo reboot now")


def halt():
    import os
    os.system("sudo halt now")


# setup the button to exit
# when a rising edge is detected on the Exit button pin, regardless of whatever
# else is happening in the program, the exitPiScale function will be called
GPIO.add_event_detect(btns.btnExit.pin,
                      GPIO.RISING,
                      callback=exitPiScale,
                      bouncetime=150)

try:
    lcd.setText("PiScale started, ", "waiting for data", "", "")
    leds.statusLed.turnOn()

except Exception as e:
    lcd.setText(e)

finally:
    pass
Example #5
0
def getData(testingMode):
    try:
        #data = ser.readline()
        if (testingMode == True and btns.btnSimData.state == GPIO.HIGH):
           data = getTestData()
           result = data
        else:
           data = ser.readline()
           
           try:
               result = data.decode(encoding='UTF-8')
           except:
               result = ""       
 
        # result should be a string something like 00199387   0.186KG
        # length should be exactly 18
        length = len(result)


        pw = pwr(False, "", "", False, "no data")
        
        if (length == 0): return pw

        if (length > 0):
            pw.hasData = True
            

            if (length == 22 or length == 29):
                pw.success = True
                #work order number is the first 8 chars
                result = remove_control_characters(result)
                if (length == 22):
                    pw.workOrderNumber = result[:9].strip()
                else:
                    pw.workOrderNumber = result[:16].strip()

                print(pw.workOrderNumber)
                # weight is the last 11 (or so) chars
                pw.weight = result[-11:].strip()
                print(pw.weight)

                uom = pw.weight[-2:]    # get the UoM, it must bt LG
                uom2 = pw.weight[-3:]    # get the UoM, it must bt LG
                # for some reason, the scale in now returning "LN" as the lbs uom - Jun 06 2016
                if (uom == "LG" or uom2 == "LGM" or uom == "LN" or uom2 == "LNM"):
                    print("good UoM")
                    print(uom)
                    pass
                else:
                    pw.success = False
                    pw.msg = "Invalid U of M"
                    print(uom)
                    return pw

                pw.weight = pw.weight[:-2] # get rid of the letters at the end

                if (pw.weight == "0.000"):
                    pw.success = False
                    pw.msg = "A zero weight was found, ensure item is on scale"

            else:
                pw.success = False
                pw.msg = "An invalid number of characters was read from the scale"
                pw.workOrderNumber = ""
                pw.weight = "-1"

        return pw

    except Exception as e:
        error = e.args[0]
        error2 = e.args[1]
        lcd.setText(error, error2)
Example #6
0
def displayWoAndWeight(workOrderNumber, weight):
    lcd.setText("Work Order:", workOrderNumber, "Weight:", weight)
Example #7
0
def alert(msg1, msg2 = "", msg3 = ""):
    lcd.setText(msg1, msg2, msg3, pressAckMsg)
    leds.blinkNoGoLeds()
    lcd.setText(readyText)
Example #8
0
def alert(msg1, msg2 = "", msg3 = ""):
    lcd.setText(msg1, msg2, msg3, pressAckMsg)
    leds.blinkNoGoLeds()
    lcd.setText(readyText)

try:
    while (True):   
        #exit by pressing the Exit button
        # .getData returns the PartWeightResult object
        pw = mySerial.getData(testingMode)

        # no data from scale, keep on truckin' 
        if (pw.hasData == False): continue
    
        lcd.addTextToBottom("Received data:")

        # Data from scale
        # data is good
        if (pw.success):
            #leds.goLed.turnOn()
            lcd.clearText()
            lcd.addTextToBottom("WO: " + pw.workOrderNumber)
            lcd.addTextToBottom("Weight: " + pw.weight)
            
            # send data to webApi and get the result
            lcd.addTextToBottom("Submitting data...", True)
            
            apiResult = webApi.SubmitWeight(pw.workOrderNumber, pw.weight, testingMode)

            # some error occured, but it was (probably already handled, 
Example #9
0
def getData(testingMode):
    try:
        #data = ser.readline()
        if (testingMode == True and btns.btnSimData.state == GPIO.HIGH):
            data = getTestData()
            result = data
        else:
            data = ser.readline()

            try:
                result = data.decode(encoding='UTF-8')
            except:
                result = ""

        # result should be a string something like 00199387   0.186KG
        # length should be exactly 18
        length = len(result)

        pw = pwr(False, "", "", False, "no data")

        if (length == 0): return pw

        if (length > 0):
            pw.hasData = True

            if (length == 22 or length == 29):
                pw.success = True
                #work order number is the first 8 chars
                result = remove_control_characters(result)
                if (length == 22):
                    pw.workOrderNumber = result[:9].strip()
                else:
                    pw.workOrderNumber = result[:16].strip()

                print(pw.workOrderNumber)
                # weight is the last 11 (or so) chars
                pw.weight = result[-11:].strip()
                print(pw.weight)

                uom = pw.weight[-2:]  # get the UoM, it must bt LG
                uom2 = pw.weight[-3:]  # get the UoM, it must bt LG
                # for some reason, the scale in now returning "LN" as the lbs uom - Jun 06 2016
                if (uom == "LG" or uom2 == "LGM" or uom == "LN"
                        or uom2 == "LNM"):
                    print("good UoM")
                    print(uom)
                    pass
                else:
                    pw.success = False
                    pw.msg = "Invalid U of M"
                    print(uom)
                    return pw

                pw.weight = pw.weight[:-2]  # get rid of the letters at the end

                if (pw.weight == "0.000"):
                    pw.success = False
                    pw.msg = "A zero weight was found, ensure item is on scale"

            else:
                pw.success = False
                pw.msg = "An invalid number of characters was read from the scale"
                pw.workOrderNumber = ""
                pw.weight = "-1"

        return pw

    except Exception as e:
        error = e.args[0]
        error2 = e.args[1]
        lcd.setText(error, error2)
Example #10
0
def displayWoAndWeight(workOrderNumber, weight):
    lcd.setText("Work Order:", workOrderNumber, "Weight:", weight)
Example #11
0
def exitPiScale(args):
    global time_stamp
    a=False
    b=False
    c=False

    x=0
    while(btns.btnExit.state == GPIO.HIGH):
        time.sleep(0.1)
        x = x + 0.1
        if (x < 5):
            if (a== False):
                lcd.setText("release button to", "resume part weight", "continue to hold for", "more options")
                a = True
        if (x >= 5 and x < 10): 
            if (b == False):
                a = False
                lcd.setText("release button to", "restart", "continue to hold for", "more options")
                b = True

        if (x >= 10 and x < 15):
            if (c == False):
                b = False
                lcd.setText("release button to", "shutdown", "continue to hold for", "more options")
                c = True
        if (x >= 15):
            lcd.setText("system ready", "  ",  "You can release", "the button now!")
            a = True
            b = False
            c = False           

    if (a): 
        lcd.setText("system ready")
    else:
        if (b): 
            lcd.setText("rebooting")
            GPIO.cleanup()
            reboot()
        if (c): 
            lcd.setText("shutting down...")
            halt()
Example #12
0
            reboot()
        if (c): 
            lcd.setText("shutting down...")
            halt()


def reboot():
    import os
    os.system("sudo reboot now")

def halt():
    import os
    os.system("sudo halt now")


# setup the button to exit
# when a rising edge is detected on the Exit button pin, regardless of whatever   
# else is happening in the program, the exitPiScale function will be called
GPIO.add_event_detect(btns.btnExit.pin, GPIO.RISING, callback=exitPiScale, bouncetime=150)  

    
try:
    lcd.setText("PiScale started, ", "waiting for data", "", "")
    leds.statusLed.turnOn()

except Exception as e:
    lcd.setText(e)

finally:
    pass
Example #13
0
def alert(msg1, msg2="", msg3=""):
    lcd.setText(msg1, msg2, msg3, pressAckMsg)
    leds.blinkNoGoLeds()
    lcd.setText(readyText)
Example #14
0
def alert(msg1, msg2="", msg3=""):
    lcd.setText(msg1, msg2, msg3, pressAckMsg)
    leds.blinkNoGoLeds()
    lcd.setText(readyText)


try:
    while (True):
        #exit by pressing the Exit button
        # .getData returns the PartWeightResult object
        pw = mySerial.getData(testingMode)

        # no data from scale, keep on truckin'
        if (pw.hasData == False): continue

        lcd.addTextToBottom("Received data:")

        # Data from scale
        # data is good
        if (pw.success):
            #leds.goLed.turnOn()
            lcd.clearText()
            lcd.addTextToBottom("WO: " + pw.workOrderNumber)
            lcd.addTextToBottom("Weight: " + pw.weight)

            # send data to webApi and get the result
            lcd.addTextToBottom("Submitting data...", True)

            apiResult = webApi.SubmitWeight(pw.workOrderNumber, pw.weight,
                                            testingMode)