07-24-2007 09:46 AM
public
class UpdateVoltage{private native void UpdateVoltage();
static {
System.load("C:/Documents and Settings/AntoineG/My Documents/Java/Projects/DataAcquisition/src/libTest2.dll");
}
public static void main(String[] args) {
new UpdateVoltage();
}
}
The C-code side of my program (which generates libTest2.dll)
/*********************************************************************
*
* ANSI C Example program:
* WriteDigChan.c
*
* Example Category:
* DO
*
* Description:
* This example demonstrates how to write values to a digital
* output channel.
*
* Instructions for Running:
* 1. Select the digital lines on the DAQ device to be written.
* 2. Select a value to write.
* Note: The array is sized for 8 lines, if using a different
* amount of lines, change the number of elements in the
* array to equal the number of lines chosen.
*
* Steps:
* 1. Create a task.
* 2. Create a Digital Output channel. Use one channel for all
* lines.
* 3. Call the Start function to start the task.
* 4. Write the digital Boolean array data. This write function
* writes a single sample of digital data on demand, so no
* timeout is necessary.
* 5. Call the Clear Task function to clear the Task.
* 6. Display an error if any.
*
* I/O Connections Overview:
* Make sure your signal output terminals match the Lines I/O
* Control. In this case wire the item to receive the signal to the
* first eight digital lines on your DAQ Device.
*
*********************************************************************/
/*============================================================================*/
/* National Instruments / Data Acquisition */
/*----------------------------------------------------------------------------*/
/* Copyright (c) National Instruments 2003. All Rights Reserved. */
/*----------------------------------------------------------------------------*/
/* */
/* Title: NIDAQmx.h */
/* Purpose: Include file for NI-DAQmx library support. */
/* */
/*============================================================================*/
#include
<stdio.h>/* DO NOT EDIT THIS FILE - it is machine generated */
#include
"jni.h"#include
"NIDAQmx.h"#pragma
comment(lib,"NIDAQmx.lib")/* Header for class EnvoiDigSignal */
#ifndef
_Included_EnvoiDigSignal#define
_Included_EnvoiDigSignal#ifdef
__cplusplusextern
"C" {#endif
/*
* Class: EnvoiDigSignal
* Method: EnvoiDigSignal
* Signature: (Ljava/lang/String;[I)V
*/
JNIEXPORT
void JNICALL Java_EnvoiDigSignal_EnvoiDigSignal(JNIEnv *, jobject);#ifdef
__cplusplus}
#endif
#endif
JNIEXPORT
void JNICALL Java_EnvoiDigSignal_EnvoiDigSignal(JNIEnv *env, jobject obj){
int32 error=0;
TaskHandle taskHandle=0;
float64 data[1] = {1.0};
char errBuff[2048]={'\0'}; /*********************************************/ // DAQmx Configure Code /*********************************************/DAQmxCreateTask(
"",&taskHandle);DAQmxCreateAOVoltageChan(taskHandle,
"Dev1/ao0","",-10.0,10.0,DAQmx_Val_Volts,""); /*********************************************/ // DAQmx Start Code /*********************************************/DAQmxStartTask(taskHandle);
/*********************************************/ // DAQmx Write Code /*********************************************/DAQmxWriteAnalogF64(taskHandle,1,1,10.0,DAQmx_Val_GroupByChannel,data,NULL,NULL);
}
I've checked, my device name is Dev1 and I am looking at a voltage from the AO0.
07-24-2007 10:02 AM
07-24-2007 10:46 AM