Hi,
I have written a libusb code to send strings across to a power meter. I am successfully able to send strings across, but error occurs when I try to read the response from the meter.Can you please tell me am I going wrong?
#include <stdio.h>
#include <usb.h>
#include <time.h>
//clock_t start, end;
//double cpu_time_used;
// int argc, char **argv
int main(int argc, char **argv)
{
struct usb_bus *busses;
usb_set_debug(2);
usb_init();
usb_find_busses();
usb_find_devices();
busses = usb_get_busses();
struct usb_dev_handle* usb_handle;
struct usb_bus *bus;
int c, i, a;
char buf[255];
char buf2[5];
char* ptr = buf;
for (bus = busses; bus; bus = bus->next)
{
struct usb_device *dev;
for (dev = bus->devices; dev; dev =dev->next)
{
/* Check if this device is a power meter */
if (dev->descriptor.idProduct == 0xCEC7)
{
int i,stat,j;
printf("vendor: %04X\n",dev->descriptor.idVendor);
usb_handle = usb_open(dev);
if(usb_handle == NULL) {
printf("Could not open device: %s\n", usb_strerror());
}
if(usb_handle != NULL) {
printf("<<<Device Open>>>\n");
}
//usb_detach_kernel_driver_np(usb_handle, 0);
stat = usb_claim_interface(usb_handle,0);
if(stat ==0){
printf("Interface Claimed\n");}
//printf ("stat:%d from claim\n",stat);
buf2[0]='P';
buf2[1]='M';
buf2[2]=':';
buf2[3]='P';
buf2[4]='?';
/* buf2[5]=0x38;
buf2[6]=0x31;
buf2[7]=0x30; */
i=usb_bulk_write(usb_handle,0x02,buf2, 5, 10);
printf("write: %d\n",i);
for(i=0;i<sizeof(buf2);i++)
{
printf("buf2[%d]=%X\n",i,buf2[i]);
}
j=usb_bulk_read(usb_handle, 0x81, buf, sizeof(buf), 10);
if(j < 0) {
printf("No output\n");
} else
{
printf("read %d bytes\n", j);
}
usb_close(usb_handle);
}
}
}
return 0;
}
/////OUTPUT////
pratik-mehtas-macbook-2:~ pratik$ gcc exp4.c -lusb
pratik-mehtas-macbook-2:~ pratik$ ./a.out
usb_set_debug: Setting debugging level to 2 (on)
vendor: 104D
<<<Device Open>>>
libusb/darwin.c get_endpoints: building table of endpoints.
get_endpoints: Pipe 1: DIR: 1 number: 1
get_endpoints: Pipe 2: DIR: 0 number: 2
libusb/darwin.c get_endpoints: complete.
Interface Claimed
libusb/darwin.c ep_to_pipeRef: Converting ep address to pipeRef.
libusb/darwin.c usb_bulk_transfer: Transfering 5 bytes of data on endpoint 0x02
write: 5
buf2[0]=50
buf2[1]=4D
buf2[2]=3A
buf2[3]=50
buf2[4]=3F
libusb/darwin.c ep_to_pipeRef: Converting ep address to pipeRef.
libusb/darwin.c usb_bulk_transfer: Transfering 255 bytes of data on endpoint 0x81
USB error: libusb/darwin.c usb_bulk_transfer: transaction timed out
USB error: usb_bulk_read: An error occured during read (see messages above)
No output
pratik-mehtas-macbook-2:~ pratik$
Thank you,
Pratik Mehta
- Replies:
- Re: DIfficulty with Libusb with EPICS Lawrence T. Hoff
- References:
- Difficulty with edm installation Mehta, Pratik
- Navigate by Date:
- Prev:
RE: Failed to create single DLLs on Windows Wang Xiaoqiang
- Next:
Re: Motor Control - anyone have drivers and opinions for: SpiiPlus, Delta Tau, Parker ACR9000 So, Sung-Leung
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
<2009>
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
- Navigate by Thread:
- Prev:
Difficulty with edm installation Mehta, Pratik
- Next:
Re: DIfficulty with Libusb with EPICS Lawrence T. Hoff
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
<2009>
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
|