Files
Mu/localTester/LocalTester/serialportio.cpp
meepingsnesroms 03a9358375 Start making LocalTester threaded
Currenlty compiles, may not run properly
2018-05-22 15:08:11 -07:00

32 lines
702 B
C++

#include <QObject>
#include <fcntl.h>
#include <unistd.h>
#include <stdint.h>
#include <stdexcept>
#include "serialportio.h"
SerialPortIO::SerialPortIO(QString serialDeviceFilePath) : QObject(nullptr){
deviceFilePath = serialDeviceFilePath;
deviceFile = open(serialDeviceFilePath.toStdString().c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK);
if(deviceFile < 0)
throw std::invalid_argument("Cant open file!");
}
SerialPortIO::~SerialPortIO(){
deviceFilePath.clear();
close(deviceFile);
}
void SerialPortIO::transmitUint8(uint8_t data){
write(deviceFile, &data, 1);
}
uint8_t SerialPortIO::receiveUint8(){
uint8_t data = 0x00;
read(deviceFile, &data, 1);
return data;
}