CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Fri Oct 18, 2019 8:03 pm

All times are UTC+01:00

Post new topic  Reply to topic  [ 1 post ] 
Author Message
PostPosted: Mon Aug 15, 2016 5:55 pm 

Joined: Sun Aug 14, 2016 4:01 pm
Posts: 1
Hi All,

I'd like to connect a USB game-pad and use it to control things in my application.
What I've done so far:
1. Installed:
sudo apt-get install joystick

2.Tested if i can see any inputs:
jstest /dev/input/js0
Everything looked good.
Driver version is 2.1.0.
Joystick (Gasia Co.,Ltd PS(R) Gamepad) has 7 axes (X, Y, Z, Rz, Hat0X, Hat0Y, (null))
and 12 buttons (Trigger, ThumbBtn, ThumbBtn2, TopBtn, TopBtn2, PinkieBtn, BaseBtn, BaseBtn2, BaseBtn3, BaseBtn4, BaseBtn5, BaseBtn6).
Testing ... (interrupt to exit)
Axes:  0:     0  1:     0  2:     0  3:     0  4:     0  5:     0  6:-32767 Buttons:  0:off  1:off  2:off  3:off  4:off  5:off  6:off  7:off  8:off  9:off 10:off 11:off

3. Had a look into the device file. Whenever i press a button a new line with 16 Bytes gets written.
cat /dev/input/js0 | hexdump

Response, Note the first seven digits are the address then the actual 16 Bytes of data follow.
0000120 0d36 05c1 376c 0202 0d36 05c1 7fff 0302
0000130 0d54 05c1 72cd 0202 0d68 05c1 7966 0202
0000140 0d72 05c1 7d5c 0202 0d86 05c1 7fff 0202
0000150 0dc2 05c1 0000 0202 0dc2 05c1 0000 0302

So this looked very good as well. The structure in the device file isn't very difficult to reverse engineer so I thought I should be able to read this file in Codesys.

5. Then i tried to read this file in Codesys
Variable declaration:
szFilePath   : STRING := '/dev/input/js0';
Buffer: STRING(16);

hFile := SysFile.SysFileOpen(szFile:=szFilePath, am:=SysFile.AM_READ, pResult:=ADR(FileOpenResult));
dwRead := SysFile.SysFileRead(hFile:=hFile, pbyBuffer:=ADR(Buffer), ulSize:=SIZEOF(Buffer), pResult:=ADR(FileReadResult));

However I get in the variable Buffer only some counter which is constantly counting up.

Has anyone any idea how I can read this file?

Thank you!


Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 1 post ] 

All times are UTC+01:00

Who is online

Users browsing this forum: No registered users and 5 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited