Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

I want to programming USB-6009 with Delphi but....

Hello,
 
I have a USB-6009. I installed nidaqmx 8.0 and I downloaded http://digital.ni.com/public.nsf/websearch/A6715AA42405ACD786256F0A00633B8F?OpenDocument this link with attacments unit nidaqmx_80_delphi.zip". 
I use Delphi 7.0 to build an application with this NI hardware. When error, click to button1. Error message is "Access violation at address 000003E8. Read of address 000003E8."
 
Have you any idea?
 
Best regard.
 
Onur.
 
==========
Code is...
===========
uses
  ......,nidaqmx, NIDAQmxCAPI_TLB;
 
procedure TForm1.Button1Click(Sender: TObject);
const
  DAQmx_Val_Rising = $00002828;
  DAQmx_Val_FiniteSamps = 10178;
type
  int8 = Shortint;
type
  PUINT8 = ^UINT8;
  uInt8 = Byte;
type
  PINT16 = ^int16;
  int16 = SmallInt;
type
  uInt16 = Word;
type
  PINT32 = ^INT32;
  int32 = LongInt;
type
  PUINT32 = ^UINT32;
  uInt32 = LongInt;
type
  float32 = Single;
type
  pfloat64 = ^float64;
  float64 = Double;
  __INT64 = int64;
  uInt64 =  __INT64;
  PBOOL32 = ^BOOL32;
  bool32 = UINT32;
var
  TaskHandle: PLongint;
  error: Longint;
  read: Longint;
  data: PDouble;
  errBuff: Pchar;
  i: byte;
begin
  // DAQmx Configure Code
  error := DAQmxCreateTask('', @taskHandle);
  error := DAQmxCreateAIVoltageChan(taskHandle^,'Dev1/ai1','',DAQmx_Cfg_Default(-1),-10.0,10.0,DAQmxVoltageUnits2(0),nil);
  error := DAQmxCfgSampClkTiming(taskHandle^,'',10000.0,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,1000);
  // DAQmx Start Code
  error := DAQmxStartTask(taskHandle^);
  // DAQmx Read Code
  error := DAQmxReadAnalogF64(taskHandle^,1000,10.0,DAQmx_Val_GroupByChannel,data,1000,@read,nil);
  Memo1.Lines.Add(intTOstr(read));
  // DAQmx Stop Code
  if( taskHandle^<>0 ) then
  begin
  DAQmxStopTask(taskHandle^);
  DAQmxClearTask(taskHandle^);
  end;
end;
0 Kudos
Message 1 of 17
(7,467 Views)

Hi Onur,

As it says in the KnowledgeBase article you referenced, National Instruments doesn't officially support Borland Delphi in the NI-DAQmx driver.  However, I'd be very interested to know if you get those wrapper functions to work.  Has anyone out there had any experience using them that could offer some insight?

Thanks,

Justin M.
National Instruments

 

0 Kudos
Message 2 of 17
(7,420 Views)
Function TTestBox.ReadADC( Channel : Integer; ADCMode : Shortint) : extended;
var
  hdl           : Integer;
  data, ModeNew : Double;
  ret           : LongInt;
  channelstr    : string;
  channelpchar  : pansichar;
  Value, Mode   : i16;
begin
  if CardType = PCI6229 then
  begin
    ModeNew := ADCModeArrayNew[ADCMode];
    channelstr := 'dev1/ai' + inttostr(channel);
    channelpchar := addr(channelstr[1]);
    ret := DAQmxCreateTask('', @hdl);
    ret := DAQmxCreateAIVoltageChan(hdl, channelpchar,'', DAQmx_Val_InputTermCfg_RSE,0.0, ModeNew, DAQmx_Val_VoltageUnits1_Volts, '');
    ret := DAQmxReadAnalogScalarF64(hdl, 100, @data, nil);
    ret := DAQmxWaitUntilTaskDone(hdl,10);
    ret := DAQmxStopTask(hdl);
    ret := DAQmxClearTask(hdl);
    result := data ;


This is a piece of my code which is working 🙂
0 Kudos
Message 3 of 17
(7,386 Views)
This problem is ok. But I have a new problem. Problem is following:
 
I can't multichannel read. I try this the same time return to me error message: "The specified resource is reserved. The operation could not be completed as specified.
Task Name: _unnamedTask<1>
 
Status
 
0 Kudos
Message 4 of 17
(7,370 Views)
This problem is ok. But I have a new problem. Problem is following:
 
I can't multichannel read. I try this the same time return to me error message: "The specified resource is reserved. The operation could not be completed as specified.
Task Name: _unnamedTask<1>
 
Status Code:
 
0 Kudos
Message 5 of 17
(7,370 Views)

Hi All,

This problem is ok.
But I have a new problem. Now, I can'T multiple channel read the same time.
I try this return error message to me. Message is following.

 --------------------
 Error:
 The specified resource is reserved. The operation could not be completed as specified.
 Task Name: _unnamedTask<1>
 
 Status Code: -50103
 --------------------

0 Kudos
Message 6 of 17
(7,369 Views)

Onur,

It sounds like you are trying to run multiple analog input tasks as the same time.  In DAQmx, you can only have one analog input task running at a time.  You'll need to add multiple channels to the same task if you want them to run at the same time.  When you call the DAQmxCreateChannel function, you can specify multiple channels.  Here is an example of a channel string that includes channels ai0, ai3, ai4, ai5, and ai6:

"Dev0/ai0, Dev0/ai3:6"

For more information on channel syntax, see the NI-DAQmx C Reference Help (NI-DAQmx Concepts >> NI-DAQmx Help >> NI-DAQmx Key Concepts >> Channels >> Physical Channel Syntax).

Thanks,

Justin M.
National Instruments

0 Kudos
Message 7 of 17
(7,354 Views)
Hi,
 
How do you guys solve the problem of  "not supported" lines in nidaqmx.pas ?
 
This one for instance
 
function DAQmxGetCIFreqDigFltrEnable(taskHandle:Longint; channel:PChar; data:P<not supported>):Longint; stdcall;
 
This line does not compile. How we solve the problem ? Comment out and d'ont use ?
 
Thanks
 
Joaquim
0 Kudos
Message 8 of 17
(7,318 Views)
Joaquim,

Problem solution is following.

unit nidaqmx;

interface

uses Windows, ActiveX, Classes, Graphics, StdVCL, Variants, SysUtils, NIDAQmxCAPI_TLB;

type
  Bool32 = LongInt;
type
  pBool32 = ^Bool32;
type
   i8 = ShortInt;
type
   u8 = Byte;
......
Code continues to attachment file.
0 Kudos
Message 9 of 17
(7,300 Views)
Justin,

I think, you don't understand me or I couldn't told to you.
I solved to this problem but continues read very slowly.
Every channel for start and stop task this slowly reason.
How can I faster than this?

All code is attachment file.

Thanks.

Uses
   .....
   .....
  
AnalogReadClass;
...
..
function readUSB(ch:byte):double;
Label
  err, stopProcess;
var
  i: byte;
begin
  if niUSB=nil then niUSB := TNIusb.Create;
  if niUSB.deviceDetect<>0 then goto err;
  Showmessage(niUSB.getReturn);
  niUSB.extractDeviceName(niUSB.getReturn);
  //if niUSB.channelDetect<>0 then goto err;

  //Memo1.Lines.Add(niUSB.getReturn);
  if niUSB.createTask(ch)<>0 then goto err;
  if niUSB.createAIVoltageChan(ch)<>0 then goto err;
  if niUSB.CfgSampClkTiming(ch)<>0 then goto err;
  if niUSB.ReadAnalogF64(ch)<>0 then goto err;
  readUSB := niUSB.getData[0];
  Application.ProcessMessages;
  niUSB.StopTask(niUSB.getTaskHandle[ch]);
  niUSB.ClearTask(niUSB.getTaskHandle[ch]);
  freeAndNil(niUSB);
  exit; //goto stopProcess;

  ///////////////
  // Error label
  ///////////////
  err:
    Fmonitor.IswitcBaslat.Active := False;
    readUSB := -191919;
    niUSB.GetExtendedErrorInfo(niUSB.mesaj, 2048);
    Application.MessageBox(niUSB.mesaj, 'Hata', mb_OK+MB_ICONERROR);
    goto stopProcess;

  //////////////
  // Stop label
  //////////////
  stopProcess:
    // DAQmx Stop Code
    if (niUSB.getTaskHandle[ch]<>0) then
    begin
      niUSB.StopTask(niUSB.getTaskHandle[ch]);
      niUSB.ClearTask(niUSB.getTaskHandle[ch]);
    end;
    freeAndNil(niUSB);   
    exit;
end;

0 Kudos
Message 10 of 17
(7,299 Views)