Hi!
I am working on a hid under Linux Suse and i want to communicate with it. it
is working under Windows, I have to adapt it also for Linux. I was able to
read out some device infos, but I have some problem with sending and
recieving data from the device.
I wrote a little c-program to handle a communication. I don't get any error
messages from the ioctl() but there happen strange things:
My stdout:
/*******************************************************************
ewien-134:/home/ogu1234/knx# ./knx4
Vendor_ID:0x03eb Product: 0x0001 Version: 1.0.4.
1 Application, Location: 1, devnum: 2, ifnum: 0
Senden...
knx_send 1
report_id=0, report_type= 2
knx_send vor for-Schleife: uindex:0 - rc:0
value = 5
knx_send vor for-Schleife: uindex:1 - rc:0
value = ffffffb1
knx_send vor for-Schleife: uindex:2 - rc:0
value = 4
knx_send vor for-Schleife: uindex:3 - rc:0
value = 1f
knx_send vor for-Schleife: uindex:4 - rc:0
value = 50
knx_send 6
send = 0
...gesendet...fd closed
/*****************************************************************************
The second value is on ffffffb1 and not on b1, that must be because value is
defined as __s32, or not? How can I modify this in linux, because I think it
is not enough to adapt the hiddev.h and set "_u32 value" in the
hiddev_usage_ref....
Could you help me?
Greetings from Vienna
Günther
***********************************************
************ProgrammCode***********************
***********************************************
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <asm/types.h>
#ifndef HID_MAX_USAGES
#define HID_MAX_USAGES 1024
#endif
#include <linux/hiddev.h>
int getUsageCode_Out0( int );
int match_fail( const char*, short );
int fd, version;
struct hiddev_devinfo device_info;
#define READ_BUFFER_LENGTH 5
/* File-global */
unsigned long usageCode;
/*
* In: report - The report buffer (always 64
bytes), including
record_ID
* fd - The file descriptor as delivered
by init()
* Out: -
*
* Returns: 0 if ok, or the error code of a failed
ioctl() call
*/
int knx_send( const char report[5], int fd )
{
int rc = 0, uindex;
// send output report
struct hiddev_usage_ref uref;
struct hiddev_report_info rinfo;
// always send 5 bytes, assume 0x01 (report_id) is
prepended
uref.report_id = 0x00;//*report++; // report_id
byte: special treatment
uref.report_type = HID_REPORT_TYPE_OUTPUT;
uref.field_index = 0x00;
// uref.usage_code = 0xFFA10005;
uref.usage_code = usageCode;
for( uindex = 0; uindex < 5; uindex++ )
{
uref.usage_index = uindex;
uref.value = *report++;
printf("knx_send vor for-Schleife: uindex:%d -
rc:%d\n", uindex,rc);
printf("value = %-12x\n", uref.value);
if( (rc=ioctl( fd, HIDIOCSUSAGE, &uref )) != 0 )
{
printf("knx_send fehler 1: uindex:%d - rc:%d\n",
uindex,rc);
return rc;
}
}
rinfo.report_type = HID_REPORT_TYPE_OUTPUT;
rinfo.report_id = 0x00;
rinfo.num_fields = 1;
if( (rc=ioctl( fd, HIDIOCSREPORT, &rinfo )) != 0 )
{
printf("knx_send fehler 2");
return rc;
}
printf("knx_send 6\n");
return 0;
}
/*
* In: device path - Typically,
"/dev/usb/hiddev0"
* vendorId - 4 hex digits passed as a
string, e.g. "2c58"
* productId - 4 hex digits passed as a
string, see above
* versionId - 4 hex digits passed as a
string, see above
* Out: -
*
* Returns: A valid file descriptor as returned by
open(), or < 0 on
error
*/
int knx_init( char* device_path,
const char* vendorId,
const char* productId,
const char* versionId )
{
struct hiddev_devinfo device_info;
int fd = open ( device_path, O_RDWR );
if (fd < 0) {
printf("open() failed, check the connection to the
device\n");
exit(1);
}
if (ioctl (fd, HIDIOCGDEVINFO, &device_info) |
ioctl (fd, HIDIOCGVERSION, &version) ==-1) {
close(fd);
printf("GDEVINFO failed\n");
}
printf(" Vendor_ID:0x%04hx Product: 0x%04hx
Version: %d.%d.%d.\n", device_info.vendor,
device_info.product, version >> 16, (version >> 8) &
0xff, version & 0xff);
printf("%i Application%s, ",
device_info.num_applications,
(device_info.num_applications==1?"":"s"));
printf(" Location: %d, devnum: %d, ifnum: %d\n",
device_info.busnum, device_info.devnum,
device_info.ifnum);
if (getUsageCode_Out0( fd ) < 0) {
printf("getusageCode_Out0 kleiner 0\n");
return -8;
}
printf("Ausgabe");
if (*vendorId != 0 || *productId != 0 ||
*versionId != 0) {
/*
* If vendorID, productId, or versionId provided:
* Check if device matches them!
*/
printf("if abfrage: vendorId != 0 || *productId != 0
|| *versionId != 0");
int rc = ioctl( fd, HIDIOCGDEVINFO, &device_info );
if (rc < 0) {
printf("ioctl in init -Fehler");
return -16;
}
if ((*vendorId != 0) && match_fail(vendorId,
device_info.vendor)){
printf("VendorID failed");
return -4;
}
if ((*productId != 0) && match_fail(productId,
device_info.product)){
printf("ProductID Failed");
return -4;
}
if ((*versionId != 0) && match_fail(versionId,
device_info.version)){
printf("VersionID failed");
return -4;
}
}
printf("init fertig");
return fd;
}
/*
* In: fd - The file descriptor of the currently
opened device
* Out: -
* Returns: 0 if ok, error code of close() if not
*/
int knx_exit( int fd )
{
return close( fd );
}
/*
* Internally used functions - don't export to Ruby!
*/
int getUsageCode_Out0( int fd )
{
struct hiddev_usage_ref uref;
int rc;
uref.report_type = HID_REPORT_TYPE_OUTPUT;
uref.report_id = 0x00;
uref.field_index = 0;
uref.usage_index = 0;
rc = ioctl( fd, HIDIOCGUCODE, &uref );
if (rc < 0) return rc;
usageCode = uref.usage_code;
printf("return 0");
return 0;
}
int match_fail( const char* id_string, short value )
{
int id;
sscanf( id_string, "%4x", &id );
return (id == value) ? 0 : 1;
}
int main(int argc, char **argv[]) {
int send, close, uc;
char report[5];
fd=knx_init("/dev/usb/hiddev0","03eb", "0001",
"0100");
printf("fd = %d\n",fd);
printf("Senden...\n");
report[0] = 0x05;
report[1] = 0xb1;
report[2] = 0x04;
report[3] = 0x1f;
report[4] = 0x50;
send=knx_send(report, fd);
printf("send = %d\n",send);
if (send==0)
printf("...gesendet");
close=knx_exit(fd);
if (close==0)
printf("...fd closed");
return 1;
}
Günther Obrist
Moeller Gebäudeautomation KG
Scheydgasse 42, 1210 Wien
AUT Entwicklung Wien (Diplomant)
--
Günther Obrist
Moeller Gebäudeautomation KG
Scheydgasse 42, 1210 Wien
AUT Entwicklung Wien (Diplomant)
-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel