Commit 79cb40d2 authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

operates

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 2669
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent d5ed0bb5
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: DL1direct.cc,v 1.3 2008-11-25 09:46:15 tforb Exp $
* $Id: DL1direct.cc,v 1.4 2008-11-25 10:22:30 tforb Exp $
* \author Thomas Forbriger
* \date 24/11/2008
*
......@@ -36,7 +36,7 @@
#define DL1DIRECT_VERSION \
"DL1DIRECT V1.0 directly send command to DL1 and receive the response"
#define DL1DIRECT_CVSID \
"$Id: DL1direct.cc,v 1.3 2008-11-25 09:46:15 tforb Exp $"
"$Id: DL1direct.cc,v 1.4 2008-11-25 10:22:30 tforb Exp $"
#include <iostream>
#include <string>
......@@ -145,7 +145,7 @@ int main(int iargc, char* argv[])
// receive response
const int timeout=2;
while (true) { cout << port.getline(timeout) << endl; }
while (true) { cout << "L: " << port.getline(timeout) << endl; }
}
/* ----- END OF DL1direct.cc ----- */
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.3 2008-11-25 09:46:15 tforb Exp $
# $Id: Makefile,v 1.4 2008-11-25 10:22:30 tforb Exp $
#
# Copyright (c) 2008 by Thomas Forbriger (BFO Schiltach)
#
......@@ -63,6 +63,8 @@ CPPFLAGS=-I$(LOCINCLUDEDIR) $(FLAGS)
> $@; \
[ -s $@ ] || rm -f $@'
-include $(patsubst %.cc,%.d,$(wildcard *.cc))
#======================================================================
# documentation part
# ------------------
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: thiesdl1.cc,v 1.3 2008-11-25 09:46:16 tforb Exp $
* $Id: thiesdl1.cc,v 1.4 2008-11-25 10:22:30 tforb Exp $
* \author Thomas Forbriger
* \date 25/11/2008
*
......@@ -36,7 +36,7 @@
#define TF_THIESDL1_CC_VERSION \
"TF_THIESDL1_CC V1.0 "
#define TF_THIESDL1_CC_CVSID \
"$Id: thiesdl1.cc,v 1.3 2008-11-25 09:46:16 tforb Exp $"
"$Id: thiesdl1.cc,v 1.4 2008-11-25 10:22:30 tforb Exp $"
#include "thiesdl1.h"
#include<iostream>
......@@ -67,6 +67,8 @@ namespace dl1 {
Mport.flowxon();
if (Mdebug) { cout << "DL1 (DEBUG): set mode 7E1" << endl; }
Mport.mode7E1();
if (Mdebug) { cout << "DL1 (DEBUG): clear input buffer" << endl; }
this->Minput.clear();
}
/*----------------------------------------------------------------------*/
......@@ -94,26 +96,41 @@ namespace dl1 {
/*----------------------------------------------------------------------*/
std::string DL1::getline(const int& timeout) const
std::string DL1::getline(const int& timeout)
{
std::string retval;
libtime::TAbsoluteTime now=libtime::utc();
const int nbuf=255;
const std::string eolstring(DL1::EOL);
char buffer[nbuf];
bool hot=true;
bool timeisout=false;
Mport.sendxon();
// enter loop until
// 1. EOL is found
// 2. or timeout
while (hot)
{
// read data from port
int nbytes=Mport.read(buffer, nbuf);
if (Mdebug)
{
std::cout << "DL1 (DEBUG): " << std::endl
<< "read " << nbytes << " characters" << std::endl;
}
if (nbytes>0) { retval.append(buffer, nbytes); }
if (retval.find(DL1::EOL)!=std::string::npos) { hot=false; }
if (timeout>0)
// append to input buffer
if (nbytes>0) { this->Minput.append(buffer, nbytes); }
// look for EOL
unsigned int eolpos=this->Minput.find(DL1::EOL);
// extract line if EOL was found
if (eolpos!=std::string::npos)
{
retval=this->Minput.substr(0, eolpos);
this->Minput.erase(0, eolpos+eolstring.length());
hot=false;
}
// check for timeout otherwise
else if (timeout>0)
{
libtime::TRelativeTime passed=libtime::utc()-now;
int seconds=int(libtime::time2double(passed));
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: thiesdl1.h,v 1.3 2008-11-25 09:46:16 tforb Exp $
* $Id: thiesdl1.h,v 1.4 2008-11-25 10:22:31 tforb Exp $
* \author Thomas Forbriger
* \date 25/11/2008
*
......@@ -40,7 +40,7 @@
#define TF_THIESDL1_H_VERSION \
"TF_THIESDL1_H V1.0 "
#define TF_THIESDL1_H_CVSID \
"$Id: thiesdl1.h,v 1.3 2008-11-25 09:46:16 tforb Exp $"
"$Id: thiesdl1.h,v 1.4 2008-11-25 10:22:31 tforb Exp $"
#include<serialxx/serialport.h>
#include<libtime++.h>
......@@ -64,7 +64,7 @@ namespace dl1 {
* throw TimeOut if time spent is larger than timeout seconds
* and timeout > 0
*/
std::string getline(const int& timeout=0) const;
std::string getline(const int& timeout=0);
//! send command string
void sendcommand(const std::string& command,
const bool& activate=true) const;
......@@ -111,6 +111,8 @@ namespace dl1 {
serialport::SerialPort Mport;
//! debug mode
bool Mdebug;
//! maintein input buffer for reading from DL1
std::string Minput;
}; // class DL1
} // namespace dl1
......
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