Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Read ticks from encoder

Hello,

I have problem with reading position from encoder (encoder is a part of ThorLabs DCMotor).
I've connected it to my NI USB-6259 based on information from page: http://zone.ni.com/devzone/cda/tut/p/id/7109#toc1

I created CIAngEncoderChan and after starting the task I tried to read value from encoder.
I've obtained the error massage:
-200378 Custom scale specified not exist.
Do I make something wrong?

I'm using a code which part is bellow:
DAQmxErrChk DAQmxCreateCIAngEncoderChan(taskHandleCont, "Dev1/ctr0", "", DAQmx_Val_EncoderType2_X4, False, 0, DAQmx_Val_EncoderZIndexPhase1_AHighBLow, DAQmx_Val_LengthUnits3_Ticks, 29, 0, ByVal 0&)

DAQmxErrChk DAQmxStartTask(taskHandleCont)
   
While taskIsRunningCont = True
    DAQmxErrChk DAQmxReadCounterF64(taskHandleCont, 10000, 10, dataH, 10000, dataL,         ByVal 0&)
    countTextBox.Text = Conversion.CStr(dataL)
    DoEvents
 Wend


Any suggestions?????
 

Thanks,
AndrzejS

 

0 Kudos
Message 1 of 4
(3,160 Views)

Hi Andrzej,

 

The error message says that custom scale is not correct.

 

from help:

DAQmxCreateCIAngEncoderChan

int32 DAQmxCreateCIAngEncoderChan (TaskHandle taskHandle, const char counter[], const char nameToAssignToChannel[], int32 decodingType, bool32 ZidxEnable, float64 ZidxVal, int32 ZidxPhase, int32 units, uInt32 pulsesPerRev, float64 initialAngle, const char customScaleName[]);

 

There are 2 parts where custome scale is taking place - units and customScaleName.

 

if i compare function declaration with your code:

DAQmxCreateCIAngEncoderChan(taskHandleCont, "Dev1/ctr0", "", DAQmx_Val_EncoderType2_X4, False, 0, DAQmx_Val_EncoderZIndexPhase1_AHighBLow, DAQmx_Val_LengthUnits3_Ticks, 29, 0, ByVal 0&)

then I can think of some mistype. If you are not using custom scale, name must be set to NULL:

customScaleName const char [] The name of a custom scale to apply to the channel. To use this parameter, you must set units to DAQmx_Val_FromCustomScale. If you do not set units to DAQmx_Val_FromCustomScale, you must set customScaleName to NULL.

 

another think is parameter units:

units int32 The units to use to return angular position measurements from the channel.

Value Description
DAQmx_Val_Degrees   Degrees
DAQmx_Val_Radians   Radians
DAQmx_Val_Ticks   Timebase ticks
DAQmx_Val_FromCustomScale   Units a custom scale specifies. Use customScaleName to specify a custom scale.

 

from what i can see in your code, there is DAQmx_Val_LengthUnits3_Ticks, which I don't think is proper value. Remove the 3 from name Smiley Wink

 

I hope I'm not mistaken.

 

 

Regards,

Stefo

Certified-LabVIEW-Developer_rgb.jpg

0 Kudos
Message 2 of 4
(3,138 Views)

Hi Stefo,

Thanks for your help, I've put the proper values. The index has been put as an artefact (in true, there are different indexes for linear and angular encoders).
But I still have a problem with reading position from encoder 😞

After creating Counter Input Channels I use code:

    DAQmxErrChk DAQmxStartTask(taskHandleCont)
   
    While taskIsRunningCont = True
        DAQmxErrChk DAQmxReadCounterF64(taskHandleCont, 10000, 10, dataH, 10000, dataL, ByVal 0&)
        countTextBox.Text = Conversion.CStr(dataL)
        DoEvents
    Wend

But it dosen't work.
When I put "" (instead bolded ByVal 0&) at last position in DAQmxReadCounterF64, I obtained error "reserved parameter must be NULL"

And, when I put "ByVal 0&" the program is terminated without any messages 😞

 

Regards,

Andrzej

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

Hi Andrzej,

 

what programming language do you use? Is it VB, VB .NET or something different?

 

It is a while since i was using text languages, but as I found out, VB might have issues with ByVal 0&. It depends on how the function is declared. However, according to the NI-DAQmx C API Visual Basic 6.0 Help, you should instead NULL pass 'ByVal 0&' for reserved parameters. So now i'm not sure.

 

If you use VB 6, you might try to reset your DAQ board (which I'm not sure will help you): Error -200492 "Reserved Parameter Must Be NULL" With Visual Basic 6 and NI-DAQmx

 

From my view, code seems to be fine, the question is how to pass NULL value properly. The think I can recomend is to open example - this you can install with DAQmx driver, you just need to install it manually (NI-DAQmx Examples for Visual Basic 6.0).

 

 

regards,

Stefo

Certified-LabVIEW-Developer_rgb.jpg

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