mirror of
https://github.com/libretro/Mu.git
synced 2026-04-30 18:20:25 +00:00
32 lines
702 B
C++
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;
|
|
}
|