?? serial.cpp
字號:
/* Component of the D-ITG 2.4 Platform
*
*
* copyright : (C) 2004 by Stefano Avallone, Alessio Botta, Donato Emma,
* Salvatore Guadagno, Antonio Pescape'
* DIS Dipartimento di Informatica e Sistemistica
* (Computer Science Department)
* University of Naples "Federico II"
* email: : {stavallo, pescape}@unina.it, {abotta, demma, sguadagno}@napoli.consorzio-cini.it
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#include "serial.h"
#ifdef WIN32
HANDLE serialUp(char *nameSerial)
{
HANDLE ret = CreateFile(nameSerial,
GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING,
FILE_FLAG_OVERLAPPED, 0);
return ret;
}
void DTR_Enable(HANDLE hComm)
{
DCB dcb_app;
GetCommState(hComm,&dcb_app);
dcb_app.fDtrControl = DTR_CONTROL_ENABLE;
SetCommState(hComm,&dcb_app);
}
void DTR_Disable(HANDLE hComm)
{
DCB dcb_app;
GetCommState(hComm,&dcb_app);
dcb_app.fDtrControl = DTR_CONTROL_DISABLE;
SetCommState(hComm,&dcb_app);
}
void RTS_Enable(HANDLE hComm)
{
DCB dcb_app;
GetCommState(hComm,&dcb_app);
dcb_app.fRtsControl = RTS_CONTROL_ENABLE;
SetCommState(hComm,&dcb_app);
}
void RTS_Disable(HANDLE hComm)
{
DCB dcb_app;
GetCommState(hComm,&dcb_app);
dcb_app.fRtsControl = RTS_CONTROL_DISABLE;
SetCommState(hComm,&dcb_app);
}
#endif
#ifdef LINUX_OS
#include <string.h>
#include <unistd.h>
#include <termios.h>
#include <stropts.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/ioctl.h>
HANDLE serialUp(char *nameSerial)
{
int fd;
char stringa[]="/dev/";
strcat(stringa, nameSerial);
fd = open(stringa, O_RDWR | O_NOCTTY);
return fd;
}
void DTR_Disable(HANDLE hComm)
{
int status;
ioctl(hComm, TIOCMGET, &status);
status &= ~ TIOCM_DTR;
ioctl(hComm, TIOCMSET, &status);
}
void DTR_Enable(HANDLE hComm)
{
int status;
ioctl(hComm, TIOCMGET, &status);
status |= TIOCM_DTR;
ioctl(hComm, TIOCMSET, &status);
}
void RTS_Disable(HANDLE hComm)
{
int status;
ioctl(hComm, TIOCMGET, &status);
status &= ~ TIOCM_RTS;
ioctl(hComm, TIOCMSET, &status);
}
void RTS_Enable(HANDLE hComm)
{
int status;
ioctl(hComm, TIOCMGET, &status);
status |= TIOCM_RTS;
ioctl(hComm, TIOCMSET, &status);
}
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -