⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serial.cpp

📁 D-ITG2.4源代码
💻 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 + -