Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

vbnet counter input channel read

VB2005 Counter Input DAQmx Single Reading

 


I have been tasked with upgrading a previous vb6 application using DAQ Legacy to .net using pre-existing components.

6052E and 6601. I am a vb.net programmer, not an engineer, nor did I write the original application.

- lots of deciphering and figuring out terms that I am very unfamiliar with.

6052e = Dev1

6601 = Dev2

 

Encodertype = x4

zIndexEnable = false

EncoderPhase = AHighBHigh

PulsesPerRev = 60

 

SampleClockSource = “/Dev2/PFI39”

Rate = 1000

Samples = 25

 

Taken pretty much straight from the example -

myTask.CIChannels.CreateAngularEncoderChannel(counterComboBox.Text, _

                "", encoderType, zIndexEnable, zIndexValue, encoderPhase, pulsePerRev, _

                0.0, CIAngularEncoderUnits.Ticks)

            myTask.Timing.ConfigureSampleClock(sampleClkSourceTextBox.Text, _

                Convert.ToDouble(rateTextBox.Text), SampleClockActiveEdge.Rising, _

                SampleQuantityMode.ContinuousSamples, 25)

 

 

I have installed DAQmx 8.5 and have been reading the help and scanning the samples to try and figure these things out.

Specifically MeasAngularPositionBufferedCont_ExtClk, after calling and getting help, I was finally able to get this sample to work.

 

In my application, I have my own counter object that I instantiate and each of the four has its own task, CIChannel and reader. When a channel is selected, the task is configured, the channel added, the task timing configured and the task started, when the object is unselected, I dispose of the task and channel. In my gui I have a timer event and if that channel has been selected, then I call its getcurrentvalue method, which calls the reader to get value asynchronously and pumps it to a textbox. This same type of scheme worked for me with the AIChannels, but trying to get counter angular position, all I am able to get is error -200284 pretty consistently.

 

I have matched all my criteria to the working sample, but am unable to get a value returned. Better yet, after I start my app, even if I don’t enable one of my channel objects, I can no longer run the sample application.

 

I have found that after I run my application I can use the original application (which is using the DAQ Legacy) and initiate a read and then close the original application and everything is reset aka I can successfully run the sample application again.

 

QUESTIONS:

Is there a way to test the start trigger to determine that it is configured correctly?

I have the task set up for external timing and the clock works on the sample how can I verify this is working in code?

Any idea of why I would have to go into the original application in order to get the sample to work again?

Any know of other vb code examples that might relate that you could point me to?

 

Thanks for any help

CM

Well, time to get back to the frustration...


0 Kudos
Message 1 of 35
(6,161 Views)

Hi,

Is there a way to test the start trigger to determine that it is configured correctly? - Where are you using a start trigger? - I didn't see a mention of it in your description. When troubleshooting triggers I ussually end up checking 3 things. First, I confirm that my physical trigger source is outputting a TTL signal. Second, in Max I do count events on the PFI line I have the signal connected to in order to confirm my connections. Third, I try a simple example - if it will trigger in the example, then it will trigger in my code as long as the call is made with the same settings and configurations.

I have the task set up for external timing and the clock works on the sample how can I verify this is working in code? I would start with the first two steps from above. In your case, PFI39 is an actual enoder signal if I recall correctly. With the error that you receive, -200284, one of the causes of that is when there is not external clock signal (do a quick search on ni.com for "200284" and check out the first link) - is your encoder moving when you take these readings? If there is no clock signal present, then the task will not latch in values. One good way to work around this is to use another one of your counters to generate a pulse train and use that output as a clock signal instead of PFI 39. Also, if you just want to grab single values, you don't have to do a buffered acquisition - you can figure timing for "on demand" and not have to woory about clocked values. Either method should work.

Any idea of why I would have to go into the original application in order to get the sample to work again? That ones a little tougher. If somehow you are leaving the task in an undefined state (not stopping and clearing) it can cause some issues with the next iteration. You may want to try reseting the device at the beginning of your program.

 Any know of other vb code examples that might relate that you could point me to? I think you're already looking at a good shipping example, you may want to try modifying that before trying different setups in your application.

 

Hope this helps, please don't hesitate to post back to this thread with additional questions,

Andrew S

National Instruments 

  

 

0 Kudos
Message 2 of 35
(6,140 Views)
Thanks Andrew.
I have a few follow up questions.
 
1. Start Trigger = none, but it was part of the error message and I wasn't sure how I could prove that it wasn't the culprit if I didn't know it was set.
1.1 Confirm trigger is ouputting TTL signal. What, how, physically verify?
1.2 Max do a count events on the PIF line. I went into Max, but for the 6601 the only option I had was pulse and edge timing in the test panel? Where do I go to find the signal event?
1.3 Great point and just a good standard practice. I try to do this whenever possible.

2. Grabbing single values.
2.1 Encoder is not always moving.
2.2 OnDemand. The only On Demand I could find in help was Timing.OnDemandAOIsSimultaneous, but this doesn't seem to apply as I am not writting values, just trying to read them. Or do you mean by On Demand that I should just do a singlesampleread? For this project, I actually have to do both, just not at the same time. I need to show the user a current read (which could be single current reads) and then when the user starts the automated test, then I need to collect the values into a buffer for later use.

3. Resetting the device. Sounds good, how? Is this the same method that you can do in Max by right clicking a device? If so that does't work, I still have to open the original app to get  before I can get anymore readings.

Thanks again for you help.
cm
0 Kudos
Message 3 of 35
(6,134 Views)

Hi,

I usually only have to confirm if my source is outputting a trigger if steps if I can't get any sourt of response in MAX. If you are able to count up on the correct PFI line, then you have confirmed that the trigger source is generating.

With a test panel, the "Mode" drop down box should have "Pulse Train Generation" and  "Edge Counting" - if one or both are not present, what version of DAQmx do you have? (MAX>>Software>>NI-DAQmx)

For Ondemand, I was thinking of setting the sample timing type to Ondemand instead of continuous. You could take out the timing call completely, or just change the mode to on demand

myTask.Timing.ConfigureSampleClock(sampleClkSourceTextBox.Text, _

                Convert.ToDouble(rateTextBox.Text), SampleClockActiveEdge.Rising, _

                SampleQuantityMode.OnDemand, )

You could also configure one task for ondeand reads, and another for your continuous so you don't have to reconfigure just one.

Reset  is from the NationalInstruments.DAQmx.Device class. If this doesn't work, does resetting the tradtional DAQ driver help (MAX>>Devices and Interfaces right click Traditional NI-DAQ (Legacy) and select Reset Driver for Traditional NI-DAQ.

Hope this helps,

Andrew S.

 

0 Kudos
Message 4 of 35
(6,109 Views)
Hey,
MAX version 4.2.0.3001
DAQmx version 8.5

So no need to confirm a source if I am getting values, which I am for the most part. "Count the PIF line"... What does this mean?
In Max NI-DAQmx Devices\NI PCI-6601: "Dev2" - If I call up a test panel, I do have "Pulse Train Generation" and "Edge Counting", are one of those the "Count Events" you mentioned earlier?

I don't get the option for SampleQualityMode. I get (ContinouSamples, FiniteSamples, and HardwareTimedSinglePoint). I will try to remove the timing statement and see if that clears things up.

I will check out that drive reset. Resetting through the Traditional Driver in MAX doesn't reset whatever the problem is. The only way I have been able to get it to reset is to open up the original app and enable a counter channel (which then pulls in values using the traditional daq) and after exiting the orginal app, then every things works. I did try again.

So I have had some success with the hardwaretimedsinglepoint, but it will return one value and then timeout on me.
0 Kudos
Message 5 of 35
(6,105 Views)
If I remove the timing statement, I only get 0 value back, but it doesn't time out...

CM
0 Kudos
Message 6 of 35
(6,105 Views)
So... I have removed all references to a DAQmx and commented out every line of code in my project that errors out = not using the DAQmx at all.

Reset via the origial app.
Sample app works great, close.

Start my app, open the testform.
Close the test form
exit my app

Open Sample app, try = fail, times out. -200284
---------
Next test

Reset via the original app,
Sample app works great, close.

Open sample app, works great, close. (not something with closeing the sample app).
---------
Next test
Open up main form of myapp, not the test form. Close & exit.
Open sample app, works great, close.

----
Next test
After opening up myApp and going to the testform, then exiting.
Open sample app, fails (as expected)

Try to reset via MAX.
    Traditional - open and run sample app, fail. Close.
     reset each device in mx part of MAX - open and run sample app, fail, close.

Conclusion - only able to reset via opening the original application.

Thoughts, perhaps there is a resource confilict with one of the other drivers in my project.
----------

I will be trying to remove things one at a time till I can get the sample to work consitently after the testform being opened up.

Any other suggestions?

Thanks for your help so far,

CM



So, opening the testform of my app, something seems to be interfering with the DAQmx (and affecting the counter portion of the DAQmx driver, Analog Inputs were functioning as expected).
0 Kudos
Message 7 of 35
(6,096 Views)

Next Update:
I have isolated the cause of the malfunction...!

I am using a com obj to control a servo motor (com6svr). This obj connects and then you can send it commands using either the write or write blocking after it has connected to the motor. So I have tracked the "error" down to after the obj has connected, and I use the write blocking command. That is when the sample app will no longer receive values.  I have verified that the sample app still gets values after the obj has connected, but before that write blocking is sent. I have verified the settings of that com object and tried different connect statements all to no avail. Sad thing is that the obj appears to be working just fine and the NI Driver for the analog channels is working also, only the counter channels seem to be affected by this.

I am out of ideas at this point.
I fear that my only option to continue my project would be to use the legacy driver with .net, which should work, but would mean scrapping a lot of time/energy already invested into utilizing the new driver.

I would be interested in any other suggestions if anyone else has any....

Thanks again,
cm

0 Kudos
Message 8 of 35
(6,083 Views)

What kind of communication does that com6svr use (serial, usb...)? I still suspicious that we're not getting our clock signal. What I would try is to open the "Generate Continuous Pulse Train" example and have it generate at ~100 hz on ctr2. Start up the Measure Angular Postion Buffered Continious External Clock example, and specify counter 0, and the Sample Clock source as PFI28 (Ctr 2 out for the 6601). With this setup, do you still see problems with your other calls? Does this work for you? This is how you would traditionally perform a buffered counter operation - generate a clock signal and latch in values on each clock edge. This should return, independent of the motor moving, and may resolve this issue.

Let me know if this works for you.

Andrew S

0 Kudos
Message 9 of 35
(6,077 Views)
com6svr is a com object that is controling a servo motor. The company that makes it told me that is not compatiable with .net, although I might accidentally get some functionality out of it.

The solution you offered did work, momentarily. Then it again locked up. So because it did work the first time, I did yet some more troubleshooting and I belive that I have the answer finally.

The com6svr has standard methods etc to use and certain action words, well one of the action words "DRESET:" is specific to that servo motor only and is sent just after I intialize the com6svr using the writebocking command (which would lock things up). This command is for resetting things on the servo after losing power. So when I remove this command, everything continues to function, when I put it back in, it fails. The writeblocking statement works for other commands just fine so I just didn't dig quite far enough when I found the problem intially. It has been quite a learning experience.

Oh and I did cycle the power on the unit, and after restarting my app, everything still works. So I am not seeing a consequence to removing this command, though I must say that I am not trusting the com6svr object.

Thanks for all the help Andrew and the last example config was very helpful in getting me to that last discovery.

cm
0 Kudos
Message 10 of 35
(6,065 Views)