General USB driver(VC winXP) can't read/write msg with S7 USB Adapter?

chenhg

Member
Join Date
Sep 2008
Location
Shanghai
Posts
26
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)
 
What are your declarations?
It looks like you at least are using uninitialized nReadByte and length.

Why are you opening the file, with mode OVERLAPPED, writing to it without reference to an OVERLAPPED structure, then trying to read it using an OVERLAPPED structure? You have to do one, or the other. OVERLAPPED or not. The same (properly initialized) OVERLAPPED should be passed to all calls (read/write/etc) operating against that handle.

Additionally, you should not be using _wo and _ro as names. Leading underscores are reserved for the compiler, and shouldn't be used by users.
 

Similar Topics

What is your perspective? Are you a Maintenance Tech? Systems Integrator? OEM Engineer? What are your thoughts on the topic of source...
Replies
24
Views
1,174
Wizards, It has been a few, but you all have always done me well. I have acquired a 1769-L33ER and want to use it as my collection PLC to...
Replies
5
Views
532
Hi! I recently discovered how to get to configuration mode and disable printing for connecting to PanelBuilder32 and updating my Panelview...
Replies
1
Views
453
Hello Guys, Hope everyone is doing well. I have a general doubt about ladder programming. The outputs are not getting energized when I used the...
Replies
13
Views
1,886
Hey all, I'm teaching myself PLC programming, and don't have a lot of resources at my disposal, so probably a very basic question, but I recently...
Replies
9
Views
2,421
Back
Top Bottom