Pokeys

More
24 Oct 2015 14:06 - 21 Mar 2017 17:41 #64207 by fixer
fixer created the topic: Pokeys
Attached basic hal component for Pokeys USB IO board. Uses Cross-platform library from here . It scans at about 15hz, fast enough for UI keys and knobs. I had problems with hidcomp, taking too much resources on my rather slow computer i use for my mill, so I wrote that. With this, i dont get any significant slow down on performance and key presses get detected 100%.
It needs device serial pin to be set in HAL file with proper value.
Set your IO pin function with standard windows software that comes with the board.

pokeys.comp:
component pokeys "PoKeys IO driver, by Mit Zot";

option userspace yes;


pin out bit in-# [55];
pin out unsigned ain-# [3];
pin out bit err;
pin in unsigned devSerial;
pin out bit alive;

license "GPL";
;;

#include "PoKeysLib.h"
#include <unistd.h>   /* UNIX standard function definitions */

sPoKeysDevice * dev=0;
int i=0;

void user_mainloop(void) 
{ 
   
    while(0xb){
       FOR_ALL_INSTS() {

	 while(dev == NULL)dev = PK_ConnectToDeviceWSerial(devSerial, 2000);  //waits for usb device
	
	
	 alive=1; 
	 if ((PK_DigitalIOGet(dev) == PK_OK) && (PK_AnalogIOGet(dev) == PK_OK)){  //gets IO data and checks return value 
		err=0;
		for(i=0;i<54;i++)in(i)=!dev->Pins[i].DigitalValueGet;           //just transfers values
		for(i=0;i<3;i++)ain(i)=dev->Pins[i+44].AnalogValue;
	 }
         else{             		  //on connection error
		PK_DisconnectDevice(dev);
		dev=NULL;  		  //tries to reconnect
		err=1;
		for(i=0;i<54;i++)in(i)=0;
		for(i=0;i<3;i++)ain(i)=0;
	 }
	 alive=0;
	usleep(40000); 
        }
    }

    exit(0);
}


first compile pokeys library:
PoKeysLib requires libusb-1.0 installed on the target system.  The libusb-1.0 is installed using the following command line commands
sudo apt-get install libusb-1.0-0
sudo apt-get install libusb-1.0-0-dev

After the sources are downloaded, they must be compiled. In order to do this, go to the pokeyslib folder (where the sources have been downloaded to) and execute the following command (on Linux machine)
sudo make -f Makefile.noqmake install

or (on OS X machine)
sudo make -f Makefile.noqmake.osx install

These will also install the library in /usr/lib folder and copy the header file to /usr/include. Sudo is required to gain write access to these two folders

If qmake is preffered, PoKeysLib.pro project file can be used to compile and build the library.


Compile linuxcnc pokeys component with:
sudo halcompile ./pokeys.comp
and:
gcc -Wall  -Os -g -I. -I/usr/include/libusb-1.0 -I/usr/include -L/usr/lib/ -L/usr/lib/arm-linux-gnueabihf/ -lPoKeys -lusb-1.0 -I/usr/realtime-3.4-9-rtai-686-pae/include -I. -I/usr/realtime-3.4-9-rtai-686-pae/include -I/usr/include/i386-linux-gnu -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 -fno-math-errno -funsafe-math-optimizations -fno-rounding-math -fno-signaling-nans -fcx-limited-range -mhard-float -DRTAI=3 -fno-fast-math -mieee-fp -fno-unsafe-math-optimizations -DRTAPI -D_GNU_SOURCE -Drealtime -D__MODULE__ -I/usr/include/linuxcnc -Wframe-larger-than=2560 -URTAPI -U__MODULE__ -DULAPI -Os  -o pokeys ./pokeys.c -Wl,-rpath,/lib -L/lib -llinuxcnchal

then copy executable to proper location:
sudo mv ./pokeys /usr/bin/pokeys

To enable RW permission for USB device, you also need to set "udev" rules in linux:

REEEN wrote:
Finally I got it!
I needed to create a new udev rule:
Create a new file in the

/etc/udev/rules.d
named
90-usb-pokeys.rules
with the following contents:
SUBSYSTEM=="usb", ATTRS{idVendor}=="1dc3", ATTRS{idProduct}=="1001", GROUP="plugdev", MODE="664"
Save the file, then execute
udevadm control --reload-rules
That's it!


And that is it, now you can include the driver in your hal file with:
loadusr pokeys

and after you set yours board serial with:
setp pokeys.0.devSerial 12345
should pokeys.0.err become False and pokeys.0.alive start blinking with approx 10hz.


edit:
added some additional info
Added pokeys lib compiling procedure, original text from Polabs.
Fixed url for library in description.
Code changed to properly handle communication errors, outputs hal pin "err" on USB disconnection. Connect it in your hal file to motion.abort or emergency stop....
Last Edit: 21 Mar 2017 17:41 by fixer.
The following user(s) said Thank You: BigJohnT
More
30 Oct 2015 20:35 #64517 by REEEN
REEEN replied the topic: Pokeys
Well done!!

I have a question related to this board:
Is it possible to use some of the ios as outputs ?

I have a panel with several inputs and a few leds.
I would like to use such a board to make it easier to wire the panel, a single USB cable is much easier than several wires.
But I never saw a USB board that can also control the led outputs.
(Don't worry Estop is hardwired)

Greets Rene
More
30 Oct 2015 20:51 #64521 by andypugh
andypugh replied the topic: Pokeys
Yes the PoKeys has 55 IN and 55 OUT
www.poscope.com/pokeys-devices/PoKeys57U
The driver appears (from looking at the code) to drive the outputs too.
The pins are shared, but it appears that you can read any output as an input.

As an alternative, the Mesa 7i73 is functionally and physically very similar, and about the same price. It needs to connect to a Mesa board, rather than USB, though.
More
01 Nov 2015 22:57 #64582 by REEEN
REEEN replied the topic: Pokeys
Hello Andy,
Thank you.

I know the mesa 7i73, but I don't like it..
It has no clamps and I need to connect it to the mesa bus, currently I have a 5i25 with a 7i77 and a 7i84 connected to the 7i77. To be able to use the 7i73 I need a expansion.

I want to use it for a panel, so no realtime is needed.
More
05 Nov 2015 04:01 #64769 by fixer
fixer replied the topic: Pokeys

Is it possible to use some of the ios as outputs ?


yes, digital IO, HW encoder counters and analog inputs are supported in HAL component from first post. The board can also decode matrix keyboard and PWM outputs. It can also emulate USB HID keyboard and joystick buttons and pots.
there is also ethernet version of the board, that uses the same library, but I havent worked with that yet...
The following user(s) said Thank You: REEEN
More
29 Dec 2015 15:00 #67456 by REEEN
REEEN replied the topic: Pokeys
I just compiled and installed the pokeys component succesfully.
In my hal I did :
loadusr pokeys

Now i can see the pins.
Do i need to define my usb board anyhow with some name or else ?

I added a PoextbusOc16 board for my LEDs with the extbus to the board.

Can I somehow access the outputs of that extbus board with this comp ?

Would be great if someone could post a example hal.


Greets Rene
More
29 Dec 2015 17:10 #67460 by fixer
fixer replied the topic: Pokeys
You set the device serial in devSerial HAL pin.
More
29 Dec 2015 17:34 #67461 by REEEN
REEEN replied the topic: Pokeys
how can I find out my device serial ?
More
29 Dec 2015 21:53 #67466 by REEEN
REEEN replied the topic: Pokeys
Is it also possible to access the outputs of the extbus board the poextoc16 ?
More
30 Dec 2015 13:28 #67510 by fixer
fixer replied the topic: Pokeys
well, I only use it for encoders and input pins. It could be added though... look at the link in my first post on how to use the library.
Time to create page: 0.104 seconds
Powered by Kunena Forum