Open rainit2006 opened 6 years ago
Serial Port Sample https://code.msdn.microsoft.com/windowsdesktop/Serial-Port-Sample-e8accf30
Serial UART Basics http://gopinaths.gitlab.io/post/serial_uart/
Windows CreateFile : opens a communications port.
hPort1 = CreateFile (TEXT("COM5"), // Name of the port
GENERIC_READ | GENERIC_WRITE, // Access (read-write) mode
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
Writefile: transmitting data out the communications port . ReadFile: Reading Data from the Port. CloseHandle(hComm): close the serial port,
There are number of factors effecting read and write behaviours baud-rate, time-outs,Software flow control etc. These all values should be properly configured before read and write operations. ex. COMMTIMEOUTS,
UART uart(Universal Asynchronous Receiver/Transmitter)是一种异步通信协议。
GetCommState函数 Retrieves the current control settings for a specified communications device.
GetCommTimeouts (hPort2, &CommTimeouts); Retrieves the time-out parameters for all read and write operations on a specified communications device.