Hi all,
After having checked some of these threads out I realized that you
guys here on the forum probably will solve my problem in no-time,
while it is a tough problem for me.
In your answers - please be explainatory and tell the obvious as I am
a hardware guy trying to make a sw driver to a com-port. That's
another way of saying "I kinda suck at programming" :)
Ok - here goes:
I first used ReadFile and it worked nicely. Then I exchange it with
ReadFileEx and try and interface it like this: (I've rearranged the
code in a try to make it simple to interpret)
//First I have a callback declared as:
private callback my_callback;
//And it looks like this:
private delegate void callback(int nErrorCode,
int nNumberOfBytesT ransfered,
ref OVERLAPPED lpOverlapped);
//When I create my file I also create the callback function:
my_callback = new callback(this.t his_happens_aft er_callback);
//And the input to "my_callbac k" is:
private void this_happens_af ter_callback(in t nErrorCode,
int nNumberOfBytesT ransfered,
ref OVERLAPPED lpOverlapped)
{
}
//After I have started the program I make a new lpOverlapped, and call
ReadFileEx:
OVERLAPPED ovlCommPort = new OVERLAPPED();
ReadFileEx(hCom m,BufBytes,NumB ytes,ref ovlCommPort, ref
my_callback);
//Some additional information:
//I create the file like this:
hComm = CreateFile("COM " + PortNum ,GENERIC_READ |
GENERIC_WRITE,0 , 0,OPEN_EXISTING ,FILE_FLAG_OVER LAPPED,0);
//My OVERLAPPED looks like this:
[StructLayout(La youtKind.Sequen tial)]
private struct OVERLAPPED {
public int Internal;
public int InternalHigh;
public int Offset;
public int OffsetHigh;
public int hEvent;
}
//And this is what the import looks like:
[DllImport("kern el32.dll")]
private static extern bool ReadFileEx(
int hFile, // filehandle
byte[] lpBuffer, // data buffer
int nNumberOfBytesT oRead, // number of bytes to read
ref OVERLAPPED lpOverlapped, // overlapped buffer
ref callback lpCompletionRou tine // pointer to the completion
routine... I think.
);
Now for the (to me) strange part: I never enter the callback-function!
Why is this? That is why I don't have anything written in
"this_happens_a fter_callback" - it is useless as I never enter the
procedure...
I would be most grateful for help in this matter, as I've been trying
and trying for a whole day to make it work - without success...
Regards,
Christian
After having checked some of these threads out I realized that you
guys here on the forum probably will solve my problem in no-time,
while it is a tough problem for me.
In your answers - please be explainatory and tell the obvious as I am
a hardware guy trying to make a sw driver to a com-port. That's
another way of saying "I kinda suck at programming" :)
Ok - here goes:
I first used ReadFile and it worked nicely. Then I exchange it with
ReadFileEx and try and interface it like this: (I've rearranged the
code in a try to make it simple to interpret)
//First I have a callback declared as:
private callback my_callback;
//And it looks like this:
private delegate void callback(int nErrorCode,
int nNumberOfBytesT ransfered,
ref OVERLAPPED lpOverlapped);
//When I create my file I also create the callback function:
my_callback = new callback(this.t his_happens_aft er_callback);
//And the input to "my_callbac k" is:
private void this_happens_af ter_callback(in t nErrorCode,
int nNumberOfBytesT ransfered,
ref OVERLAPPED lpOverlapped)
{
}
//After I have started the program I make a new lpOverlapped, and call
ReadFileEx:
OVERLAPPED ovlCommPort = new OVERLAPPED();
ReadFileEx(hCom m,BufBytes,NumB ytes,ref ovlCommPort, ref
my_callback);
//Some additional information:
//I create the file like this:
hComm = CreateFile("COM " + PortNum ,GENERIC_READ |
GENERIC_WRITE,0 , 0,OPEN_EXISTING ,FILE_FLAG_OVER LAPPED,0);
//My OVERLAPPED looks like this:
[StructLayout(La youtKind.Sequen tial)]
private struct OVERLAPPED {
public int Internal;
public int InternalHigh;
public int Offset;
public int OffsetHigh;
public int hEvent;
}
//And this is what the import looks like:
[DllImport("kern el32.dll")]
private static extern bool ReadFileEx(
int hFile, // filehandle
byte[] lpBuffer, // data buffer
int nNumberOfBytesT oRead, // number of bytes to read
ref OVERLAPPED lpOverlapped, // overlapped buffer
ref callback lpCompletionRou tine // pointer to the completion
routine... I think.
);
Now for the (to me) strange part: I never enter the callback-function!
Why is this? That is why I don't have anything written in
"this_happens_a fter_callback" - it is useless as I never enter the
procedure...
I would be most grateful for help in this matter, as I've been trying
and trying for a whole day to make it work - without success...
Regards,
Christian
Comment