" WindowsDriverSample.py
" Author: LabJack Corporation
"
"
" This driver shows some of the basic functions 
" of the LabJackPython driver.
"""

#The LabJackPython.pyc file should be in the Python\Lib directory
from LabJackPython import LabJackPython

try:
    if __name__ == "__main__":

        #Open a UE9 over usb with the first found flag.
        ue9Handle = LabJackPython.OpenLabJack(LabJackPython.LJ_dtUE9,
                                              LabJackPython.LJ_ctUSB, "0", 1)

        #Get Channel 0
        ain0 = LabJackPython.eGet(ue9Handle, LabJackPython.LJ_ioGET_AIN, 0, 0,
                                  0)
        print "eGet AIN0:" + str(ain0)

        #Add request to get channel 0
        LabJackPython.AddRequest(ue9Handle, LabJackPython.LJ_ioGET_AIN, 0, 0.0,
                                 0, 0.0)
        LabJackPython.Go()
        ain0 = LabJackPython.GetResult(ue9Handle, LabJackPython.LJ_ioGET_AIN,
                                       0)
        print "addRequest AIN0:" + str(ain0)

except Exception, e:
        LabJackPython.AddRequest(deviceHandle, LabJackPython.LJ_ioADD_STREAM_CHANNEL, 2, 0, 0, 0)
        LabJackPython.AddRequest(deviceHandle, LabJackPython.LJ_ioADD_STREAM_CHANNEL, 3, 0, 0, 0)

        #Apply the requests prior to starting streaming.
        LabJackPython.GoOne(deviceHandle)
        
        #Get all the Results until an exception is thrown
        try: 
            rIOType, rChannel, rValue, rxValue, rudValue = LabJackPython.GetFirstResult(deviceHandle)
            while (True):
                rIOType, rChannel, rValue, rxValue, rudValue = LabJackPython.GetNextResult(deviceHandle)
        except LabJackException, lje:
            print "Recieved Exception:" + str(lje)
        
        #Start the Stream
        actualScanRate = LabJackPython.eGet(deviceHandle, LabJackPython.LJ_ioSTART_STREAM, 0, 0, 0)
        
        #Since the actual scan rate is based on how the desired
        #scan rate divides into the LabJack's clock
        #the actual scan rate is returned in eGet's pValue parameter 
        #which is the return parameter of eGet.
        print "Scanrate " + str(scanrate) + " requested."
        print "Stream started running with " + str(actualScanRate) + " scanrate."
        
        #Read 10 Scans
        while not msvcrt.kbhit():            
            
            try:
                print "Iteration Number:" + str(numReads)
                numReads += 1
                #Must set the number of scans to read each iteration, as the read
Example #3
0
from LabJackPython import LabJackPython

try:
    if __name__ == "__main__":

        #Create a simple comm config packet to
        #read all data from the UE9
        sendBuffer = [0] * 38

        sendBuffer[0] = 0x89
        sendBuffer[1] = 0x78
        sendBuffer[2] = 0x10
        sendBuffer[3] = 0x01

        #Open a UE9 over usb with the first found flag.
        ue9Handle = LabJackPython.OpenLabJack(LabJackPython.LJ_dtUE9,
                                              LabJackPython.LJ_ctUSB, "0", 1)

        #Write a command to get the version numbers from the UE9
        LabJackPython.Write(ue9Handle, sendBuffer, len(sendBuffer))

        numBytes, rcvBuffer = LabJackPython.Read(ue9Handle, False, 38)

        localID = int(rcvBuffer[8])
        ipAddress = str(int(rcvBuffer[13])) + "." + str(int(
            rcvBuffer[12])) + "." + str(int(rcvBuffer[11])) + "." + str(
                int(rcvBuffer[10]))
        gateway = str(int(rcvBuffer[17])) + "." + str(int(
            rcvBuffer[16])) + "." + str(int(rcvBuffer[15])) + "." + str(
                int(rcvBuffer[14]))
        subnet = str(int(rcvBuffer[21])) + "." + str(int(
            rcvBuffer[20])) + "." + str(int(rcvBuffer[19])) + "." + str(
" WindowsDriverSample.py
" Author: LabJack Corporation
"
"
" This driver shows some of the basic functions 
" of the LabJackPython driver.
"""

#The LabJackPython.pyc file should be in the Python\Lib directory
from LabJackPython import LabJackPython

try:
    if __name__ == "__main__":
        
        #Open a UE9 over usb with the first found flag.
        ue9Handle = LabJackPython.OpenLabJack(LabJackPython.LJ_dtUE9, LabJackPython.LJ_ctUSB, "0", 1)
        
        #Get Channel 0
        ain0 = LabJackPython.eGet(ue9Handle, LabJackPython.LJ_ioGET_AIN, 0, 0, 0)
        print "eGet AIN0:" + str(ain0)

        #Add request to get channel 0
        LabJackPython.AddRequest(ue9Handle,LabJackPython.LJ_ioGET_AIN, 0, 0.0, 0, 0.0)
        LabJackPython.Go()
        ain0 = LabJackPython.GetResult(ue9Handle, LabJackPython.LJ_ioGET_AIN, 0)
        print "addRequest AIN0:" + str(ain0)
        
except Exception, e: 
    print "Exception:" + str(e)
    
    
#The LabJackPython.pyc file should be in the Python\Lib directory
from LabJackPython import LabJackPython
from LabJackPython import LabJackException
import msvcrt

try:
    if __name__ == "__main__":

        scanrate = 100
        done = False
        numReads = 0

        #Open a UE9 over usb with the first found flag.
        #Comment out if using a U3
        deviceHandle = LabJackPython.OpenLabJack(LabJackPython.LJ_dtUE9,
                                                 LabJackPython.LJ_ctUSB, "1",
                                                 1)

        #FOR U3 ONLY Uncomment if using a U3
        #Open the U3 Device
        #deviceHandle = LabJackPython.OpenLabJack(LabJackPython.LJ_dtU3, LabJackPython.LJ_ctUSB, "1", 1)
        #Set FIO 2 and 3 as Analog Inputs
        #LabJackPython.ePut(deviceHandle, LabJackPython.LJ_ioPUT_ANALOG_ENABLE_BIT, 3, 1, 0)
        #LabJackPython.ePut(deviceHandle, LabJackPython.LJ_ioPUT_ANALOG_ENABLE_BIT, 2, 1, 0)

        #Configure the Stream Mode:
        #Configure all analog inputs for 12-bit resolution
        LabJackPython.AddRequest(deviceHandle, LabJackPython.LJ_ioPUT_CONFIG,
                                 LabJackPython.LJ_chAIN_RESOLUTION, 12, 0, 0)

        #Configure the analog input range on channel 0 for bipolar +-5 volts.