« Close

Datasheets and User Guides

App Notes

Software & Driver

 

C#, VB .NET for UD - Windows

C# and VB .NET examples for the Windows UD library. The Windows UD library is the high-level Windows library/driver for the LabJack U3, U6 and UE9. For other LabJack devices, go to the Software page.

Refer to the text file in the download for more information.

File Attachment: 

19 comments

AIN resolution in U6 C# examples updated December 27, 2010

I2C C# examples updated December 28, 2010

Minor revisions December 29, 2010

Hi

I have a LJU3-HV which has been installed successfuly on a Windows Vista 64 machine (The test Control Panel utility can read and write to all inputs) but I'm having trouble with the .Net examples as neither the example VB nor the C versions will run in VS2010.

The error generated is: "Unable to load DLL labjackud.dll. The specified module could not be found". I ran a Windows search for "labjackud.dll" and it confirmed that the file doesn't exist on my system.

Any ideas? Please help!

Simon

If the LJControlPanel works then LabJackUD.dll should be on the system.  It would either be in C:\windows\system32 or C:\windows\SysWOW64.

Most likely with this error, the issue is building for the wrong version of the .dll.  Since LJControlPanel works, that means that the 32-bit version of the .dll is likely in the SysWOW64 folder.  32-bit programs can then run and use this version of the .dll.  Since the program is not finding it, it's likely that the program is a 64-bit program and looking for the 64-bit version in the System32 directory.

There are two fixes to this.  The first (most common and easiest) is to change the build options for the project, and set the target architecture to x86, which will force a 32-bit application.  This is often set to "any architecture" which will compile as 64-bit on 64-bit machines and 32-bit on 32-bit machines.  That change should fix the problem.

The other fix is to place a copy of the 64-bit version of the .dll into the system32 directory.  You can find information on doing that here.

 

Hi Paul

Thank you so much for the reponse - "fix 1" sorted out the problem immediately - I can now get down to some serious fun!

Thanks again!

Simon

Hi there,

 

when running the VB.net DAC program I get an error 69 -comunication with the LJTDac module, wrong number of acks recieved. wrong number of AKS.

Any ideas.... the control panel works ok.

James

Does the LJTDAC test utility work?  I suggest you continue these troubleshooting details on our forum.

Yep the test tool works fine.

when I try and enter any number in the DAC0 or DAC1 field that is what I see.

 

I've hit a roadblock trying to use C# VS Express 2012 for Windows Desktop. I installed the U3-HV on my Microsoft surface (Windows 8) and it works beautifully with the labjack apps. I have tried many of the C# examples and all behave in the same manner.

As soon as the code hits the LJUD.eput statement, I get:
"An unhandled exception of type 'System.AccessViolationException' occurred in LJUDDotNet.dll

Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt."   

Any suggestions would be appreciated.

What parameters are being passed to the ePut call?


The first thing you should check is to see if it is a generic issue or one specific to the architecture.  In VS 2012 Express you should check the build properties for the project and see what the target is.  If it is "any cpu" then it will run as 32-bit or 64-bit depending on the system.  You should try forcing it to 32-bit (x86) or 64-bit (a64) and see if you get the issue in only one, or both situations.  With that info we can help you debug it further if you email us at [email protected]

Thanks, 64/32 was the problem.  I actually found it in another post late that night.  Might be worth a note in the install materials since there are more of us finally using 64-bit stuff.  (of course that would mean that I would have to read it....  ;-)  Cheers, R

 

btw, this site does not play well with IE10.  Editing and saving is a problem...  Firefox is fine.

Falls at first hurdle :(

VC# 2010 Express needs to convert all the zip files (eg easyfunctions.sln) and then stops with LJME_ATTR_LOAD_COMM_FAILURE. Have tried 32 & 64bit compiles from a clean PC restart and LabJack test panel runs fine. Am also a VC# virgin which prob doesn't help!

The EasyFunctions example is from the LJM library's .NET examples, and not from the UD library's examples on this page. The LJM library does not support LabJack UD series devices (UE9, U3, U6), and most likely you are trying to use a UD device with the LJM library resulting in the LJME_ATTR_LOAD_COMM_FAILURE error.

If using a LabJack UE9, U3 or U6, use the .NET examples on this page. In general, all UD examples are available on this page:

http://labjack.com/support/ud/software-options/programming-ud

If using a LabJack T7, use the LJM examples which are all available here:

http://labjack.com/support/ljm/examples

Good day. I'm using Labjack U3 and I have to manage DO and DI pins from VB.NET software. Could you please provide me the list of commands or manual in order of how can I do that?

Take a look at the U3_EFunctions and U3_Simple examples in the download's U3\VB\ folder. They demonstrate digital I/O usage among other things and VB .NET syntax.

UD driver documentation (the UD .NET assembly is a wrapper to the UD driver) can be found here:

http://labjack.com/support/u3/users-guide/4

In particular you'll find the eDI and eDO function documentation used in the U3_EFunctions examples, and helpful digital I/O pseudocode/documentation. Note that constants are enumerated types in .NET. For example, LJ_ioGET_DIGITAL_BIT is LJUD.IO.GET_DIGITAL_BIT in .NET.

 

fzwerver's picture

Hi,

I recently bought one of your products, the U3LV. The examples show to poll GetNextResult until an exception occurs and it works, but the output window gets flooded over time by Exception thrown: 'LabJack.LabJackUD.LabJackUDException' in LJUDDotNet.dll. Is there any way to turn the message from the dll off?

LabJack Support's picture

Exceptions can't be disabled in the dll, and I believe the ones you are seeing are only displayed when running debug builds in Visual Studios. The examples handle the NO_MORE_DATA_AVAILABLE exception, the likely cause of the flood, but Visual Studios still displays a message about it when debugging.

In Visual Studios in the Output window you can disable exception messages. Right mouse click the Output window and deselect "Exception Messages" to stop those messages. Note when running the example's executable outside of Visual Studios, or in Visual Studios with a Release build you don't get the flood of messages.

fzwerver's picture

I just want to be able to disable the 'LabJack.LabJackUD.LabJackUDException' message from the dll. I know I'm causing an exception and my code is handling it. I understand why the exception occurs and I think i have an idea why you are not willing to support events which would have not a need for this polling/NO_MORE_DATA_AVAILABLE stuff. I don't want to turn of all "Exception Messages" because I need to see what is going wrong when debugging. It would be nice to have an option to silence the dll when knowing it performs as intended instead of shouting out it did.

LabJack Support's picture

Our .NET dll raises exceptions to return errors and there are no plans to add a feature to disable exceptions. I'm not sure how to filter out specific exception messages out of the debugger output in Visual Studios.

You could change your code to use AddRequest/GoOne/GetResult instead of AddRequest/GoOne/GetFirstResult with a GetNextResult loop detecting a NO_MORE_DATA_AVAILABLE exception. A quick example derived from the U3_Simple example which doesn't depend on the NO_MORE_DATA_AVAILABLE exception:

'Request a reading from AIN0 and AIN1.
LJUD.AddRequest(lngHandle, LJUD.IO.GET_AIN, 0, 0, 0, 0)
LJUD.AddRequest(lngHandle, LJUD.IO.GET_AIN, 1, 0, 0, 0)
'Perform requests
LJUD.GoOne(lngHandle)
'Get the analog input voltage readings.
LJUD.GetResult(lngHandle, LJUD.IO.GET_AIN, 0, dblAIN0)
LJUD.GetResult(lngHandle, LJUD.IO.GET_AIN, 1, dblAIN1)

fzwerver's picture

Thank you for your reply. I was hoping you could throw the exception in a function/class that would allow me to override it and handle the exception in my code. For now I will go with [System.Diagnostics.DebuggerNonUserCode] to suppress the message from the dll.

Thanks again.