Hallo all:
Recently we have released our MPI driver using S7 Serial adapter(without Prodave comm lib).Now we want to write MPI OPC driver using S7 USB adapter.but when we call function Readfile(),the PC restart.The following is partion of the source code about usb communication.Appreciate anyone help me.
//find usb adapter (success)
if(sDevice.Find("vid_0908")!=-1 && sDevice.Find("pid_0004")!=-1)
{
hHid = CreateFile ( strtDetailData->DevicePath,
GENERIC_READ | GENERIC_WRITE,
NULL/*FILE_SHARE_READ |FILE_SHARE_WRITE*/,
NULL,
2,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED |
FILE_FLAG_WRITE_THROUGH,
0);
}
//Write msg(Get return code :997)
DWORD length;
DWORD nSendByte = 1;
BYTE buff1[256];
buff1[0] = 2;
//if(!WriteFile(hHid,buff1,nSendByte,&length,&_wo))
if(!WriteFile(hHid,buff1,nSendByte,&length,NULL))
{
DWORD d = GetLastError();
if(d != ERROR_IO_PENDING)
length = 0;
}
//Readfile(PC Restart)
ReadFile(hHid,buff,nReadByte,&length,&_ro)
Recently we have released our MPI driver using S7 Serial adapter(without Prodave comm lib).Now we want to write MPI OPC driver using S7 USB adapter.but when we call function Readfile(),the PC restart.The following is partion of the source code about usb communication.Appreciate anyone help me.
//find usb adapter (success)
if(sDevice.Find("vid_0908")!=-1 && sDevice.Find("pid_0004")!=-1)
{
hHid = CreateFile ( strtDetailData->DevicePath,
GENERIC_READ | GENERIC_WRITE,
NULL/*FILE_SHARE_READ |FILE_SHARE_WRITE*/,
NULL,
2,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED |
FILE_FLAG_WRITE_THROUGH,
0);
}
//Write msg(Get return code :997)
DWORD length;
DWORD nSendByte = 1;
BYTE buff1[256];
buff1[0] = 2;
//if(!WriteFile(hHid,buff1,nSendByte,&length,&_wo))
if(!WriteFile(hHid,buff1,nSendByte,&length,NULL))
{
DWORD d = GetLastError();
if(d != ERROR_IO_PENDING)
length = 0;
}
//Readfile(PC Restart)
ReadFile(hHid,buff,nReadByte,&length,&_ro)