LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

User event from dll source - no events

Solved!
Go to solution

I'm trying to get user events created by Logitech XBOX 360 controller. 

I'm able to communicate with the device via LabVIEW but I don't succeed to receive events from the dll file

My code is based on this example https://forums.ni.com/t5/Example-Code/Posting-Events-to-a-LabVIEW-Event-Structure-From-a-Dll/ta-p/39...

 

Tamir87_0-1660622555042.png

I'm not sure what is my problem, should I edit the dll? 

 

Kindly ask for assistance here. 

 

0 Kudos
Message 1 of 10
(285 Views)

I don't see where you are generating a user event.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 10
(277 Views)

attaching my project files.

0 Kudos
Message 3 of 10
(266 Views)
Solution
Accepted by topic author Tamir87

Your problem is that you do not understand how events work.

 

Yes you will have to change the DLL file considerably! And not the LVUserEvent.dll but the XInput1_4.dll, so you better have the source code for that too.

 

Basically the way you would have to do it is to somewhere in that DLL you want to have a function to which you can pass the actual UserEvent Refnum handle rather than the data cluster that you also use to create the user event. And that function should be also smart enough to deregister the user event when you pass it a NULL value instead of a User Event Refnum, or you have a second boolean parameter that tells the DLL if the event should be registered or rather deregistered. Then that DLL needs to have some internal function that generates the event similar to what your LVUSerEvent.cpp does but instead of a string handle it needs to post the actual cluster you defined the event with.

 

You use the XInputGetState function to do nothing really. It simply reads the state from the DLL but you try to use it to set something in the DLL and the XInputSetState function can't just be misappropriated to send a LabVIEW User Event to the DLL, this function expects a structure (cluster) of two numbers in it and if you don't pass what the function expects you are extremely unlucky that it doesn't crash! Yes I mean unlucky, because such mistakes could corrupt your memory and theoretically even eat your harddrive if you keep executing more code after that. A crash is the fastest and quickest resolution to avoid further mischief.

 

But a much simpler solution would be of course to simply reuse that XBox360.llb example and let it keep polling the state of the XBox controller with the XBox_GetState.vi and verify it with the previous state and post that user event simply from within that loop!

Rolf Kalbermatter
Averna BV
0 Kudos
Message 4 of 10
(258 Views)

Thank you for your explanation. 

I really don't understand this so well. 

 

The solution sounds a bit complicated,  I don't know how to deal with dll files. 

 

I wanted to know when a user push one of the joystick buttons without reading the joystick all the time

0 Kudos
Message 5 of 10
(239 Views)

Well technically someone actually has to poll (although theoretically the XBox controller might support interrupt USB transfer that if could send unprompted on its own).

That DLL would need to support that and require a callback function that it can call on such an interrupt.But LabVIEW can’t call callback APIs so you would need to extend the DLL to write that callback in C and then generate a LabVIEW user event from inside that callback. This sounds almost certainly all Greek to you and you share that feeling with most LabVIEW users. Most program in LabVIEW for a reason and that is not because the like to fiddle with C programming. 😀

 

Since that polling likely needs to be done anyhow there is no reason not to do it in LabVIEW.

Rolf Kalbermatter
Averna BV
0 Kudos
Message 6 of 10
(196 Views)

Xinput9_1_0.dll doesn't generate events. No callbacks either. You'd have to poll.

 

It's a standard MS dll, so no source, and no editing.

 

I've used this to get a PS3 controller's state:

wiebeCARYA_0-1660725574210.png

That's a U32, U16, U8, U8, I16, I16, I16, I16 in that cluster.

 

With prototype: int32_t XInputGetState(int32_t dwUserIndex, void *pState);

 

Of course you could put this in a loop, start it in a dll so it runs in the background, and make it send events. But what would be the point? It would do exactly the same as a VI not running in a dll.

0 Kudos
Message 7 of 10
(163 Views)

wiebe@CARYA wrote:

Xinput9_1_0.dll doesn't generate events. No callbacks either. You'd have to poll.

 

It's a standard MS dll, so no source, and no editing.

 

I've used this to get a PS3 controller's state:

wiebeCARYA_0-1660725574210.png

That's a U32, U16, U8, U8, I16, I16, I16, I16 in that cluster.

 

With prototype: int32_t XInputGetState(int32_t dwUserIndex, void *pState);

 

Of course you could put this in a loop, start it in a dll so it runs in the background, and make it send events. But what would be the point? It would do exactly the same as a VI not running in a dll.


That VI is in the XBox360.llb contained in the archive that the OP attached. And is the actual function called just before generating the User Event in the modified event example, which of course makes no sense (but doesn't hurt either, unlike the misappropriated XInputSetState() in the lower loop to try to send the LabVIEW user event to the DLL to have it magically generate an event.

Rolf Kalbermatter
Averna BV
0 Kudos
Message 8 of 10
(159 Views)

@Tamir87 wrote:

The solution sounds a bit complicated,  I don't know how to deal with dll files. 


So, polling is more complicated that polling in a dll and make it generate events?

 


@Tamir87 wrote:

I wanted to know when a user push one of the joystick buttons without reading the joystick all the time


Polling is the only way. Poll in a loop, and compare the new state with the previous state. If state is different, generate an event.

 

It's most definitely not do this in a dll, as there's no benefit to do this, and it adds a lot of complications.
 XBOX XInputGetState.png

Message 9 of 10
(154 Views)

thank you very much everyone, I couldn't deal with by myself. 

now I know what to do, ill use your solution. 

0 Kudos
Message 10 of 10
(139 Views)