I'm not sure if this should have gone into the beginner, but nonetheless: I'm attempting to turn on an FTDI Usb Relay by writing 3 bytes 0xFF0101 as the manual says, and I'm failing at it. Specifically I'm having trouble using the writefile method. Using this code, I keep on getting the 997 error code, and I can't tell from the MSDN website what to make of it. I haven't been back to programming after several years for all of a week. You can bash me if you want for my use of the IOstream. But whatever.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
OVERLAPPED osWrite = {0};
static DWORD dwWritten;
DWORD dwRes;
BOOL fRes;
//I don't really understand what the osWrite is, nor what this next part does.
osWrite.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (osWrite.hEvent == NULL)
// error creating overlapped event handle
return FALSE;
constchar toWrite = 0xFF0101;
if(!WriteFile(hComm, &toWrite, 3, &dwWritten, &osWrite)){//<------HERE I'm having issue------
cout<<GetLastError()<<": It's an error code. You should discover why it failed, Evin. It's weird.\n";
}
cout<<"Number of bytes written are:";
cout<<dwWritten;
Thank you so much in advance: I've torn my head apart doing it.
Okay. I believe the writefile function requires a char variable, correct me if I'm wrong. So: Following your advice, I now redefined it after much tweaking. This simple stuff should have been in the beginners code.
I tried both:
1 2 3 4 5 6 7
char toWrite [3];
toWrite[0] = 0xFF;
toWrite[1] = 0x01;
toWrite[2] = 0x01;
if(!WriteFile(hComm, &toWrite, 3, &dwWritten, &osWrite)){//<------HERE I'm having issue------
cout<<GetLastError()<<": It's an error code. You should discover why it failed, Evin. It's weird.\n";
}
And:
int toWrite = 0xFF0101;
I still get the same error: 997. But now I believe it's defined properly, and we can work from there.
Solved!! Guys, don't be stupid like me and let windows choose your drivers all the time. Since 'twas my first try at something like this, I was confused. Code worked, with no errors.