##// END OF EJS Templates
Protocole written but not tested yet.
Protocole written but not tested yet.

File last commit:

r3:66fd6489c66a default
r3:66fd6489c66a default
Show More
ucomport.cpp
88 lines | 1.5 KiB | text/x-c | CppLexer
#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;
}
return p_opened;
}
bool UComPort::close()
{
if(p_opened)
{
p_opened = rs232close(this->p_port);
}
return !p_opened;
}
bool UComPort::opened()
{
return p_opened;
}
bool UComPort::open(const QString &name, int speed)
{
setPortName(name);
setSpeed(speed);
return open();
}
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);
}