I have made a serial port class inspired bu the MTTTY example and the serial
port class from OpenNETCF . below is the code from the readfile method in
which there is a problem. The code calls the WaitForSingleObject function
but always locks there until the timeout happens (GetOverlappedResult is
never called). If data is present in the buffer before I call this method
everything works well (readfile return immediately with the data). Can any
body point to the possible problem ?
OVERLAPPED readOverlapped = new OVERLAPPED();
IntPtr readOverlappedPtr = IntPtr.Zero;
ManualResetEvent readEvent = new ManualResetEvent(true);
UInt32 bytesRead = 0;
readOverlappedPtr = LocalAlloc(0x40, Marshal.SizeOf(readOverlapped));
readOverlapped.Offset = 0;
readOverlapped.OffsetHigh = 0;
readOverlapped.hEvent = readEvent.Handle;
Marshal.StructureToPtr(readOverlapped, readOverlappedPtr, true);
if (!api.ReadFile(hCommPort, buffer, (UInt32)count, ref bytesRead,
readOverlappedPtr))
{ // readfile didn't finish immediatly so wait for it to finish
if(Marshal.GetLastWin32Error() == ERROR_IO_PENDING)
{ // no error occurred so wait for readfile to finish
if (api.WaitForSingleObject(hCommPort, readTimeout) ==
WAIT_OBJECT_0)
{ // Check for number of bytes actually received
api.GetOverlappedResult(hCommPort, readOverlappedPtr,
ref bytesRead, false);
}
}
}
Your help is highly appreciated !
Thanks
Ole 1 4547
OK - got it to work - I did set the eventhandle in WaitForSingleObject to
the handle to the serial port (big mistake!)
Thanks anyway!
Ole
"ORC" <or*@sol.dk> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl... I have made a serial port class inspired bu the MTTTY example and the
serial port class from OpenNETCF . below is the code from the readfile method in which there is a problem. The code calls the WaitForSingleObject function but always locks there until the timeout happens (GetOverlappedResult is never called). If data is present in the buffer before I call this method everything works well (readfile return immediately with the data). Can any body point to the possible problem ?
OVERLAPPED readOverlapped = new OVERLAPPED(); IntPtr readOverlappedPtr = IntPtr.Zero; ManualResetEvent readEvent = new ManualResetEvent(true); UInt32 bytesRead = 0;
readOverlappedPtr = LocalAlloc(0x40, Marshal.SizeOf(readOverlapped)); readOverlapped.Offset = 0; readOverlapped.OffsetHigh = 0; readOverlapped.hEvent = readEvent.Handle; Marshal.StructureToPtr(readOverlapped, readOverlappedPtr, true); if (!api.ReadFile(hCommPort, buffer, (UInt32)count, ref bytesRead, readOverlappedPtr)) { // readfile didn't finish immediatly so wait for it to finish if(Marshal.GetLastWin32Error() == ERROR_IO_PENDING) { // no error occurred so wait for readfile to finish if (api.WaitForSingleObject(hCommPort, readTimeout) == WAIT_OBJECT_0) { // Check for number of bytes actually received api.GetOverlappedResult(hCommPort, readOverlappedPtr, ref bytesRead, false); } } }
Your help is highly appreciated !
Thanks Ole
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: ^CeFoS^ |
last post by:
Hello to everybody,
I've done an application that draws in a frame the trajectory of a
robot. The robot position is readed through the serial port, and
several commands are wrote through the...
|
by: collinm |
last post by:
hi
i send a command to a led display, the led display is suppose to return
me some character
i write a string on a serial port
void ledDisplayExist()
{
char msg={'\0', '\0', '\0', '\0',...
|
by: Kevin |
last post by:
Hi all
I am having a problem reading from a serial port, first of all I have now resorted to using the MSComm ActiveX control on my Windows Forms to provide me with the interface to my serial...
|
by: Ramakant Kasar |
last post by:
Hi,
If an application is reading data from a serial port, How can I open the
same serial port with another application?
Any idea? Please help.
Thanks,
Ramakant K.
|
by: joe bloggs |
last post by:
I am writing a mobile application to interface with a legacy system and I am
planning to use web services to communicate with this system. The legacy
system receives data through a serial port. ...
|
by: Mircea |
last post by:
Hi everybody,
I have a big problem. I am trying to use serial communication in C# 2. The
problem is that the event DataReceived is never fired. I have tried on two
computers and it does not...
|
by: Rob |
last post by:
Hi all,
I am fairly new to python, but not programming and embedded. I am
having an issue which I believe is related to the hardware, triggered
by the software read I am doing in pySerial. I...
|
by: naveen.sabapathy |
last post by:
Hi,
I am trying to use virtual serial ports to develop/test my serial
communication program. Running in to trouble...
I am using com0com to create the virtual ports. The virtual ports
seem to...
|
by: Hal Vaughan |
last post by:
I've done a fair amount of Googling for information on reading the serial
port in C++ (and in Linux). Unfortunately, out of every 4 hits, 1 seems to
be an unanswered question, 1 is someone saying,...
|
by: terry |
last post by:
Hi,
I am trying to send a character to '/dev/ttyS0' and expect the same
character and upon receipt I want to send another character. I tired
with Pyserial but in vain.
Test Set up:
1. Send...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |