reading partially works
This commit is contained in:
parent
724b025795
commit
5543d707df
@ -33,6 +33,12 @@ int GcLogger::run() {
|
|||||||
string deviceVersion = device->getVersion();
|
string deviceVersion = device->getVersion();
|
||||||
cout << "GMC Device version: " << deviceVersion << endl;
|
cout << "GMC Device version: " << deviceVersion << endl;
|
||||||
|
|
||||||
|
int cpm = device->getCPM();
|
||||||
|
cout << "CPM: " << cpm << endl;
|
||||||
|
|
||||||
|
float temperature = device->getTemperature();
|
||||||
|
cout << "Temperature: " << temperature << endl;
|
||||||
|
|
||||||
device->close();
|
device->close();
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,9 @@ int GmcDevice::getCPM() {
|
|||||||
string result;
|
string result;
|
||||||
|
|
||||||
if(device->serialWrite(cmd) == cmd.length()) {
|
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];
|
return result[0] * 256 + result[1];
|
||||||
@ -52,7 +54,9 @@ float GmcDevice::getTemperature() {
|
|||||||
string result;
|
string result;
|
||||||
|
|
||||||
if(device->serialWrite(cmd) == cmd.length()) {
|
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;
|
int sign = result[2] == 0 ? 1 : -1;
|
||||||
@ -72,7 +76,9 @@ string GmcDevice::getVersion() {
|
|||||||
string result;
|
string result;
|
||||||
|
|
||||||
if(device->serialWrite(cmd) == cmd.length()) {
|
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;
|
return result;
|
||||||
@ -84,6 +90,15 @@ bool GmcDevice::setHeartbeatOff() {
|
|||||||
return false;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,11 +60,18 @@ SerialPort::~SerialPort() {
|
|||||||
serialClose();
|
serialClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
int SerialPort::serialRead(string buffer, int length) {
|
string SerialPort::serialRead(int length) {
|
||||||
return read(fd, buffer.data(), 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) {
|
int SerialPort::serialWrite(const string &data) {
|
||||||
return write(fd, data.c_str(), data.length());
|
return write(fd, data.c_str(), data.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ public:
|
|||||||
bool isOpen();
|
bool isOpen();
|
||||||
bool serialClose();
|
bool serialClose();
|
||||||
|
|
||||||
int serialRead(string, int);
|
string serialRead(int);
|
||||||
int serialWrite(const string&);
|
int serialWrite(const string&);
|
||||||
bool clearInput(int);
|
bool clearInput(int);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user