USB Communication and ioctl macros

Linux specific forum
RE-A
User
User
Posts: 39
Joined: Thu Aug 21, 2008 4:19 pm
Location: Belgium
Contact:

USB Communication and ioctl macros

Post by RE-A »

I’m trying to communicate with a usb device (microcontroller 18F2550) and used libhid to control it but I have some issues with this library like bad connections, (random) read and write errors. I want to try the ioctl api’s but stumbled on some macro translations (_IO, _IOC, _IOR,….) in the ioctl.h (located somewhere in the /usr/src/…..)

This is part of the header file:

Code: Select all

.........
#define _IOC(dir,type,nr,size) \
	(((dir)  << _IOC_DIRSHIFT) | \
	 ((type) << _IOC_TYPESHIFT) | \
	 ((nr)   << _IOC_NRSHIFT) | \
	 ((size) << _IOC_SIZESHIFT))

#ifdef __KERNEL__
/* provoke compile error for invalid uses of size argument */
extern unsigned int __invalid_size_argument_for_IOC;
#define _IOC_TYPECHECK(t) \
	((sizeof(t) == sizeof(t[1]) && \
	  sizeof(t) < (1 << _IOC_SIZEBITS)) ? \
	  sizeof(t) : __invalid_size_argument_for_IOC)
#else
#define _IOC_TYPECHECK(t) (sizeof(t))
#endif

/* used to create numbers */
#define _IO(type,nr)		_IOC(_IOC_NONE,(type),(nr),0)
#define _IOR(type,nr,size)	_IOC(_IOC_READ,(type),(nr),(_IOC_TYPECHECK(size)))
#define _IOW(type,nr,size)	_IOC(_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
.............
Does anyone have an translation, example or a good alternative to use usb in pb Linux?
RE-A
User
User
Posts: 39
Joined: Thu Aug 21, 2008 4:19 pm
Location: Belgium
Contact:

Post by RE-A »

Never mind, I solved it.
User avatar
dhouston
Enthusiast
Enthusiast
Posts: 430
Joined: Tue Aug 21, 2007 2:44 pm
Location: USA (Cincinnati)
Contact:

Post by dhouston »

How about sharing your solution?
RE-A
User
User
Posts: 39
Joined: Thu Aug 21, 2008 4:19 pm
Location: Belgium
Contact:

Post by RE-A »

Sorry for the delay, just got back from vacation :)

I found that a translation was useless because in my opinion it’s not yet possible to use these ioctl macros in native pb. The request parameter of the ioctl function is an unsigned integer type and the outcome of almost all these usb controlling macros are too big to be contained by an signed integer (on a 32 bit system). Pb doesn’t yet support unsigned types and I just installed and tested it on the latest 4.40 beta version, but I see that there is progress on this because fred just added the unsigned word type :D

I transferred all of my hardware controlling functions to C and created a library. :(
RE-A
User
User
Posts: 39
Joined: Thu Aug 21, 2008 4:19 pm
Location: Belgium
Contact:

Post by RE-A »

Forget the unsigned integer or long types, Fred in not going to implement it. To be honest pb is the first compiler I know that doesn’t support this kind of variable types :( :(
http://www.purebasic.fr/english/viewtop ... t=unsigned
User avatar
dhouston
Enthusiast
Enthusiast
Posts: 430
Joined: Tue Aug 21, 2007 2:44 pm
Location: USA (Cincinnati)
Contact:

Post by dhouston »

Thanks for the explanation.
Post Reply