Keyboard Wedge & Python, Perfect Match
Python & KeyBoard Wedge?
Let’s explore how powerful Keyboard Wedge technology can be. A Keyboard Wedge is a device that emulates a keyboard to input data into a computer. Although it sounds pretty simple, it opens up a world of opportunities, such as creating a Python program to analyze your gage data in real-time. We will use Python and our GageWay KW to take data from a caliper and process it in real-time. We’ll set a lower tolerance and an upper tolerance for our feature and have the program display a message when we end up out of that tolerance range. You only need limited python experience to build a program that can interact with a gage when using our Keyboard Wedge Technology. In this program, we’re using a few built-in functions, such as input, print, and a while loop. A while loop will continue to run until a condition is met; in our case, that is when we are outside the tolerance range. Let’s get to it.
Setting Up Variables
First thing to do is set you gage variable and tolerances.
gage_reading = float(input(“Take your first gage reading when ready. \n”))
feature_lower_tolerance = 2.25
feature_upper_tolerance = 3.25
While Loop
This is a very approchable while loop. We’re telling the program to keep looking for gage readings until we go either above or below the tolerances we just set. Note: this loop will run for forever unless a gage reading is above or below the tolerance, you can build in other conditions to break out of the loop but that is for another day.
while feature_lower_tolerance < gage_reading < feature_upper_tolerance:
gage_reading = float(input())
Print Functions
Here we are notifying the user that our gage reading was either above or below the tolerance. We’re using conditional logic to change our message based on the gage reading. One message for above the tolerance and another for below. Finally we print the final gage reading that was outside the tolerance.
if gage_reading < feature_lower_tolerance:
print(f”Gage reading is below lower tolerance of {feature_lower_tolerance}”)
else:
print(f”Gage reading is above upper tolerance of {feature_upper_tolerance}”)
print(f”Final gage reading {gage_reading}”)
There you have it, a Python program that analyzes your gage data!
Running the Program
Let’s run the program in cmd/Terminal. You’ll need to navigate to the directory with your program and fire it up! Here you will take your gage readings, as many as you would like and it will terminate and print the messages once your gage reading is above of below the tolerance.