Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Python Flexport Serial Gage Adapter Seria Port Data Acquisition

Status
Not open for further replies.

Cbey

Programmer
Oct 29, 2008
4
US
This is a very rudimentary program in Python, which is for a specific piece of equipment. It is my hope, however that it will serve as a crude starting-point for others interested in data acquisition via serial port and certainly those who have the Midwest Flex Flexport gage interface for a Chicago Dial Indicator Gage who want to automate readings from the gage via the serial port.

Please feel free to improve upon the example provided and reply in this thread any recommendations you might have.

You'll notice the lack of short-cuts (some say eloquence), but I thought that by demonstrating each individual step, that would be most helpful to beginners.

Good Luck.

#data acquisition shell program in python
# by C.Bey
import serial
from time import sleep
from pylab import *

filename=raw_input("Please enter filename for the test: ")
name = filename+".txt"
print "Your new filename is ",name
rate = raw_input("Enter Sample Rate in Readings/second ")
rat = int(rate)
duration = raw_input("Enter Duration of Experiment in Minutes ")
duration = int(duration)
samples = (duration * 60)/rat
samples = int(samples)
print ("There will be a total of ", samples," readings.")
current_count = 0

f=open(name,"w")
f.write("Time in secs")
f.write(",")
f.write("null")
f.write(",")
f.write("Reading")
f.write(",")
f.write("unit")
f.write(",")
f.write("mode\n")
while current_count < samples:
current_count = current_count + 1
print "Reading ",current_count


sleep(rat)
ser=serial.Serial(0) #open serial port
print ser.portstr #check which port was really used
ser.write("R<CR>")
ser.write("R<LF>")
ser.write("!@R01") #Command to Flexport to take a reading
a=ser.read(5) #read 5 bytes
s=ser.read(10) #actual reading
b=ser.read(1) #comma
u=ser.read(5) #units of measure for reading
c=ser.read(3) #read 3 bytes
r=ser.read(2) #end of line and carriage return
ser.close() #p to be defined as int characters 6-15 from CDI
x=rat*current_count

count = current_count
count = str(count)

datapoint = s + u
datapoint = str(datapoint)
y = str(x)
f.write(y)
f.write(",")
f.write(s)
f.write(",")
f.write(u)
f.write("\n")
print y,datapoint


print "Measurements Completed.
 
Nice. Maybe it should be in the FAQ.

_________________
Bob Rashkin
 
My previous post contained some old code which wasn't revised to reflect the current format of the data.
The section below:

f=open(name,"w")
f.write("Time in secs")
f.write(",")
f.write("null")
f.write(",")
f.write("Reading")
f.write(",")
f.write("unit")
f.write(",")
f.write("mode\n")

Should be simply:
f=open(name,"w")
f.write("Time in secs")
f.write(",")
f.write("Reading")
f.write(",")
f.write("unit\n")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top