1 / 19

ECE 103 Engineering Programming Chapter 27 LabJack Introduction

ECE 103 Engineering Programming Chapter 27 LabJack Introduction. Herbert G. Mayer, PSU CS Status 7/30/2014 Initial content copied verbatim from ECE 103 material developed by Professor Phillip Wong @ PSU ECE. Syllabus. Company & Product Initial Setup LabJack Features LabJack Library ePut

tymon
Download Presentation

ECE 103 Engineering Programming Chapter 27 LabJack Introduction

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ECE 103 Engineering ProgrammingChapter 27LabJack Introduction Herbert G. Mayer, PSU CS Status 7/30/2014 Initial content copied verbatim from ECE 103 material developed by Professor Phillip Wong @ PSU ECE

  2. Syllabus • Company & Product • Initial Setup • LabJack Features • LabJack Library • ePut • eGet • Basic LabJack Commands

  3. Company & Product Company: LabJack Corp., 3232 S Vance St STE 100, Lakewood, CO 80227 Product name: LabJack Function: Affordable Multifunction DAQ with USB interface to computer Specific models: T7/T7, U3-LV/U3-HV, and U6/U6-Pro and more ECE 103 uses: U3-LV and U3-HV url: http://labjack.com U3 url: http://labjack.com/u3 LabJack FAQ: http://labjack.com/support/faq User Guide: http://labjack.com/support/u3/users-guide 2

  4. Company & Product Purpose: USB/Ethernet/WiFi based measurement and automation device, providing analog and digital inputs/outputs. Serves as inexpensive, easy interface between computers and physical world U3-LV spec: 12-bit ADC, 0 to 3.6 V U3-HV spec: 12-bit ADC, -10 to +20 V 3

  5. LabJack Features • Model U3-LV (Low Voltage) • 16 flexible I/O (digital input, digital output, or analog input) • Up to 16 12-bit analog inputs (0 → 2.4 V or 0 → 3.6 V, SE or Diff) • Maximum input stream rate of 2.5 → 50 kHz • 2 analog outputs (10-bit, 0-5 V, 16 Hz) • 4 additional digital I/O • Up to 2 timers (pulse timing, PWM output, quadrature input) • Up to 2 counters (32 bit each) • USB 2.0/1.1 interface → Connect to computer via USB cable • Windows, Linux, Mac drivers • Model U3-HV (High Voltage) • First 4 FIO are replaced by dedicated HV analog inputs • The HV inputs have ±10 V or -10/+20 V range 4

  6. Setting Up LabJack Driver software provides the low-level interface between the computer and the LabJack unit A programming library is included with the driver In the FAB 55-17, FAB 60-01, and EB 325 labs, the driver has already been installed on the computers Easiest to use the PSU pre-installed desk-tops, but can be installed on your private laptops too; just download the driver from the LabJack website and install it yourself 5

  7. Accessing LabJack Library LabJack comes with a library file that provides an API for controlling HW This library file must be added to any project’s search path: C:\Program Files\LabJack\Drivers\labjackud.lib This header file must be included in your source file: #include "C:\Program Files\LabJack\Drivers\LabJackUD.h” NOTES: The setup for using GCC+NetBeans is similar, though somewhat more complicated Spelling of library and include file slightly different! 6

  8. Setup Commands These setup commands must be placed at the start of any Visual C program that controls a LabJack unit Load the LabJack UD header file: #include "C:\Program Files\LabJack\Drivers\LabJackUD.h" Add an error handler function: See full programming guide for details. Add these two variable declarations to any C program using LabJack: LJ_ERROR ljError; LJ_HANDLE ljHandle = 0; 7

  9. Open & Configure Found U3 LabJack & Check Error READ LabJack web site: http://labjack.com/support/u3/users-guide/4.2.2/ LJ_ERROR _stdcall OpenLabJack ( long DeviceType, // low or high V long ConnectionType, // USB, WiFi . . . others const char *pAddress, // ID or SerNo of LJ long FirstFound, // if true, ignore others LJ_HANDLE *pHandle // provide address ); 8

  10. Open & Configure Found U3 LabJack & Check Error ljError = OpenLabJack( LJ_dtU3, LJ_ctUSB, "1", 1, & ljHandle ); ljHandleis the unique ID# assigned to the found LabJack Set LabJack to factory default condition: ljError= ePut( ljHandle, LJ_ioPIN_CONFIGURATION_RESET, 0, 0, 0 ); All FIO/EIO set to digital input, DAC set to 0 V, timers & counters disabled Check error status of each issued LabJack command: ErrorHandler( ljError, __LINE__ ); If no error, then this function does nothing; else, it displays relevant error message (Use this after each LabJack command that returns an error code.) 9

  11. ePut() – Write data to an I/O channel, e  easy LJ_ERRORePut( LJ_HANDLE Handle, long IOType, long Channel, double Value, // these are the data to be written! long x1 ); Parameters: Handle : Handle returned by OpenLabJack() IOType : Type of I/O request (macro defined in LabJack header) Channel : Channel (bit) number of the particular IOType Value : Contains the data value to be written to the channel x1 : Optional parameter used by some IOTypes; set to 0 Returns: Error code, 0 meaning no error 10

  12. eGet() – Read data from an I/O channel LJ_ERROReGet( LJ_HANDLE Handle, long IOType, long Channel, double * pValue, // these are the data being read long x1 ); Parameters: Handle : Handle returned by OpenLabJack() IOType : The type of request (macros defined in LabJack header) Channel : The channel (bit) number of the particular IOType pValue : Pointer to Value that receives the data x1 : Optional parameter used by some IOTypes Returns: Error code 11

  13. Table of bit numbers/channels: 12

  14. Digital Output Syntax for writing to a digital channel( FIO/EIO/CIO ): ljError = ePut( ljHandle, LJ_ioPUT_DIGITAL_BIT, Bit#, OutState, 0 ); OutState is the desired output state: 0 (logic low) or 1 (logic high) Example: % Output a logic ‘High’ (1) on FIO5 ljError = ePut( ljHandle, LJ_ioPUT_DIGITAL_BIT, 5, 1, 0 ); Example: % Output a logic ‘Low’ (0) on FIO5 state = 0; ljError = ePut( ljHandle, LJ_ioPUT_DIGITAL_BIT, 5, state, 0 ); // note: state == 0 == low 13

  15. Digital Input Syntax for reading from a digital channel (FIO/EIO/CIO): ljError = eGet( ljHandle, LJ_ioGET_DIGITAL_BIT, Bit#, &InState, 0 ); After this command, variable InStateholds either 0 (logic low) or 1 (logic high) as measured by the channel Example: % Read the logic state on FIO5 and save it to variable “InState” ljError = eGet( ljHandle, LJ_ioGET_DIGITAL_BIT, 5, &InState, 0 ); // now InState is assigned 14

  16. Analog Output Syntax for writing to an analog channel (DAC): ljError = ePut( ljHandle, LJ_ioPUT_DAC, DAC#, Volt_value, 0 ); DAC# is the desired DAC channel: 0 (DAC0) or 1 (DAC1) Volt_value is the desired DAC output voltage: 0 to 5 Example: // Generate 2.5V on DAC0 channel ljError = ePut( ljHandle, LJ_ioPUT_DAC, 0, 2.5, 0 ); 15

  17. Analog Input Syntax to enable/disable an FIO channel for analog input (FIO/EIO/AIN): ljError = ePut( ljHandle, LJ_ioPUT_ANALOG_ENABLE_BIT, Bit#, ENA, 0 ); ENA is the desired state: 0 (disable) or 1 (enable) When analog is disabled, the channel reverts back to digital I/O Syntax for reading from an analog channel: ljError = eGet( ljHandle, LJ_ioGET_AIN, Bit#, &Value, 0 ); After this command, Value holds the voltage measured by the FIO4 channel. Example: // Read the analog voltage on FIO4 and assign the value to variable “AIN_volt” ljError = ePut( ljHandle, LJ_ioPUT_ANALOG_ENABLE_BIT, 4, 1, 0 ); ljError = eGet( ljHandle, LJ_ioGET_AIN, 4, &AIN_volt, 0 ); 16

  18. Example: #include <stdio.h> #include "C:\Program Files\LabJack\Drivers\LabJackUD.h" /* Note: Calls to ErrorHandler omitted in this sample code */ int main( void ) { // main LJ_ERROR ljError; /* LabJack error code */ LJ_HANDLE ljHandle = 0; /* ID# assigned to the opened LabJack */ double WriteVal, ReadVal;/* I/O values */ /* Open the first found LabJack U3 */ ljError = OpenLabJack( LJ_dtU3, LJ_ctUSB, "1", 1, & ljHandle ); // here you’d need to check for error condition: if ( ljError ) { . . . /* Set all pin assignments to the factory default condition */ ljError = ePut( ljHandle, LJ_ioPIN_CONFIGURATION_RESET, 0, 0, 0 ); /* Prompt user for FIO4 output value */ printf( "Enter desired FIO4 setting ( 1 for high and 0 for low ): ”); scanf( "%lf", & WriteVal ); /* Write FIO4 value */ ljError = ePut( ljHandle, LJ_ioPUT_DIGITAL_BIT, 4, WriteVal, 0 ); /* Read FIO5 value (assume a wire is connected between FIO4 and FIO5) */ ljError = eGet( ljHandle, LJ_ioGET_DIGITAL_BIT, 5, & ReadVal, 0 ); printf( "FIO5 value = %g\n", ReadVal ); return 0; } //end main 17

  19. For More Detailed Information Available on the course website (LabJack page): LJ_Programming_Guide_MSVS_v1.5.pdf LJ_Programming_Guide_GCC_NetBeans_v1.5.pdf 18

More Related