5秒后页面跳转
AN197 PDF预览

AN197

更新时间: 2022-04-23 23:00:11
品牌 Logo 应用领域
芯科 - SILICON 通信
页数 文件大小 规格书
14页 234K
描述
SERIAL COMMUNICATIONS GUIDE FOR THE CP210X

AN197 数据手册

 浏览型号AN197的Datasheet PDF文件第1页浏览型号AN197的Datasheet PDF文件第3页浏览型号AN197的Datasheet PDF文件第4页浏览型号AN197的Datasheet PDF文件第5页浏览型号AN197的Datasheet PDF文件第6页浏览型号AN197的Datasheet PDF文件第7页 
AN197  
3. Preparing an Open COM Port for Data Transmission  
Once a handle is successfully assigned to a COM port several steps must be taken to set it up. The COM port must  
first be purged and its initial state should be retrieved. Then the COM port's new settings can be assigned and set  
up by a device control block (DCB) structure (more information is provided on the DCB structure in section 3.3. and  
at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/dcb_str.asp).  
3.1. Purging the COM Port  
First the COM port should be purged to clear any existing data going to or from the COM port using the  
PurgeComm() function:  
PurgeComm(hMasterCOM, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR);  
The first parameter in the PurgeComm() function is a handle to the open COM port that will be purged. The second  
parameter contains flags that further describe what actions should be taken. All four flags, PURGE_TXABORT,  
PURGE_RXABORT, PURGE_TXCLEAR, and PURGE_RXCLEAR should always be used. The first two flags  
terminate overlapped write and read operations, and the last two flags clear the output and input buffers.  
If this function returns successfully then a non-zero value is returned. If the function fails, then it returns 0. Upon  
return, check the return value; if it is non-zero, continue to set up the COM port (more information on the  
PurgeComm() function is located at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/  
purgecomm.asp).  
3.2. Saving the COM Port's Original State  
Since the COM port settings can be modified to meet different needs, it is good practice to obtain the COM port's  
current state and store it so that when the COM port is closed, the COM port can be restored back to its original  
state. This can be done using the GetCommState() function:  
DCB dcbMasterInitState;  
GetCommState(hMasterCOM, &dcbMasterInitState);  
The first parameter in the GetCommState() function is a handle to the open COM port to obtain settings from. The  
second parameter is an address to a DCB structure to store the COM port's settings. This DCB structure should  
also be used as the initial state when specifying new settings for the COM port (see section 3.3.).  
If this function returns successfully then a non-zero value is returned. If the function fails, then it returns 0. Upon  
return, check the return value; if it is non-zero, continue to set up the COM port (more information on the  
GetCommState() function is located at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/  
getcommstate.asp).  
3.3. Setting up a DCB Structure to Set the New COM State  
All of a COM port's settings are stored in a DCB structure. In section 3.2. a DCB structure was retrieved that  
contained the initial settings of the COM port by using the GetCommState() function. To change a COM port's  
settings, a DCB structure must be created and filled out with the desired settings. Then the SetCommState()  
function can be used to activate those settings:  
DCB dcbMaster = dcbMasterInitState;  
dcbMaster.BaudRate= 57600;  
dcbMaster.Parity= NOPARITY;  
dcbMaster.ByteSize= 8;  
dcbMaster.StopBits= ONESTOPBIT;  
SetCommState(hMasterCOM, &dcbMaster);  
Delay(60);  
2
Rev. 0.6  

与AN197相关器件

型号 品牌 描述 获取价格 数据表
AN1979 FREESCALE Altimeter and Barometer System

获取价格

AN1984 FREESCALE Handling Freescale Pressure Sensors

获取价格

AN1A3Q NEC On-Chip Resistor PNP Silicon Epitaxial Transistor

获取价格

AN1A4M NEC PNP SILICON TRANSISTOR

获取价格

AN1A4P NEC PNP SILICON TRANSISTOR

获取价格

AN1A4P-A RENESAS AN1A4P-A

获取价格