ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

NIDAQmx wrapper problems

I am currently trying to drive a NI USB-6009 device via Java but when I run my program nothing happens so I wonder if someone here could help me. Everything in my code is based on the examples given by NI.
 
The java side of my program:
 

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

__cplusplus

extern

"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.

0 Kudos
Message 1 of 3
(3,219 Views)
I pasted the wrong version of my C code and I can't edit, so in the actual version UpdateVoltage have replaced EnvoiDigSignal.
0 Kudos
Message 2 of 3
(3,215 Views)
Ok I found the problem, at least I think so. I think it was a problem with DAQmxCreateAOVoltageChan function and more pricely the voltage range of -10,10 I was entering. I think that was a too big range for my NIDAQ card, now I have put it down to 0,5 it is working fine.
0 Kudos
Message 3 of 3
(3,209 Views)