05-26-2010 05:06 AM
hello;
I want to write 8 byte to a usb raw device,but the write() must been call back many times for write the data to device,I dont know what is wrong with my programe,the usb raw have one interrupt in -pipe and one bulk out --pipe ,i will use the out bulk pipe to change the I/0 of device.i hope you can help me.
#include <ansi_c.h>
#include <visa.h>
#include <cvirte.h>
#include <userint.h>
#include "USB.h"
static int panelHandle;
static ViSession defaultRM;
static ViSession instr;
static unsigned char buffer[100];
static int i;
static ViUInt16 RcCount;
static ViUInt8 RcCounteel[9];
static ViStatus STATUS;
static ViSession USB_INICIO;
static ViString identificador_usb = "USB0::0x10C4::0x0000::NI-VISA-0::RAW";
static ViFindList findList;
static ViUInt32 numInstrs;
static char instrDescriptor[256];
static ViSession USB_FIND;
static ViUInt8 Swrite[8]={1,0,1,1,1,1,0,0};
int main (int argc, char *argv[])
{
/* Open Default RM */
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "USB.uir", PANEL)) < 0)
return -1;
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
return 0;
}
int CVICALLBACK senddate(int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
ViEventType tipoEvento=-5;
ViEvent evento;
switch (event)
{
case EVENT_COMMIT:
STATUS = viOpenDefaultRM (&USB_INICIO);
if(STATUS != VI_SUCCESS)
{break;
}
STATUS = viFindRsrc (USB_INICIO, identificador_usb, &findList, &numInstrs, instrDescriptor);
if(STATUS != VI_SUCCESS)
{
MessagePopup("ATEN??O","N?o foi possivel abrir a viFindRsrc");
QuitUserInterface (0); };
STATUS = viOpen (USB_INICIO, &instrDescriptor[0], VI_NULL, VI_NULL, &USB_FIND);
STATUS = viSetAttribute (USB_FIND, VI_ATTR_TMO_VALUE, 2000);
viSetAttribute(USB_FIND,VI_ATTR_MAX_QUEUE_LENGTH,50);
if(STATUS != VI_SUCCESS)
{
MessagePopup("ATEN??O","N?o foi possivel abrir a VI_ATTR_MAX_QUEUE_LENGTH ");
QuitUserInterface (0); // for?a o fechamento do programa
};
STATUS=viWrite (USB_FIND, Swrite, 8, VI_NULL);
if(STATUS != VI_SUCCESS)
{
MessagePopup("ATEN??O","N?o foi possivel abrir a viWrite ");
QuitUserInterface (0);
};
break;
}
return 0;
}
int CVICALLBACK Quite (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
STATUS = viClose (USB_FIND);
STATUS = viClose (USB_INICIO);
QuitUserInterface (0);
break;
}
return 0;
}