Skip to content

Commit

Permalink
Merge branch 'PlanetInnovation-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
davelopez01 committed Oct 13, 2016
2 parents 3f585a8 + 0b0fcd1 commit 4dedad1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 35 deletions.
62 changes: 31 additions & 31 deletions Examples/outputSinDAC.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# we can update the DAC. Update intervals faster than 5 ms may give weird
# results because of the large percentage of missed updates.
#
# Note: This example uses signal.setitimer() and signal.alarm(), and therefore
# Note: This example uses signal.setitimer() and signal.alarm(), and therefore
# requires Python 2.6 on Unix to run. See:
# http://docs.python.org/library/signal.html#signal.setitimer
# http://docs.python.org/library/signal.html#signal.alarm
Expand All @@ -30,84 +30,84 @@
FREQUENCY = 10

if __name__ == '__main__':
print "This program will attempt to generate a sine wave with a frequency of %s Hz, updating once every %s seconds." % (FREQUENCY, UPDATE_INTERVAL)
print "Opening LabJack...",
print("This program will attempt to generate a sine wave with a frequency of %s Hz, updating once every %s seconds." % (FREQUENCY, UPDATE_INTERVAL))


print("Opening LabJack...",)
# Open up our LabJack
d = u3.U3()
#d = u6.U6()
#d = ue9.UE9()
print "Done"

print("Done")

# Make a class to keep track of variables and the like
class DacSetter(object):
def __init__(self, frequency, updateInterval):
self.count = 0
self.dac = 0
self.setDacCount = 0
self.go = True

# Points between peaks (pbp)
pbp = (float(1)/frequency)/updateInterval

# Figure out how many degrees per update we need to go.
self.step = float(360)/pbp

# Stupid sin function only takes radians... but I think in degrees.
self.degToRad = ( (2*math.pi) / 360 )

def setDac(self):
# calculate the value to put in the sin
value = (self.setDacCount * self.step) * self.degToRad

# Writes the dac.
self.dac = d.writeRegister(5000, 2.5+2*math.sin(value))

# Count measures how many successful updates occurred.
self.count += 1

# Lower the go flag
self.go = False

def handleSetDac(self, signum, frame):
# This function gets called every UPDATE_INTERVAL seconds.

# Raise the go flag.
self.go = True

# setDacCount measures how many times the timer went off.
self.setDacCount += 1

# Create our DacSetter
dacs = DacSetter(FREQUENCY, UPDATE_INTERVAL)

# Set up the signals
signal.signal(signal.SIGALRM, dacs.handleSetDac)
signal.setitimer(signal.ITIMER_REAL, UPDATE_INTERVAL, UPDATE_INTERVAL)

# Run for ~10 seconds. Expect about 2 extra seconds of overhead.
signalcount = int(10/UPDATE_INTERVAL)

# Print the current time, just to let you know something is happening.
print "Start:", datetime.now()
print("Start:", datetime.now())

for i in range(signalcount):
# Wait for signal to be received
signal.pause()

# If the dacs flag is set, set the dac.
if dacs.go:
dacs.setDac()

# Print the stop time, in case you wanted to know.
print "Stop:", datetime.now()
print("Stop:", datetime.now())

# Done with the timer, let's turn it off.
signal.setitimer(signal.ITIMER_REAL, 0)

# Print short summary of the difference between how may updates were
# expected and how many occurred.
print "# of Updates = %s, # of signals = %s" % (dacs.count, dacs.setDacCount)
print "The closer the number of updates is to the number of signals, the better your waveform will be."
print("# of Updates = %s, # of signals = %s" % (dacs.count, dacs.setDacCount))
print("The closer the number of updates is to the number of signals, the better your waveform will be.")
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[bdist_wheel]
universal = 1
13 changes: 9 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import sys
from distutils.core import setup
from setuptools import setup

if sys.version_info[:2] < (2, 5) or sys.version_info[0] > 2:
msg = ("LabJackPython requires Python 2.5 or later but does not work on "
"any version of Python 3. You are using version %s. Please "
if sys.version_info[:2] < (2, 6):
msg = ("LabJackPython requires Python 2.6 or later. "
"You are using version %s. Please "
"install using a supported version." % sys.version)
sys.stderr.write(msg)
sys.exit(1)
Expand All @@ -21,6 +21,11 @@
'Programming Language :: Python :: 2.5',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Topic :: Software Development',
'Topic :: Software Development :: Embedded Systems',
'Topic :: System :: Hardware'
Expand Down

0 comments on commit 4dedad1

Please sign in to comment.