Hey just a beginner here to the win32 API so hopefully you'll bare with me :)
Programing in c++ with the win32 API on windows 10, to make a serial comm program to communicate with an Atmel microcontroller. I have been wondering if you can make a call to ReadFile and WriteFile at the same time, so as to be full duplex. Let's say i have a separate thread for writing and reading, would it be possible to read and write at the exact same time? Or do i have to pause the other thread while one is reading/writing?
That is using the:
#include <thread>
std::thread
class.
Ok. Why is this? Is the serial port just not capable of reading and writing at the same time?
In any case i think I'll have a bool flag trigger just before read/write, and if the other thread try's to do the opposite I'll make it wait in a while loop.
Sorry for slow reply!
I guess i just assumed that when you use it for serial com port interfacing, readfile and writefile pushed data to two discrete registers, not one file. What do you mean by file? As in a memory address in the system that gets buffered before it gets pushed to the actual pins? Is there any way you can have two file's, so that you could write and read at the same time?
You then use ReadFile and WriteFile to do simultaneous read and write on file that may be anything supported by API.
How does this work internally, the API manages file access in asyncronous way that is you don't need to work with mutexes, to verify this behavior call GetLastError()
The GetLastError code ERROR_IO_PENDING is not a failure; it designates the read operation is pending completion asynchronously.
This means read and write in same is not exactly in same time down to nano second unless in case of serial ports the API works differently, you said serial com interfacing works by pushing data to registers so syncronization may work slightly differently..
but I'm not expert for serial ports and registers so this is all I can say about win32 API and how to use it.