取消
显示结果 
搜索替代 
您的意思是: 

XInput/DirectInput and Xbox Controllers

已解决!
转到解答

For my final year project I'm using LabVIEW to create simple tactile feedback in an Xbox 360 controller.

 

Attached is some C++ example code using XInput that converts the trigger values (0 - 255) to vibration motor speed (0 - 65535);

The code defines a structure:

 

struct CONTROLER_STATE
{
XINPUT_STATE lastState;
XINPUT_STATE state;
DWORD dwResult;
bool bLockVibration;
XINPUT_VIBRATION vibration;
};

CONTROLER_STATE g_Controllers[MAX_CONTROLLERS];

 

it then sets values for vibration.wLeftMotorSpeed and vibration.wRightMotorSpeed, and passes the values to XInputSetState:

 

XInputSetState( i, &g_Controllers[i].vibration );

 

Using the "Call Library Function" node, and selecting XInput1_3.dll, I have access to XInputSetState and other functions.

'i' is the index of the controller (0 -3), but although the motor speeds are UInt_16, they are buried within the struct, and I'm not sure which type I should use, or how I should assemble the data in the block diagram.

Does anyone have any suggestions?

 

Thanks in advance,

Greg.

0 项奖励
1 条消息(共 7 条)
7,130 次查看

Dear Greg,

 

You can change the representation of a numeric control by right clicking on it and selecting Representation -> U16.  This should ensure that the data type you pass into the Call Library Function node is the same as that assigned in the .DLL

 

I hope this helps, and if you upload the .dll or the .vi you are working on then I can provide further assistance.

 

Kind Regards,

Robert Ward
Applications Engineer, NI
0 项奖励
2 条消息(共 7 条)
7,110 次查看

Attached are the dll and the test vi

 

I would like to point out that I do have experience with LabVIEW (I have used it for my second and third year projects), and I do have a bit of experience with C/C++, but I have no experience of interfacing the two.

So, although I am able to create the values needed, and I understand (somewhat) how the C++ code works, I'm not sure if wiring them into the node in the way I have is suitable.

下载全部
0 项奖励
3 条消息(共 7 条)
7,104 次查看
解答
接受人 Lucid_Insanity

Dear Greg,


Thank you for the clarification; I assumed that with 5 posts that you were a beginner.

 

It is possible to pass struct data type as defined in a .DLL as clusters in LabVIEW.  I was able to find this community example ( https://decibel.ni.com/content/docs/DOC-9079 ), and you can examine some of the attachments in LabVIEWWrapper as a basis.


Kind Regards,

Robert Ward
Applications Engineer, NI
0 项奖励
4 条消息(共 7 条)
7,093 次查看

Dear Greg,

 

Did you find that community example useful or do you still require assitance with this issue?  I believe it is a relatively straight forward issue by converting structs into clusters and vice versa (see https://decibel.ni.com/content/docs/DOC-9076 ) but; still one needs to be careful and treat it accordingly.

 

Regards,

Robert Ward
Applications Engineer, NI
0 项奖励
5 条消息(共 7 条)
7,062 次查看

I have managed to use the impolrt wizard to create vi's for some of the functions, but it didn't work for others.

However, untill the controller I ordered turns up, I won't be able to test the vi's. In the mean time, I'll keep trying to figure out the other functions, and why the wizard didn't work with them.

0 项奖励
6 条消息(共 7 条)
7,052 次查看

Thanks Rob,

 

I Just received my controller, and the vi's generated by the import wizard work perfectly.

0 项奖励
7 条消息(共 7 条)
7,029 次查看