Commit 0640f524 authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

proceeding with DL1

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: 2663
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 911a1b62
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: DL1direct.cc,v 1.1 2008-11-24 15:44:15 tforb Exp $
* $Id: DL1direct.cc,v 1.2 2008-11-24 17:04:59 tforb Exp $
* \author Thomas Forbriger
* \date 24/11/2008
*
......@@ -36,15 +36,22 @@
#define DL1DIRECT_VERSION \
"DL1DIRECT V1.0 directly send command to DL1 and receive the response"
#define DL1DIRECT_CVSID \
"$Id: DL1direct.cc,v 1.1 2008-11-24 15:44:15 tforb Exp $"
"$Id: DL1direct.cc,v 1.2 2008-11-24 17:04:59 tforb Exp $"
#include <iostream>
#include <string>
#include <tfxx/commandline.h>
#include <serialxx/serialport.h>
using std::cout;
using std::cerr;
using std::endl;
struct Options {
bool verbose, timespecified;
std::string device, command,timestring;
};
int main(int iargc, char* argv[])
{
......@@ -70,6 +77,12 @@ int main(int iargc, char* argv[])
{"help",arg_no,"-"},
// 1: verbose mode
{"v",arg_no,"-"},
// 2: device file name
{"p",arg_yes,"/dev/ttyS0"},
// 3: command
{"c",arg_yes,"LL"},
// 4: time
{"t",arg_yes,"-"},
{NULL}
};
......@@ -91,6 +104,7 @@ int main(int iargc, char* argv[])
exit(0);
}
/*
// dummy operation: print option settings
for (int iopt=0; iopt<2; iopt++)
{
......@@ -112,6 +126,40 @@ int main(int iargc, char* argv[])
// dummy operation: print rest of command line
while (cmdline.extra()) { cout << cmdline.next() << endl; }
*/
Options opt;
opt.verbose=cmdline.optset(1);
opt.device=cmdline.string_arg(2);
opt.command=cmdline.string_arg(3);
opt.timespecified=cmdline.optset(4);
opt.timestring=cmdline.string_arg(4);
if (opt.verbose) { cout << "open port " << opt.device << endl; }
serialport::SerialPort port(opt.device);
if (opt.verbose) { cout << "enable xon/xoff flow control" << endl; }
port.flowxon();
if (opt.verbose) { cout << "set mode 7E1" << endl; }
port.mode7E1();
// activate DL1
if (opt.verbose) { cout << "activate DL1" << endl; }
port.write("0");
::sleep(1);
// send command
if (opt.verbose) { cout << "send command " << opt.command << endl; }
std::string commandsequence;
commandsequence.append("\x02");
commandsequence.append(opt.command);
commandsequence.append("\x03\r");
port.write(commandsequence);
// receive response
std::string response;
if (opt.verbose) { cout << "read response " << endl; }
response=port.read("END");
cout << response << endl;
}
/* ----- END OF DL1direct.cc ----- */
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: serialport.cc,v 1.2 2008-11-24 15:38:21 tforb Exp $
* $Id: serialport.cc,v 1.3 2008-11-24 17:04:59 tforb Exp $
* \author Thomas Forbriger
* \date 24/11/2008
*
......@@ -36,7 +36,7 @@
#define TF_SERIALPORT_CC_VERSION \
"TF_SERIALPORT_CC V1.0 "
#define TF_SERIALPORT_CC_CVSID \
"$Id: serialport.cc,v 1.2 2008-11-24 15:38:21 tforb Exp $"
"$Id: serialport.cc,v 1.3 2008-11-24 17:04:59 tforb Exp $"
#include <serialxx/serialport.h>
#include <serialxx/error.h>
......@@ -52,6 +52,8 @@ namespace serialport {
Mfd=open(devname.c_str(), flags);
SERIALPORT_assert(Mfd>0, "ERROR on opening port");
Mdebug=false;
::tcgetattr(Mfd, &Mdevoptions);
Musexon=false;
}
/*----------------------------------------------------------------------*/
......@@ -59,6 +61,8 @@ namespace serialport {
//! close serial port
SerialPort::~SerialPort()
{
// restore options
::tcsetattr(Mfd, TCSANOW, &Mdevoptions);
SERIALPORT_assert(close(Mfd)!=-1, "ERROR on closing port");
}
......@@ -81,6 +85,7 @@ namespace serialport {
const int nbuf=255;
char buffer[nbuf];
bool hot=true;
if (Musexon) { ::tcflow(Mfd, TCION); }
while (hot)
{
int nbytes=::read(Mfd, buffer, nbuf);
......@@ -92,9 +97,47 @@ namespace serialport {
if (nbytes>0) { retval.append(buffer, nbytes); }
if (retval.find(delim)!=std::string::npos) { hot=false; }
}
if (Musexon) { ::tcflow(Mfd, TCIOFF); }
return(retval);
}
/*----------------------------------------------------------------------*/
void SerialPort::mode7E1() const
{
struct termios options;
::tcgetattr(Mfd, &options);
options.c_cflag |= PARENB;
options.c_cflag &= ~PARODD;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS7;
::tcsetattr(Mfd, TCSANOW, &options);
} // void SerialPort::mode7E1() const
/*----------------------------------------------------------------------*/
void SerialPort::flowxon()
{
struct termios options;
::tcgetattr(Mfd, &options);
options.c_iflag |= (IXON | IXOFF | IXANY);
::tcsetattr(Mfd, TCSANOW, &options);
Musexon=true;
::tcflow(Mfd, TCIOFF);
} // void SerialPort::flowxon() const
/*----------------------------------------------------------------------*/
void SerialPort::baud9600() const
{
struct termios options;
::tcgetattr(Mfd, &options);
::cfsetispeed(&options, B9600);
::cfsetospeed(&options, B9600);
::tcsetattr(Mfd, TCSANOW, &options);
} // void SerialPort::mode7E1() const
} // namespace serialport
/* ----- END OF serialport.cc ----- */
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: serialport.h,v 1.2 2008-11-24 15:38:21 tforb Exp $
* $Id: serialport.h,v 1.3 2008-11-24 17:04:59 tforb Exp $
* \author Thomas Forbriger
* \date 24/11/2008
*
......@@ -38,12 +38,13 @@
#ifndef TF_SERIALPORT_H_VERSION
#include <fcntl.h>
#include <termios.h>
#include <string>
#define TF_SERIALPORT_H_VERSION \
"TF_SERIALPORT_H V1.0 "
#define TF_SERIALPORT_H_CVSID \
"$Id: serialport.h,v 1.2 2008-11-24 15:38:21 tforb Exp $"
"$Id: serialport.h,v 1.3 2008-11-24 17:04:59 tforb Exp $"
namespace serialport {
......@@ -62,11 +63,22 @@ namespace serialport {
std::string read(const std::string& delim="\n") const;
//! set debug mode
void debug(const bool& flag) { Mdebug=flag; }
//! set xon/xoff slow control
void flowxon();
//! set 7 data bits, even parity, 1 stop bit
void mode7E1() const;
//! select 9600 baud
void baud9600() const;
private:
//! file descriptor to this port
int Mfd;
//! debug flag
bool Mdebug;
//! remember device status
struct termios Mdevoptions;
//! use xon/xoff flow control
bool Musexon;
}; // class SerialPort
} // namespace serialport
......
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