07-21-2021 12:36 PM
Hello Everyone, Thank you in advanced for your time!
I am trying to use a U3 LabJack in order to control a MCP23017 I2C device. I am much more comfortable in C# than TestStand so I wanted to keep the vast majority of the logic and commands in C#.
Right now I have multiple classes that create and control the LabJack and I2C device, if I use a main in order to control the classes there is no error and the relays I specify are flipped on the I2C device. But when I build it to a class library and try to run the same commands in TestStand instead of using a static main I get a very strange error. I even just made the main not static and tried to run that in TestStand so no variables where being passed in and I got the error at the same exact spot as I did when trying calling the commands one at a time.
The error is in an attached image LJI2CError.png
A picture of the main is also attached Main.png
To be more clear -- My program runs correctly when I use pure C#, when I try to run the same exact file in TestStand I get an error.
Quick Summary of Solutions I have tried
- Making sure my DLL is built correctly according to the TestStand 2020 x64 specs.
- Calling the commands one at a time and saving the various objects in local object references and passing them in when required.
- Putting waits/pauses in my code between commands
- I tried to run the NI Example IC2 Code (can be found in "DotNet_LJUD\Examples\LJUDDotNet\U3\C#\U3_I2C") I was able to get it running in C# but again when I tried to run it using TestStand I got the same exact issue in the same spot
- I am not sure if this helps but I also found some information on potential the same or similar error, Error Number: 478779, TestStand 2019 Known Issues By Date - NI
I know this might be a long shot but I would really appreciate any help or explanation, Thank you!
Solved! Go to Solution.
07-21-2021 04:54 PM - edited 07-21-2021 04:56 PM
The Error is likely due to the application bitness and usage of AddRequest. AddRequest expects a 32-bit integer for x1. This is a problem if you are running a 64-bit app and need to make calls where you pass an array (reference) to the x1 parameter. Instead, please replace AddRequest with AddRequestPtr wherever you need to pass an array to x1, such as with the I2C write command:
https://labjack.com/support/software/api/ud/function-reference/addrequest
07-22-2021 07:15 AM
It Worked! Thank you!
Needless to say I am very grateful and appreciate your time and effort.
😀
04-22-2024 05:43 PM
@Wyn13 and @LabJackSupport thanks for positing this issue.
I know this is an old post but hoping someone can help with a similar issue I face. I have a 64 bit C# application that references the 64 bit LJUDDotNet library (version 3.42). AddRequestPtr to do I2C_WRITE throws a AccessViolationException.
Going by @LabJackSupport comment "to just replace AddRequest with AddRequestPtr". I get the same AccessViolationException whether I run my application in Visual Studio as a x86 or x64 application.
@Wyn13 would help if you can post the AddRequestPtr related code that worked for you.