| Moteur de recherche de fiches techniques de composants électroniques |
|
AN197 Fiches technique(PDF) 1 Page - Silicon Laboratories |
|
|
|||||||||||||||||||||||||||||
AN197 Fiches technique(HTML) 1 Page - Silicon Laboratories |
|
1 / 14 page ![]() Rev. 0.6 10/07 Copyright © 2007 by Silicon Laboratories AN197 AN197 SERIAL COMMUNICATIONS GUIDE FOR THE CP210X 1. Introduction This document is intended for developers creating products based on the CP210x USB to UART Bridge Controller. It provides information about serial communications and how to obtain the port number for a specific CP210x device. Code samples are provided for opening, closing, configuring, reading, and writing to a COM port. Also included are GetPortNumWinXXXX() functions that can be copied and used to determine the port number on a CP210x device by using its Vendor ID (VID), Product ID (PID), and serial number. 2. Opening a COM Port Before configuring and using a COM port to send and receive data, it must first be opened. When a COM port is opened, a handle is returned by the CreateFile() function that is used from then on for all communication. Here is example code that opens COM3: HANDLE hMasterCOM = CreateFile("\\\\.\\COM3", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, 0); The first parameter in the CreateFile() function is a string that contains the COM port number to use. This string will always be of the form "\\\\.\\COMX" where X is the COM port number to use. The second parameter contains flags describing access, which will be GENERIC_READ and GENERIC_WRITE for the example in this document, and allows both read and write access. Parameters three and four must always be 0, and the flag in parameter five must always be OPEN_EXISTING when using CreateFile() for COM applications. The sixth parameter should always contain the FILE_ATTRIBUTE_NORMAL flag. In addition, the FILE_FLAG_OVERLAPPED is an optional flag that is used when working with asynchronous transfers (this option is used for the example in this document). If overlapped mode is used, functions that read and write to the COM port must specify an OVERLAPPED structure identifying the file pointer, which is demonstrated in section 3.1. and section 3.2. (more information on overlapped I/O is located at http://msdn.microsoft.com/library/en-us/dnfiles/html/msdn_serial.asp?frame=true - serial_topic4). The seventh, and last, parameter must always be 0. If this function returns successfully, then a handle to the COM port will be assigned to the HANDLE variable. If the function fails, then INVALID_HANDLE_VALUE will be returned. Upon return check the handle and if it's valid, then prepare the COM port for data transmission. Relevant Devices This application note applies to the following devices: CP2101, CP2102, CP2103 |
Numéro de pièce similaire - AN197 |
|
Description similaire - AN197 |
|
|
|
Lien URL |
| ALLDATASHEET vous a-t-il été utile ? [ DONATE ] |
À propos de Alldatasheet | Publicité | Contactez-nous | Politique de confidentialité | Lien vers la fiche technique | Echange de liens | Fabricants All Rights Reserved©Alldatasheet.com |
| Russian : Alldatasheetru.com | Korean : Alldatasheet.co.kr | Spanish : Alldatasheet.es | French : Alldatasheet.fr | Italian : Alldatasheetit.com Portuguese : Alldatasheetpt.com | Polish : Alldatasheet.pl | Vietnamese : Alldatasheet.vn Indian : Alldatasheet.in | Mexican : Alldatasheet.com.mx | British : Alldatasheet.co.uk | New Zealand : Alldatasheet.co.nz |
|
Family Site : ic2ic.com |
icmetro.com |