×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Python Flexport Serial Gage Adapter Seria Port Data Acquisition

Python Flexport Serial Gage Adapter Seria Port Data Acquisition

Python Flexport Serial Gage Adapter Seria Port Data Acquisition

(OP)
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. "

RE: Python Flexport Serial Gage Adapter Seria Port Data Acquisition

Nice.  Maybe it should be in the FAQ.

_________________
Bob Rashkin

RE: Python Flexport Serial Gage Adapter Seria Port Data Acquisition

(OP)
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")
   

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close