#ifndef BLUETOOTH_H
#define BLUETOOTH_H
#include <windows.h>
class Bluetooth {
public:
Bluetooth();
~Bluetooth();
void initialize();
void transmit(int right, int left);
private:
DWORD bytes_written;
BOOL Status;
HANDLE SerialHandle;
DCB SerialConfigs;
};
#endif
#ifndef BLUETOOTH_H
#define BLUETOOTH_H
#include <windows.h>
class Bluetooth {
public:
Bluetooth();
~Bluetooth();
void initialize();
void transmit(int right, int left);
private:
DWORD bytes_written;
BOOL Status;
HANDLE SerialHandle;
DCB SerialConfigs;
};
#endif
To copy to clipboard, switch view to plain text mode
#include <QDebug>
#include "bluetooth.h"
#include "settings.h"
Bluetooth::Bluetooth() {}
Bluetooth::~Bluetooth() {}
void Bluetooth::initialize() {
qDebug()<<"Initializing BlueTooth...";
Status = 0;
SerialHandle = CreateFile("COM5",
GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if(SerialHandle==INVALID_HANDLE_VALUE) {
if(GetLastError()==ERROR_FILE_NOT_FOUND) {
qDebug()<<"E: Serial Port Does Not Exist!";
}
qDebug()<<"An Error Occured!";
}
ZeroMemory(&SerialConfigs, sizeof(SerialConfigs));
SerialConfigs.DCBlength = sizeof(SerialConfigs);
if (!GetCommState(SerialHandle, &SerialConfigs)) {
qDebug()<< "Error Getting State!";
}
SerialConfigs.BaudRate = CBR_9600;
SerialConfigs.ByteSize = 8;
SerialConfigs.StopBits = ONESTOPBIT;
SerialConfigs.Parity = NOPARITY;
if(!SetCommState(SerialHandle, &SerialConfigs)) {
qDebug()<<"Error Setting Serial Port State!";
}
qDebug()<<"Initialization Done";
}
void Bluetooth::transmit(int right, int left) {
WriteFile(SerialHandle,
&right, // Outgoing data
1, // Number of bytes to write
&bytes_written, // Number of bytes written
NULL);
Status = WriteFile(SerialHandle,
&left,
1,
&bytes_written,
NULL);
if (Status == 0) {
qDebug()<<"Error Writing";
}
}
#include <QDebug>
#include "bluetooth.h"
#include "settings.h"
Bluetooth::Bluetooth() {}
Bluetooth::~Bluetooth() {}
void Bluetooth::initialize() {
qDebug()<<"Initializing BlueTooth...";
Status = 0;
SerialHandle = CreateFile("COM5",
GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if(SerialHandle==INVALID_HANDLE_VALUE) {
if(GetLastError()==ERROR_FILE_NOT_FOUND) {
qDebug()<<"E: Serial Port Does Not Exist!";
}
qDebug()<<"An Error Occured!";
}
ZeroMemory(&SerialConfigs, sizeof(SerialConfigs));
SerialConfigs.DCBlength = sizeof(SerialConfigs);
if (!GetCommState(SerialHandle, &SerialConfigs)) {
qDebug()<< "Error Getting State!";
}
SerialConfigs.BaudRate = CBR_9600;
SerialConfigs.ByteSize = 8;
SerialConfigs.StopBits = ONESTOPBIT;
SerialConfigs.Parity = NOPARITY;
if(!SetCommState(SerialHandle, &SerialConfigs)) {
qDebug()<<"Error Setting Serial Port State!";
}
qDebug()<<"Initialization Done";
}
void Bluetooth::transmit(int right, int left) {
WriteFile(SerialHandle,
&right, // Outgoing data
1, // Number of bytes to write
&bytes_written, // Number of bytes written
NULL);
Status = WriteFile(SerialHandle,
&left,
1,
&bytes_written,
NULL);
if (Status == 0) {
qDebug()<<"Error Writing";
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks