Salve a tutti!!
Poichè vengo dal mondo Java, non conosco moltissimo quello che riguarda interazione tra periferiche e sistema operativo. Quindi avrei bisogno di una spinta nella giusta direzione.
Ho bisogno di aprire una porta (USB? seriale?) per scrivere dei bit ad una frequenza di 250 kHz. So cha sarebbe semplice usare la seriale, ma con il discorso che purtroppo sul mio pc non ne ho nemmeno una, mi devo "accontentare" delle USB.
Quindi vorrei chiedervi una domanda: è possibile semplicemente "aprire" una porta USB (per il momento non mi importa di rilevare automaticamente una libera o casini vari) e scrivere valori a una certa frequenza come si poteva fare con la vecchia seriale? Perchè avevo visto la funzione DeviceDosName(), ma resta sempre il fatto se posso aprirla come stream.
Al momento ho questo codice che mi fa la lista di tutte le periferiche connesse al pc (credo
):
codice:
#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
int DoQueryDosDevice(LPCTSTR name)
{
LPTSTR devices = NULL;
DWORD len = 1024;
devices = (LPTSTR)malloc(len * sizeof(TCHAR));
if (devices == NULL)
{
/* insufficient space */
return FALSE;
} /* insufficient space */
while (TRUE)
{
/* read devices */
DWORD result = QueryDosDevice(name, devices, len);
if (result == 0)
{
/* failed */
DWORD err = GetLastError();
if (ERROR_INSUFFICIENT_BUFFER == err)
{
/* realloc and retry */
len *= 2;
devices = (LPTSTR)realloc(devices, len * sizeof(TCHAR));
continue;
} /* realloc and retry */
else
{
/* serious error */
free(devices);
return FALSE;
} /* serious error */
} /* failed */
break;
} /* read devices */
LPTSTR pos = devices;
/*******************************************************************************
From the documentation:
If lpDeviceName is non-NULL, the function retrieves information about
the particular MS-DOS device specified by lpDeviceName. The first
null-terminated string stored into the buffer is the current mapping for
the device. The other null-terminated strings represent undeleted prior
mappings for the device.
*******************************************************************************/
/* show all */
while (strlen(pos) != 0)
{
/* scan each */
if (strstr(pos, "USB") != NULL)
cout << pos << endl;
pos += strlen(pos) + 1;
} /* scan each */
free(devices);
return TRUE;
}
int main(int argc, char * argv[])
{
DoQueryDosDevice(NULL);
return 0;
}
grazie in anticipo per le risposte