Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

win32 exception when converting C code to Visual Basic 6.0

Hi,
 
I got the following C code working, and am trying to convert it to use in my Visual Basic 6.0 program. I get the following error:

"An unhandled win32 exception occurred in VB6.EXE"

Here is my C Code:

int32       error=0;
 TaskHandle  taskHandle=0;
 uInt32      data[8]={5,4,5,4,5,4,5,4};
 char        errBuff[2048]={'\0'};

 DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
 DAQmxErrChk (DAQmxCreateDOChan(taskHandle,"Dev1/port0","",DAQmx_Val_ChanForAllLines));

 DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"OnBoardClock",300000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000));
 DAQmxErrChk (DAQmxWriteDigitalU32(taskHandle,8,0,10.0,DAQmx_Val_GroupByChannel,data,NULL,NULL));
 DAQmxErrChk (DAQmxStartTask(taskHandle));
 
In my VB code I have a Public Declare statement for the Write Function:

Public Declare Function DAQmxWriteDigitalU32 Lib "nicaiu.dll" (ByVal taskHandle As Long, ByVal numSampsPerChan As Long, ByVal autoStart As Long, ByVal timeout As Double, ByVal dataLayout As Long, ByVal writeArray As Long, ByRef sampsPerChanWritten As Long, ByRef reserved As Long) As Long

I put breaks in my VB code and it gets that error when trying to execute the DAQmxWriteDigitalU32 function.

Any Ideas??

0 Kudos
Message 1 of 4
(4,839 Views)

Hi krstn-

The DAQmxWriteDigitalU32 function requires an unsigned 32-bit integer datatype which VB6 does not support.  I would suggest that you use the DAQmxWriteDigitalLines function instead.  Have you considered using the VB6 type library that ships with the current version of NI-DAQmx?  It would prevent you from having to recreate a lot of this work yourself.  Examples of how to use the .tlb are installed in \Program Files\National Instruments\NI-DAQ\Examples\Visual Basic 6.0

Hopefully this helps-

Tom W
National Instruments
0 Kudos
Message 2 of 4
(4,838 Views)

I tried using the DAQmxWriteDigitalLines function instead and it gave me:

"Attempted to Write digital data that is not supported"

is there any way around this?

I am using the 6534

0 Kudos
Message 3 of 4
(4,836 Views)

Hello krstn127,

Have you looked at the Digital Output example for VB6?  It installs at C:\Program Files\National Instruments\NI-DAQ\Examples\Visual Basic 6.0\Digital\Generate Values\Write Dig Chan.  It uses the DAQmxWriteDigitalLines function and works with the NI 6534. 

The error you are experiencing generally indicates that you are attempting to write more or less data than the number of lines you have specified.  I think if you look at the example and compare it to your code, you will be able to find the problem.

Let us know if you have additional questions.

Regards,

Laura

0 Kudos
Message 4 of 4
(4,820 Views)