ucomport.cpp
111 lines
| 2.8 KiB
| text/x-c
|
CppLexer
/ src / ucomport.cpp
|
r4 | /*------------------------------------------------------------------------------ | ||
-- This file is a part of the Uprobe Software | ||||
-- Copyright (C) 2014, Plasma Physics Laboratory - CNRS | ||||
-- | ||||
-- 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. | ||||
-- | ||||
-- This program is distributed in the hope that it will be useful, | ||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
-- GNU General Public License for more details. | ||||
-- | ||||
-- You should have received a copy of the GNU General Public License | ||||
-- along with this program; if not, write to the Free Software | ||||
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||||
-------------------------------------------------------------------------------*/ | ||||
/*-- Author : Alexis Jeandet | ||||
-- Mail : alexis.jeandet@member.fsf.org | ||||
-- Author : Kaveh Mohamadabadi | ||||
-- Mail : kaveh.mohamadabadi@lpp.polytechnique.fr | ||||
--------------------------------------------------------------------------------*/ | ||||
|
r2 | #include "ucomport.h" | ||
UComPort::UComPort() | ||||
{ | ||||
this->p_portMutex = new QMutex(); | ||||
this->p_opened = false; | ||||
} | ||||
QString UComPort::portName() | ||||
{ | ||||
QMutexLocker locker(this->p_portMutex); | ||||
return p_PortName; | ||||
} | ||||
int UComPort::speed() | ||||
{ | ||||
QMutexLocker locker(this->p_portMutex); | ||||
return p_speed; | ||||
} | ||||
void UComPort::setPortName(const QString &name) | ||||
{ | ||||
QMutexLocker locker(this->p_portMutex); | ||||
this->p_PortName = name; | ||||
} | ||||
void UComPort::setSpeed(int speed) | ||||
{ | ||||
QMutexLocker locker(this->p_portMutex); | ||||
this->p_speed = speed; | ||||
} | ||||
bool UComPort::open() | ||||
{ | ||||
QMutexLocker locker(this->p_portMutex); | ||||
if(p_opened) | ||||
{ | ||||
rs232close(this->p_port); | ||||
this->p_opened = false; | ||||
} | ||||
this->p_port = rs232open((char*)p_PortName.toStdString().c_str()); | ||||
if(this->p_port!=badPortValue) | ||||
{ | ||||
rs232setup(this->p_port,8,this->p_speed,rs232parityNo,rs232OneStop); | ||||
p_opened = true; | ||||
} | ||||
|
r3 | return p_opened; | ||
} | ||||
bool UComPort::close() | ||||
{ | ||||
if(p_opened) | ||||
{ | ||||
p_opened = rs232close(this->p_port); | ||||
} | ||||
return !p_opened; | ||||
} | ||||
bool UComPort::opened() | ||||
{ | ||||
return p_opened; | ||||
|
r2 | } | ||
bool UComPort::open(const QString &name, int speed) | ||||
{ | ||||
setPortName(name); | ||||
setSpeed(speed); | ||||
return open(); | ||||
} | ||||
|
r3 | |||
int UComPort::availableBytes() | ||||
{ | ||||
if(p_opened) | ||||
{ | ||||
return rs232availablebytes(this->p_port); | ||||
} | ||||
return 0; | ||||
} | ||||
int UComPort::readBytes(char *data, int count) | ||||
{ | ||||
return rs232read(this->p_port,data,count); | ||||
} | ||||
int UComPort::writeBytes(char *data, int count) | ||||
{ | ||||
return rs232write(this->p_port,data,count); | ||||
} | ||||