reading partially works
This commit is contained in:
parent
724b025795
commit
5543d707df
@ -33,6 +33,12 @@ int GcLogger::run() {
|
||||
string deviceVersion = device->getVersion();
|
||||
cout << "GMC Device version: " << deviceVersion << endl;
|
||||
|
||||
int cpm = device->getCPM();
|
||||
cout << "CPM: " << cpm << endl;
|
||||
|
||||
float temperature = device->getTemperature();
|
||||
cout << "Temperature: " << temperature << endl;
|
||||
|
||||
device->close();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@ -36,7 +36,9 @@ int GmcDevice::getCPM() {
|
||||
string result;
|
||||
|
||||
if(device->serialWrite(cmd) == cmd.length()) {
|
||||
device->serialRead(result, 2); // cpm result has size 2
|
||||
result = device->serialRead(2); // cpm result has size 2
|
||||
} else {
|
||||
cout << "Failed to send command to device!" << endl;
|
||||
}
|
||||
|
||||
return result[0] * 256 + result[1];
|
||||
@ -52,7 +54,9 @@ float GmcDevice::getTemperature() {
|
||||
string result;
|
||||
|
||||
if(device->serialWrite(cmd) == cmd.length()) {
|
||||
device->serialRead(result, 4); // temp result has size 4
|
||||
result = device->serialRead(4); // temp result has size 4
|
||||
} else {
|
||||
cout << "Failed to send command to device!" << endl;
|
||||
}
|
||||
|
||||
int sign = result[2] == 0 ? 1 : -1;
|
||||
@ -72,7 +76,9 @@ string GmcDevice::getVersion() {
|
||||
string result;
|
||||
|
||||
if(device->serialWrite(cmd) == cmd.length()) {
|
||||
device->serialRead(result, 14); // version result has size 14
|
||||
result = device->serialRead(14); // version result has size 14
|
||||
} else {
|
||||
cout << "Failed to send command to device!" << endl;
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -84,6 +90,15 @@ bool GmcDevice::setHeartbeatOff() {
|
||||
return false;
|
||||
}
|
||||
|
||||
string cmd = "<HEARTBEAT0>>";
|
||||
string result;
|
||||
|
||||
if(device->serialWrite(cmd) == cmd.length()) {
|
||||
return device->clearInput(100); // clear 100 chars
|
||||
} else {
|
||||
cout << "Failed to send command to device!" << endl;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -60,8 +60,15 @@ SerialPort::~SerialPort() {
|
||||
serialClose();
|
||||
}
|
||||
|
||||
int SerialPort::serialRead(string buffer, int length) {
|
||||
return read(fd, buffer.data(), length);
|
||||
string SerialPort::serialRead(int length) {
|
||||
char *buf = (char *) calloc(length + 1, sizeof(char));
|
||||
|
||||
read(fd, buf, length);
|
||||
|
||||
string result(buf);
|
||||
free(buf);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int SerialPort::serialWrite(const string &data) {
|
||||
|
@ -30,7 +30,7 @@ public:
|
||||
bool isOpen();
|
||||
bool serialClose();
|
||||
|
||||
int serialRead(string, int);
|
||||
string serialRead(int);
|
||||
int serialWrite(const string&);
|
||||
bool clearInput(int);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user