Académique Documents
Professionnel Documents
Culture Documents
Objectifs :
+ UART en général
+ UART pour les MCU ATmega
+ UART pour le système Windows + API Win32
+ GUI: sur le contrôle COMBOBOX
1
@ Linux: tty, ...
Misy logiciels maro ahafahana mi-gérer ports série. PySerial ohatra dia
bibliothèque Python multi-plateforme, azo ampiasaina tsara @ capture
de données na zavatra hafa mifandraika @ ports séries.
Faharoa.
UART ho an'ny ATmega. Ny ankamaroan'ny ATmega dia misy pé-
riphérique UART ary tsisy USB natif. Ireo dia itovizany @ microcon-
trôleurs rehetra misy, satria sarotra ny protocôle USB.
Sahala @ périphérique rehetra dia misy SFR ho an'ny contrôle, ho
an'ny statut, ho an'ny data.
NB. Afaka mi-simuler UART tsotra daholo ny MCU rehetra, na misy na
tsisy UART ny périphérique ao aminy (ohatra: PIC16F84, PIC12F675,
etc. ) Ary @ Arduino moa dia misy ny Software Serial izay afaka
mampiasa broches tsotra ho lasa Tx sy Rx
2
ATmega32
Serial Engine
DTR
TXD
Vers PC RXD
+5V
GND
3V3
Gnd
TxD
ISP
sary 2. fampiasana ny CP2101 miaraka amina MCU
3
sary 3. ireo erreur de baud rate araka ny Fquartz
4
sary 4. interface du MTTTY sous Windows
Misy kosa article vaovao AN595: migrating from UART to USB, navoakan'i
Microchip momba ny fampiasana ny PIC18F misy USB natif.
HANDLE CreateFile(
5
DWORD dwFlagsAndAttributes, // file attributes
HANDLE hTemplateFile // handle to file with attributes to copy
);
4. SECURITY_ATTRIBUTES
6
BOOL WriteFile(
HANDLE hFile, // handle to file to write to
LPCVOID lpBuffer, // pointer to data to write to file
DWORD nNumberOfBytesToWrite, // number of bytes to write
LPDWORD lpNumberOfBytesWritten, // pointer to number of bytes written
LPOVERLAPPED lpOverlapped // pointer to structure needed for overlapped
);
dans l'ordre:
handle du fichier retourné par CreateFile,
lpBuffer: pointeur vers les données à écrire
nNumberOfBytesToWrite: nombre d'octets
lpNumberOfBytesWritten: pointeur vers une variable pour stocker
le nombre d'octets écrits
lpOverlapped: pointeur vers une strucuture OVERLAPPED pour une
opération asynchrone
Ny ataon'ity fonction ity dia mi-lister ireo ports séries disponibles. Mar-
ihina fa ny ordinateur de bureau taloha na ordi portable taloha no misy
ports séries tena izy, na ilay DB9. Ny portable @ zao fotoana dia tsisy
ports séries intsony fa rehefa mitsatoka ny Arduino na matériel hafa
mampiasa ports séries virtuels, izay vao misy COM5 na COMx hafa hita
après an'ity.
Fiasany: andramana daholo COM1 à COM255 dia tazomina anaty
tableau ireo izay VALID izany hoe 6= INVALID_HANDLE_VALUE.
NB. mila asiana an'io préfixe io ny anarany raha te hahita ny ports
rehetra ohatra hoe COM25 : ("\\\\.\\COM%u"), i);
source d'inspiration:
/* if ret = TRUE
- pNumber store the number of COM port found
- pPortName contains their names
*/
INT EnumerateComPortByCreateFile(
TCHAR pPortName[8][20],
7
int strMaxLen)
{
INT i, jj=0, pNumber=0;
TCHAR pTempPortName[256];
hSerial[jj] = CreateFile(pTempPortName,
GENERIC_READ | GENERIC_WRITE,
0, NULL, OPEN_EXISTING, 0, NULL);
if (hSerial[jj] == INVALID_HANDLE_VALUE)
continue;
lstrcpy(pPortName[jj], pTempPortName);
jj++;
pNumber = jj;
}
//HeapFree(GetProcessHeap(), 0, pTempPortName);
//pTempPortName = NULL;
// *pNumber = jj;
return jj; //ret;
}/*EnumerateComPortByCreateFile*/
8
"...",
WS_CHILD|WS_VISIBLE|CBS_AUTOHSCROLL|CBS_DROPDOWN,
xpos, // ex: 200
ypos, // ex: 200
largeur, // ex: 120
hauteur, // ex: 24 ou 340
hwnd, // handle de la fenetre parent (=principale)
(HMENU) 0,
(HINSTANCE) NULL,
(LPVOID) 0
);