The best place for ReadFile()
-
Hi all, I'm writing a program using VC++ 6.0. The program is send and receives messages - string - via serial port. I used Overlapped mode for the communication. The program does not know when the data will come. i.e. if there is a data coming from the serial port at any time, read it. I used MFC in this project, so where is the best place for ReadFile() so that it checks if there is any data coming from serial port?? Thanks in advance What I learned is still a dot in the programming world
-
Hi all, I'm writing a program using VC++ 6.0. The program is send and receives messages - string - via serial port. I used Overlapped mode for the communication. The program does not know when the data will come. i.e. if there is a data coming from the serial port at any time, read it. I used MFC in this project, so where is the best place for ReadFile() so that it checks if there is any data coming from serial port?? Thanks in advance What I learned is still a dot in the programming world
I also have the same problem to read the file from the serial port.
Regards, Ram
-
Hi all, I'm writing a program using VC++ 6.0. The program is send and receives messages - string - via serial port. I used Overlapped mode for the communication. The program does not know when the data will come. i.e. if there is a data coming from the serial port at any time, read it. I used MFC in this project, so where is the best place for ReadFile() so that it checks if there is any data coming from serial port?? Thanks in advance What I learned is still a dot in the programming world
Have a look at Joe Newcomer's article about a threaded solution to serial programming: clickety[^]. In the article Joe uses UI threads. I've developed my own with worker threads. In addition to Joe's article you have to use
::SetCommState()
in order to set baudrate and such. You should also set the timeouts for the read and write operations with::SetCommTimeouts()
. I usually setReadIntervalTimeout
andReadTotalTimeoutMultiplier
toMAXDWORD
to get a special behaviour where a read operation expires afterReadTotalTimeoutConstant
ms even if nothing has been received. In my opinion a reasonable value forReadTotalTimeoutConstant
would be 50 ms. Read more here: ::SetCommState()[^] ::SetCommTimeouts()[^]
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
-
Have a look at Joe Newcomer's article about a threaded solution to serial programming: clickety[^]. In the article Joe uses UI threads. I've developed my own with worker threads. In addition to Joe's article you have to use
::SetCommState()
in order to set baudrate and such. You should also set the timeouts for the read and write operations with::SetCommTimeouts()
. I usually setReadIntervalTimeout
andReadTotalTimeoutMultiplier
toMAXDWORD
to get a special behaviour where a read operation expires afterReadTotalTimeoutConstant
ms even if nothing has been received. In my opinion a reasonable value forReadTotalTimeoutConstant
would be 50 ms. Read more here: ::SetCommState()[^] ::SetCommTimeouts()[^]
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
Thanks Roger Stoltz for help I found a function that called all the time. I put the ReadFile() there. The function is DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam). Right click on the dialog>Classwizard from Messages Maps tab choose DefWindowProc under Messages. Add function then edit code :cool: .
-
Thanks Roger Stoltz for help I found a function that called all the time. I put the ReadFile() there. The function is DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam). Right click on the dialog>Classwizard from Messages Maps tab choose DefWindowProc under Messages. Add function then edit code :cool: .
:wtf::omg::confused: X| Have you read the articles I provided links for in my previous post? If you have, you did not understand any of it.
DefWindowProc()
is probably the absolute worst place you can put a call to::ReadFile()
in since it processes unhandled messages and may get called frequently or not at all. Have a look here: http://msdn2.microsoft.com/en-us/library/ms633569.aspx[^] for further information about window procedures. You should also have a look at http://www.codeproject.com/system/#Hardware+programming[^] since you'll find some different approaches to writing serial communication.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote