Hi,
there is corrected (bugs in visatype.pas missing of some pointers definitions) NI-Scope pascal bindings for NI-Scope 3.1 for Linux(to correct installation of NI-Scope install NIDAQmx 8.0.2 for Linux after NI-Scope).
Tested under Scientific Linux 6.4 on National Instruments PXI system:
1. NI PXIe-1078 chassic.
2. NI PXIe-8101 controller.
3. 2x NI PXI-5122 (NI-Scope 3.1 for Linux driver needed).
Autosetup code example
program test;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes, niscope, visatype,sysutils
{ you can add units after this };
var
resourceName:string='Dev1';
vi:ViSession=VI_NULL;
wfmNum:ViInt32;
actualRecordLength:dword;
actualSampleRate:viReal64;
data:array of viReal64;
channel:string = '0';
wfmInfo:array of niScope_wfmInfo;
i:longint;
procedure CheckError(AErrorCode: ViStatus; Avi: viSession);
var
errorMessage:string='';
bufferSize:ViStatus;
begin
SetLength(errorMessage,MAX_ERROR_DESCRIPTION);
if (AErrorCode<>VI_SUCCESS) then begin
//due on unkown string length niScope_GetErrorMessage should call twice
//get buffer size
bufferSize:=niScope_GetError(Avi,@AErrorCode,0,@errorMessage[1]);
//read error message
SetLength(errorMessage,bufferSize);
niScope_GetError(Avi,@AErrorCode,Length(errorMessage),@errorMessage[1]);
writeln(errorMessage);
if Avi<>VI_NULL then begin
niScope_close(Avi);
end;
Halt;
end;
end;
begin
//Init Session
CheckError(niScope_init(PChar(@resourceName[1]),NISCOPE_VAL_FALSE,NISCOPE_VAL_FALSE,@vi),vi);
writeln('Vi handler value (should be 1):' ,vi);
//auto setup measurement
CheckError(niScope_AutoSetup(vi),vi);
//read the actual record length and number of waveforms
//setuped by autosetup
CheckError(niScope_ActualRecordLength(vi,@actualRecordLength),vi);
CheckError(niScope_SampleRate(vi,@actualSampleRate),vi);
CheckError(niScope_ActualNumWfms(vi,PChar(@channel[1]),@wfmNum),vi);
//set buffer for data (lenght of data array)
SetLength(data,actualRecordLength*wfmNum);
SetLength(wfmInfo,wfmNum);
CheckError(niScope_Read(vi,PChar(@channel[1]),5.0,actualRecordLength,@data[0],@wfmInfo[0]),vi);
//shows first 10 samples
writeln('----first ten samples of record------------------');
for i:=Low(data) to Low(data)+9 do writeln('sample[',i,'] = ',data[i]:4:2);
//show Info
writeln('---------------------------------------------------');
writeln('Record lenght: ',actualRecordLength);
writeln('Sample rate: ',actualSampleRate);
writeln('Number of waveforms: ',wfmNum);
//show Info from wfmInfo record
writeln('Actual samples: ',wfmInfo[0].actualSamples);
writeln('X Increament: ',wfmInfo[0].xIncrement);
writeln('Gain: ',wfmInfo[0].Gain);
//close Session
if vi<>VI_NULL then niScope_close(vi)
end.
Binary acquisition example
program binaryacq;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes,niscope,visatype
{ you can add units after this };
var
error:ViStatus = VI_SUCCESS;
vi:ViSession;
//Variables setuped hardware
resourceName:string = 'Dev1';
channelName:string = '0,1'; //nastavit merici kanal
verticalRange:ViReal64 = 10;//rozsah -5 - 5 V
verticalOffset:ViReal64 = 0.0;
minSampleRate:ViReal64 = 2e5;
minRecordLength:ViInt32 = 1000;
binaryDataType:ViInt32;
numWaveform:ViInt32;
actualRecordLength:ViInt32;
//Default values
triggerType:ViInt32 = 0; //Immediate trigger
triggerCoupling:ViInt32 = NISCOPE_VAL_DC;
triggerSlope:ViInt32 = NISCOPE_VAL_POSITIVE;
triggerLevel:ViReal64 = 0.0;
triggerHoldoff:ViReal64 = 0.0;
triggerDelay:ViReal64 = 0.0;
triggerSource:string = '0';//nastavit kanal pro trigger
refPosition:ViReal64 = 50.0;
timeout:ViReal64 = 5.0;
stop:ViInt32;
i,j:ViInt32;
wfmInfo:array of niScope_wfmInfo;
scaledWfm:array of ViReal64;
//NI-5122 is 14-bit digitizer
binaryWfm:array of ViInt16;
procedure CheckError(AErrorCode: ViStatus; Avi: viSession);
var
errorMessage:string='';
bufferSize:ViStatus;
begin
SetLength(errorMessage,MAX_ERROR_DESCRIPTION);
if (AErrorCode<>VI_SUCCESS) then begin
//due on unkown string length niScope_GetErrorMessage should call twice
//get buffer size
bufferSize:=niScope_GetError(Avi,@AErrorCode,0,@errorMessage[1]);
//read error message
SetLength(errorMessage,bufferSize);
niScope_GetError(Avi,@AErrorCode,Length(errorMessage),@errorMessage[1]);
writeln(errorMessage);
if Avi<>VI_NULL then begin
niScope_close(Avi);
end;
Halt;
end;
end;
begin
//Open the NI_SCOPE instrument handler
CheckError(niScope_init(Pchar(@resourceName[1]),NISCOPE_VAL_FALSE,NISCOPE_VAL_FALSE,@vi),vi);
//Configure the vertical parameters
CheckError(niScope_ConfigureVertical(vi,PChar(@channelName[1]),verticalRange,verticalOffset,NISCOPE_VAL_DC,1.0,NISCOPE_VAL_TRUE),vi);
//Configure the horizontal parameters
//one record
CheckError(niScope_ConfigureHorizontalTiming(vi,minSampleRate,minRecordLength,refPosition,1,VI_TRUE),vi);
//Configure the trigger
if triggerType<>0 //Edge
then CheckError(niScope_ConfigureTriggerEdge(vi,PChar(@triggerSource[1]),triggerLevel,triggerSlope,triggerCoupling,triggerHoldoff,triggerDelay),vi)
else CheckError(niScope_ConfigureTriggerImmediate(vi),vi);
//Get number of waveforms
CheckError(niScope_ActualNumWfms(vi,PChar(@channelName[1]),@numWaveform),vi);
//Get record length
CheckError(niScope_ActualRecordLength(vi,@ActualRecordLength),vi);
writeln('Record length: ',ActualRecordLength);
//Set buffer for data and waveform Info
SetLength(binaryWfm,ActualRecordLength*numWaveform);
SetLength(scaledWfm,ActualRecordLength*numWaveform);
SetLength(wfmInfo,numWaveform);
//signal acquisition 1 record
stop:=NISCOPE_VAL_FALSE;
while stop<>NISCOPE_VAL_TRUE do begin
CheckError(niScope_InitiateAcquisition(vi),vi);
CheckError(niScope_FetchBinary16(vi,PChar(@channelName[1]),timeout,actualRecordLength,@binaryWfm[0],@wfmInfo[0]),vi);
stop:=NISCOPE_VAL_TRUE;
end;
niScope_Close(vi);
//calculate scaled data from binary data
for i:=0 to NumWaveform-1 do
for j:=0 to ActualRecordLength-1 do scaledWfm[j+(i*ActualRecordLength-1)]:=binaryWfm[j+(i*ActualRecordLength-1)]*wfmInfo[i].Gain+wfmInfo[i].offset;
for i:=0 to NumWaveform-1 do begin
writeln(' Waveform channel ',i+1);
writeln(' First 10 samples ');
writeln('----------------------');
for j:=0 to 10 do writeln('value[',j,'] = ',scaledWfm[j+(i*ActualRecordLength-1)]:4:2);
writeln('----------------------');
end;
writeln('program stoped');
end.