Home > Software engineering >  Question 2 API driver serial port communication device, the use of readfile (), writefile (), progra
Question 2 API driver serial port communication device, the use of readfile (), writefile (), progra

Time:10-08

Recently want to write a Win32 console application, mainly and a serial port communication equipment, you want to send commands to the device, and then received equipment returned data display on the console window, looking for some course, also know about the whole of the serial port driver, reading and writing process, is creatfile () configuration, DCB configuration, such as, but found the readfile () and writeflie () is in the main function call, and I want to have a serial port to read and write, has been constantly sending and receiving data, so I don't understand the data transfer is how to deal with, only know data from readfile () to my buff, so want to ask the next data from the equipment through a serial port communication to print to my console, what after? The buffer where it? Program is in the background of reading data from the interrupt way?

CodePudding user response:

Because I just turn around, from the aspects of embedded so familiar with commonly used microcontroller serial port interrupt way, speaking, reading and writing, and the concept of windos programming and application mechanism may not be very clear,,,, always feel that a serial port to read and write in the main function execution can realize real-time and background,,,,

CodePudding user response:

I want to realize the function,,, console procedures, instructions, and then input device after receiving instructions have been send the data to the host, the console interface, brush brush to flowing from these data.

CodePudding user response:

Using a serial port control MSCOMM baidu MSCOMM programming data under a pile of
You want to send data suggest that you open a thread to send, receive is automatically receive, as long as there is data over a serial port, automatically triggers the receiving function that is more convenient,

CodePudding user response:

See the MSDN documentation
Serial Communications in Win32

CodePudding user response:

reference 4 floor zgl7903 response:
see MSDN document Serial Communications in Win32

Want to cry,,, we were so directly see the MSDN,,, English Alexander

CodePudding user response:

Translation is also under a lot of ah baidu

http://blog.csdn.net/zcube/article/details/8591972

CodePudding user response:

refer to 6th floor zgl7903 response:
translation is also under a lot of ah baidu

http://blog.csdn.net/zcube/article/details/8591972

Here have given way, need uninterrupted send data need to start the thread, the main thread receives the signal, the child thread to send data!

CodePudding user response:

If you want to do more real-time,
1) read the hypogyny machine code must be written in the thread, write down a machine code can be written in the main program
2) to adopt asynchronously, general open device reads

 comm_reader_handle=CreateFile (
(LPCTSTR) "\ \ \ \. \ \ COM12",//COM1
GENERIC_READ | GENERIC_WRITE,
0,//share mode: no share
NULL,//securiy attributes
OPEN_EXISTING,//the Open disposition
FILE_FLAG_OVERLAPPED,
NULL);


3) in the thread, and constantly to read the serial port, after reading a buffer, then must have the program to read to the host data is analyzed, baotou, bag end,

  • Related