Lire de usb

Fermé
gasmi6786 Messages postés 12 Date d'inscription samedi 27 octobre 2012 Statut Membre Dernière intervention 16 avril 2013 - 3 nov. 2012 à 13:01
Two Jay Messages postés 246 Date d'inscription jeudi 14 octobre 2010 Statut Membre Dernière intervention 30 avril 2014 - 27 nov. 2012 à 14:23
Bonjour,

j'ai problème en niveau ce code merci de m'aider.
// usb3.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

using namespace std;


#include <lusb0_usb.h>



#define MY_VID 0x04D8
#define MY_PID 0x0003

/* the device's endpoints */
#define EP_IN 0x81
#define EP_OUT 0x01

#define BUF_SIZE 16


usb_dev_handle *open_dev(void);

usb_dev_handle *open_dev(void)
{
struct usb_bus *bus;
struct usb_device *dev;

for(bus = usb_get_busses(); bus; bus = bus->next)
{
for(dev = bus->devices; dev; dev = dev->next)
{
if(dev->descriptor.idVendor == MY_VID
&& dev->descriptor.idProduct == MY_PID)
{
return usb_open(dev);
}
}
}
return NULL;
}

int get_value(void)
{

usb_dev_handle *dev = NULL; /* the device handle */
char tmp[BUF_SIZE];

usb_init(); /* initialize the library */
usb_find_busses(); /* find all busses */
usb_find_devices(); /* find all connected devices */


if(!(dev = open_dev()))
{
printf("error: device not found!\n");
return 0;
}

if(usb_set_configuration(dev, 1) < 0)
{
printf("error: setting config 1 failed\n");
usb_close(dev);
return 0;
}

if(usb_claim_interface(dev, 0) < 0)
{
printf("error: claiming interface 0 failed\n");
usb_close(dev);
return 0;
}

if(usb_bulk_write(dev, EP_OUT, tmp, sizeof(tmp), 5000)
!= sizeof(tmp))
{
printf("error: bulk write failed\n");
}

if(usb_bulk_read(dev, EP_IN, tmp, sizeof(tmp), 5000)
!= sizeof(tmp))
{
printf("error: bulk read failed\n");
} else {

printf("Potentiometer high_value is %d \n",tmp[0]);
printf("Potentiometer low_value is %d \n",tmp[1]);
printf("Potentiometer value is %d \n",(tmp[1] | ((tmp[0] & 0x0F) << 8)));


}

usb_release_interface(dev, 0);
usb_close(dev);

return 0;
}

l'erreur est le suivent:
1>------ Build started: Project: usb3, Configuration: Debug Win32 ------
1>Build started 11/3/2012 12:56:29 PM.
1>InitializeBuildStatus:
1> Touching "Debug\usb3.unsuccessfulbuild".
1>ClCompile:
1> All outputs are up-to-date.
1> usb3.cpp
1>ManifestResourceCompile:
1> All outputs are up-to-date.
1>usb3.obj : error LNK2019: unresolved external symbol _usb_open referenced in function "struct usb_dev_handle * __cdecl open_dev(void)" (?open_dev@@YAPAUusb_dev_handle@@XZ)
1>usb3.obj : error LNK2019: unresolved external symbol _usb_get_busses referenced in function "struct usb_dev_handle * __cdecl open_dev(void)" (?open_dev@@YAPAUusb_dev_handle@@XZ)
1>usb3.obj : error LNK2019: unresolved external symbol _usb_release_interface referenced in function "int __cdecl get_value(void)" (?get_value@@YAHXZ)
1>usb3.obj : error LNK2019: unresolved external symbol _usb_bulk_read referenced in function "int __cdecl get_value(void)" (?get_value@@YAHXZ)
1>usb3.obj : error LNK2019: unresolved external symbol _usb_bulk_write referenced in function "int __cdecl get_value(void)" (?get_value@@YAHXZ)
1>usb3.obj : error LNK2019: unresolved external symbol _usb_claim_interface referenced in function "int __cdecl get_value(void)" (?get_value@@YAHXZ)
1>usb3.obj : error LNK2019: unresolved external symbol _usb_close referenced in function "int __cdecl get_value(void)" (?get_value@@YAHXZ)
1>usb3.obj : error LNK2019: unresolved external symbol _usb_set_configuration referenced in function "int __cdecl get_value(void)" (?get_value@@YAHXZ)
1>usb3.obj : error LNK2019: unresolved external symbol _usb_find_devices referenced in function "int __cdecl get_value(void)" (?get_value@@YAHXZ)
1>usb3.obj : error LNK2019: unresolved external symbol _usb_find_busses referenced in function "int __cdecl get_value(void)" (?get_value@@YAHXZ)
1>usb3.obj : error LNK2019: unresolved external symbol _usb_init referenced in function "int __cdecl get_value(void)" (?get_value@@YAHXZ)
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>C:\Users\gasmi\Documents\Visual Studio 2010\Projects\usb3\Debug\usb3.exe : fatal error LNK1120: 12 unresolved externals
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.79
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
A voir également:

2 réponses

Utilisateur anonyme
24 nov. 2012 à 22:46
Euh... avant de lire tout ton code, dis nous ce que tu veux faire et commente le. Sinon c'est illisible, et donc je pense que personne ne t'aidera.
0
Two Jay Messages postés 246 Date d'inscription jeudi 14 octobre 2010 Statut Membre Dernière intervention 30 avril 2014 11
27 nov. 2012 à 14:23
ça fait quoi to programme???
0