Commit 1a3ea236 authored by Achim Morschhauser's avatar Achim Morschhauser
Browse files

Problem at startup fixed

parent 49d87ad2
......@@ -102,32 +102,20 @@ driver_obs_obsdaq::driver_obs_obsdaq(std::string port, int baud,
sprintf(addr_str, "%02X", addr);
RS485_addrstr = std::string(addr_str);
/* In development
// Check if requested baud rate is already set
if ( check_baud(baud) != 1){
// Check for baud rate with the right address.
// Stop any running measurement when doing so.
find_baud();
// Set baud rate
set_baud(baud);
// Set the ObsDAQ baud rate
*/
// Stop the measurement
//TODO Reactivate later, baud rate needs to be set when calling stop() !
//stop();
if ( check_baud(baud) != 1){
find_baud();
stop();
set_baud(baud);
} else {
stop();
}
// Check if given baud rate is correct
// Find correct baudrate if necessary
switch (check_baud(baud)) {
case 2:
stop();
break;
case 1:
break;
default:
find_baud();
stop();
set_baud(baud);
break;
}
// Initialize
init();
......@@ -688,6 +676,7 @@ int driver_obs_obsdaq::checked_send(const char* cmd, const char* reply,
}
return (-1);
}
strbuf=std::string(buf);
// Construct expected answer
......@@ -699,7 +688,7 @@ int driver_obs_obsdaq::checked_send(const char* cmd, const char* reply,
if (verbose) {
std::cerr << "Wrong address received." << " Expected: "
<< expected.substr(1, 2) << " Received: " << &buf[1]
<< std::endl;
<<std::endl;
}
return (-2);
}
......@@ -709,7 +698,7 @@ int driver_obs_obsdaq::checked_send(const char* cmd, const char* reply,
if (verbose) {
std::cerr << "Wrong answer received." << " Expected: "
<< expected.substr(3, digits) << " Received: "
<< strbuf.substr(3, digits) << std::endl;
<< strbuf.substr(3, digits) << " | " << strbuf.c_str() << std::endl;
}
return (-3);
}
......@@ -1275,6 +1264,7 @@ int driver_obs_obsdaq::check_baud(int baud){
if (Driver_Obs_Serial::set_baud(baud) < 0) {
return (-1);
}
////////////////////////////////////////////////////////////////////////
//
......@@ -1282,7 +1272,7 @@ int driver_obs_obsdaq::check_baud(int baud){
//
////////////////////////////////////////////////////////////////////////
send("$M");
//send("$M");
// Check for expected response
if (checked_send("$M","<ObsDaq",7,0.2,0) != 0) {
// No response, but freerun mode might be running, so check for data
......@@ -1292,10 +1282,16 @@ int driver_obs_obsdaq::check_baud(int baud){
}
fprintf(stderr,"N: %d\n",n);
if (n<2) {
fprintf(stderr,"----- CHECK BAUD FAILED -----\n");
return(-1);
} else {
fprintf(stderr,"----- CHECK BAUD DONE -----\n");
return(2);
}
}
fprintf(stderr,"----- CHECK BAUD DONE -----\n");
return(1);
......
......@@ -242,6 +242,8 @@ int driver_serial::receive(char *buf, int buflen, double timeout,
//
if (read(fd, &c, 1) > 0) {
//fprintf(stderr, "Received: %d %c \n",c,c);
// A correct termination character has arrived
if (c == term[n]) {
n++;
......
......@@ -37,7 +37,7 @@ int main() {
// Initialize new OBSDAQ device
driver_obs_obsdaq obsdaq = driver_obs_obsdaq(par.get_str("PORT"),
par.get_int("BAUD"), &pipe, &cal, 1);
par.get_int("BAUD"), &pipe, &cal, 0x0F);
// Get some data
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment