关于viwrite()的USB文件传输
(温馨提示:为了您的问题能更快得到解决,请将贴子发到对应的区域,您的是labwindows/cvi问题发到了labview区,不易于问题解答,已帮您移动到labwindows/cvi区,好运!)我在做一个项目,需要在labwindows/cvi里把一个文件传送到USBRAW设备里,我先用OpenFile()打开文件,再用ReadFile()把文件里面的数据读到字符数组SendString里面,然后viWrite()发送出去,但是在viWrite()那里总是出现timeout的错误,数据不能发出去,usb设备是一个BULK -IN通道和一个BULK-OUT通道,请教我的问题在哪里呢?这里是一部分程序
int CVICALLBACK Send_select (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{ switch (event)
{
case EVENT_COMMIT:
if (FileSelectPopup ("", "", "","请选择发送文件",VAL_SELECT_BUTTON, 0, 0, 1, 1, Sendname)
!= VAL_NO_FILE_SELECTED)
{ SetCtrlVal (panelHandle,PANEL_STRING_1, Sendname);
GetFileInfo (Sendname, &Sendfilesize);
if(Sendfilesize>4053)
{MessagePopup("ATEN??O","文件太大");
}
}
break;
}
return 0;
}
int CVICALLBACK Sendfile (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{char SendString={0,0};
switch (event)
{
case EVENT_COMMIT:
FileHandle = OpenFile (Sendname, VAL_READ_ONLY, VAL_OPEN_AS_IS, VAL_BINARY);
ReadFile (FileHandle, SendString, Sendfilesize);
STATUS=viWrite (USB_FIND, (ViBuf)SendString,64, &writeCount);
CloseFile (FileHandle);
break;
}
return 0;
}
Writes data to a device.The data to be written is in the specified Buffer.This operation returns when the transfer terminates.
This operation applies to the VISA INSTR session type.
/*-------------------- Prototype ---------------------*/
ViStatus viWrite (ViSession Instrument_Handle, ViBuf Buffer,
ViUInt32 Count, ViPUInt32 Return_Count);
你的ViSession Instrument_Handle从哪里获取出来? 如果设备打开失败,是不会成功读写的。 谢谢上面的回答,USB设备是打开成功了的,在另一个回调函数里,我没帖出来而已。USB_FIND就是在: STATUS = viOpenDefaultRM (&USB_INICIO);
if(STATUS != VI_SUCCESS)
{break;
}
STATUS = viOpen (USB_INICIO, "USB0::0x10C4::0x0003::NI-VISA-0::RAW", VI_NULL, VI_NULL, &USB_FIND);
STATUS = viSetAttribute (USB_FIND, VI_ATTR_TMO_VALUE, 2000);
页:
[1]