Streaming counter


inddyn

Recommended Posts

I have an aplication where I am measuring the thickness of a rod, over it's length. There is a wheel with an encoder feeding into the count input of a Labjack U12, and a LVDT feeding analogue input 0.

I have modified the streaming example, and can get a plot of thickness versus time OK, however I want the X Axis to follow the encoder pulse count.

I can't get the counter to function at all. I have added a channel, CNT, set to counter0, changed StartStream channel cmd: StreamCounter:Yes

When I activate StartStream, I dont see the counter change.

Question 1: Get the counter to work

Question 2: Make X Axis follow counter

Link to comment
Share on other sites

OK, to start, can you attach your current document so we can see how you have it setup?

Do you not see the counter change, or do you not see any new data in the counter channel? Also, make sure you have the timing set to 0. The counter channel must be type LabJack_U12, D# matches your other labjack channels (0 for first found, or the ID of the U12), I/O Type is Counter, Channel # is 0. If you see data streaming in, but its staying at 0 then you probably have a hardware issue.

Link to comment
Share on other sites

OK, to start, can you attach your current document so we can see how you have it setup?

I have attached my file.

Do you not see the counter change, or do you not see any new data in the counter channel?

There is no data coming in. I have created a test file with the counter not streaming, with software timing, and it works.

Also, make sure you have the timing set to 0. The counter channel must be type LabJack_U12, D# matches your other labjack channels (0 for first found, or the ID of the U12), I/O Type is Counter, Channel # is 0.

Yes, I have done this.

Glass_thickness.zip

Link to comment
Share on other sites

As I expected it was something simply. You have to actually select "Yes" from the list. It appears you typed it in or something and put a lower case "y" instead of "Y". This driver is a bit older and was written back in the days when DAQFactory was case sensitive. Give that a try and it should work for you.

Link to comment
Share on other sites

Thanks for that. I can now plot thickness versus length.

More questions:

1) When I StartStream

How can I:

a) Zero the counter

:) Clear the graph

2) After a time the graph starts erasing on the left hand side. Why?

3) How can I StopStream at a particular counter value (length)?

Link to comment
Share on other sites

1) When I StartStream

How can I:

a) Zero the counter

Create a new counter channel, same information as the one you want to clear, but a timing of 0, then in the Quick Note section, select "Reset? Yes". Actually, you come to think of it, you can just select Reset? Yes in your existing counter since you are never reading it. Then when you want to reset the counter, just read the channel. From sequence script you'd just do:

read(mycounter)

:) Clear the graph

Clear the history of the two channels. In script its just:

MyChannel.ClearHistory()

So to do all this and stream, you'd create a quick sequence action on your button that looks like this:

read(mycounter) // reset the counter

mycounter.ClearHistory()

Myotherchannel.ClearHistory()

read(startstream)

Sorry, I don't have the doc in front of me so don't know your exact channel names...

2) After a time the graph starts erasing on the left hand side. Why?

Your history length is too short. The history is one of the parameters of the channel. It defaults to 3600 points. Make it 36,000 or more. Remember to do it on both the X and Y axis channels. The history is the number of data points kept in memory for graphing. Rather than use some preset default, DAQFactory lets you decide which channels are important and should have long histories and which are not.

3) How can I StopStream at a particular counter value (length)?

You can't really stop it at the exact moment a counter hits a particular amount. You'd need a U3 or UE9 to do that, and truthfully, you'd have to ask the LabJack guys if its even possible with those devices. The problem is that the counter readings are being fed to DAQFactory in blocks, so DAQFactory can only do a comparison when a new block arrives.

That said, if a few milliseconds of extra data is ok, just go to the event on your counter channel and put something like this:

if (MyCounter[0] > EndLength)

read(stopstream)

endif

EndLength is a variable declared and defined elsewhere. StopStream is your channel for stopping the stream. The event code gets called every time a new block of data is received. I believe with the U12 this is every 64 points, but that's just off the top of my head :)

For U3 and UE9 users: the general logic for doing the above items is the same, but resetting counters and starting and stopping streaming is done differently. Just replace all the read() commands with the appropriate functions, which you can pull out of the samples at www.daqexpress.com.

Link to comment
Share on other sites

Thanks for a great answer.

Another question:

I have created a sequence attached to a button to start/stop streaming, also output to a lamp.

if (IO0 == 0)

IO0 = 1

read(CNT)

CNT.ClearHistory()

AI0.ClearHistory()

read(StartStream)

else

IO0 = 0

read(StopStream)

endif

Starting works well, but clicking again to stop causes an error:

D0004_1009 Labjack U12: General Error: Close Handle Error

removing read(StopStream) prevents the error, but also defeats the purpose of a start/stop button!

Link to comment
Share on other sites

With the U12, once streaming is running, you can't do anything else. So, more than likely, all you need to do is stopstream before you set your digital channel.

Also, as a side point, you should put [0] inside your if:

if (IO0[0] == 0)

Truthfully, it doesn't really change the result, but without it, you end up comparing the entire history of IO0 to 0 and then truncating to one value, which obviously takes longer than just comparing the most recent value, which is what you want anyway.

Link to comment
Share on other sites

  • 2 weeks later...

Hi Glenn,

I downloaded your example control file "Glass_thickness.ctl", but get always the msg: unable to load device driver LabJack.dll. In the watch window I see that the variables Var.strFileNameList and FilePathList are not known (Error Code C1005 variable not found). Have you any idea what I'm doing wrong ?

All other examples from the LAbJack CD are running well.

Regards

Joachim

Link to comment
Share on other sites

What other samples are working? The ones that run in DAQFactory or the others?

When you get Unable To Load LabJack.dll, this means one of two things:

1) You don't have the file LabJack.dll in your DAQFactory directory, or its corrupt (doubtful)

2) You don't have the file ljackuw.dll in your system32 directory, or its the wrong version, or its corrupt (doubtful)

For readers using U3 / UE9, you can get a similar error: unable to load labjackn.dll. This happens for the same reasons but different files:

1) labjackn.dll in DAQFactory directory

2) labjackud.dll in system32 directory

Link to comment
Share on other sites

What other samples are working? The ones that run in DAQFactory or the others?

--> UE9_Stream_Simple.ctl or UE9_Counter_Simple.ctl

When you get Unable To Load LabJack.dll, this means one of two things:

1) You don't have the file LabJack.dll in your DAQFactory directory, or its corrupt (doubtful)

2) You don't have the file ljackuw.dll in your system32 directory, or its the wrong version, or its corrupt (doubtful)

For readers using U3 / UE9, you can get a similar error: unable to load labjackn.dll. This happens for the same reasons but different files:

1) labjackn.dll in DAQFactory directory

2) labjackud.dll in system32 directory

--> I'm using an UE9. Check both files in DAQFactory and system 32 directory, both are excisiting.

Link to comment
Share on other sites

As mentioned before I'm using the UE9.

But in the channel-setup window I selected as device-type the UE12, because only with that device-type I can use the command-function as I/O type and add some parameters in the column Quick Note/Special/opc.

I need the command-function as I/O type to start and stop the streaming as documented in the pdf.

Is there maybe an example somewhere in the www how to get the UE9 running for streaming the Counter0 and two DigIn with a sample rate of 2000 samples per second?

Link to comment
Share on other sites

Actually you didn't mention that you were using a UE9 originally, thus your original problem. The UE9 / U3 use a different driver then the U12 so anything that applies to the U12, such as Glenn's document and the U12 samples on the CD will not work for the UE9 or U3. For these, you should use the UE9 samples as you did. As for how to stream the counter / digital in's, I leave it to the Labjack guys to tell you the exact commands for this. The DAQFactory UE9/U3 driver pretty much exposes the UD as is, so the functions you would do as documented in the UE9 manual are the ones you would use in DAQFactory, except that you would put quotes around the constant names. You can see this in the stream sample for the UE9, which would make a good starting point. You should only need to specify different channel numbers.

The other different between the DAQFactory UE9 / U3 driver and the LabJack UD is that DAQFactory automatically takes care of reading the stream data and putting it in the appropriate channels. Again, the stream sample shows this.

You can find the latest samples and the latest release of DAQFactory Express at www.daqexpress.com

Link to comment
Share on other sites

Based on that, then, you simply need to add channels 193/210/224 to your stream list. See Section 3.2.2 of the UE9 User's Guide.

If you want to combine the Counter0 LSW and MSW into a single 32-bit value, simply multiply the MSW by 2^16 and add it to the LSW.

There is a function called TestBit() that you might want to use to check the data you get back from 193 to see if your bits of interest are high or low.

Link to comment
Share on other sites

Hi,

I solved my problem. The trick is to configure the I/O type for the FIO and the Counter as "A to D" and not as DigIn and Counter. There was a comment from another user in Forum. So I stream now my counter and 3 DigIn (FIO1-FIO3) and save the datas to a file.

I append some info and the control-file, so maybe another user with a simelar problem wil get the solution quicker.

Thanks a lot for the quick and good support.

Joachim

Link to comment
Share on other sites

Yup, sorry about that. I forgot to mention that detail. DAQFactory doesn't know that you are streaming a counter. The driver is designed to be open so that when LabJack releases new hardware and new features, it will work immediately with DAQFactory. So, all the stream data comes in on the A to D I/O type because as far as DF is concerned, its all analog input...

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.