Cat
Public Member Functions | Protected Attributes | List of all members
NI6008 Class Reference

#include <inc/NI6008.h>

Inheritance diagram for NI6008:
Element Hierarchy Object Attrib

Public Member Functions

 NI6008 ()
 Standard constructor. More...
 
virtual ~NI6008 ()
 Destructor. More...
 
void help ()
 
StatusCode init ()
 
void reset ()
 
void update ()
 
std::string cmd (std::string, std::string)
 
int port ()
 
void setPort (int portno)
 
std::string hostname ()
 
void setHostname (std::string host)
 
std::vector< double > ai ()
 
int di ()
 
StatusCode addDevice (std::string path)
 
std::string device (unsigned int dev)
 
StatusCode clearDevice ()
 
unsigned int numberOfDevices ()
 
- Public Member Functions inherited from Element
 Element ()
 Standard constructor. More...
 
virtual ~Element ()
 Destructor. More...
 
void recursiveInitElement ()
 
void recursiveInitCommunications ()
 
StatusCode setConnection (Hierarchy *)
 
Hierarchyconnection ()
 
- Public Member Functions inherited from Hierarchy
 Hierarchy ()
 Standard constructor. More...
 
virtual ~Hierarchy ()
 Destructor. More...
 
void clear ()
 
void setParent (Hierarchy *parent)
 
Hierarchyparent ()
 
Hierarchyparent (std::string)
 
Hierarchyorigin ()
 
virtual void addChild (Hierarchy *element)
 
std::vector< Hierarchy * > children ()
 
Hierarchychild (std::string)
 
HierarchychildTyped (std::string)
 
unsigned long numberOfChildren ()
 
bool hasChildren ()
 
void delChild (Hierarchy *)
 
void delChild (std::string)
 
std::string path (std::string=std::string(""))
 
std::string pathTyped (std::string=std::string(""))
 
void tree (std::string indent=std::string(""))
 
void tree ()
 
- Public Member Functions inherited from Object
 Object ()
 Standard constructor. More...
 
virtual ~Object ()
 Destructor. More...
 
std::string name () const
 
std::string type ()
 
unsigned char id ()
 
std::string title ()
 
void msgSvc (int level, std::string msg, std::string name)
 
void msg (std::string mymsg)
 
void verbose (std::string mymsg)
 
void debug (std::string mymsg)
 
void info (std::string mymsg)
 
void warning (std::string mymsg)
 
void error (std::string mymsg)
 
void fatal (std::string mymsg)
 
void msg (std::string mymsg, std::string name)
 
void verbose (std::string mymsg, std::string name)
 
void debug (std::string mymsg, std::string name)
 
void info (std::string mymsg, std::string name)
 
void warning (std::string mymsg, std::string name)
 
void error (std::string mymsg, std::string name)
 
void fatal (std::string mymsg, std::string name)
 
void setName (std::string name)
 
void setType (std::string type)
 
void setId (unsigned char id)
 
void setTitle (std::string title)
 
void setDllName (std::string dllName)
 
std::string dllName ()
 
- Public Member Functions inherited from Attrib
 Attrib ()
 Standard constructor. More...
 
virtual ~Attrib ()
 Destructor. More...
 
bool is (int attribut)
 
void add (int attribut)
 
void remove (int attribut)
 
std::string attributs ()
 

Protected Attributes

int m_portno
 
std::string m_host
 
std::vector< std::string > m_device
 
int m_sockfd
 
struct sockaddr_in m_serv_addr
 
struct hostent * m_server
 
char buffer [256]
 
- Protected Attributes inherited from Element
Hierarchym_connection
 
- Protected Attributes inherited from Attrib
std::string m_attribString [10]
 

Additional Inherited Members

- Public Types inherited from Attrib
enum  Attribut {
  UNDEFINED, PASSIVE, ACTIVE, INTERFACE,
  IO, IODATA, ELEMENT, HARDWARE,
  PROCESSUS, SOFTWARE
}
 

Detailed Description

Author
NI6008
Date
2006-10-23

Definition at line 26 of file NI6008.h.

Constructor & Destructor Documentation

◆ NI6008()

NI6008::NI6008 ( )

Standard constructor.

Definition at line 22 of file NI6008.cpp.

References application(), Application::hostname(), m_host, Object::setName(), and Object::setType().

22  {
23  setName("NI6008");
24  setType("NI6008");
26 }
void setName(std::string name)
Definition: Object.h:51
std::string hostname()
Definition: Application.h:173
Application * application()
Definition: Tools.cpp:42
void setType(std::string type)
Definition: Object.h:52
std::string m_host
Definition: NI6008.h:139

◆ ~NI6008()

NI6008::~NI6008 ( )
virtual

Destructor.

Definition at line 30 of file NI6008.cpp.

References Object::info(), and m_sockfd.

30  {
31  info("Closing the NI6008 socket.");
32  close(m_sockfd);
33 }
void info(std::string mymsg)
Definition: Object.h:38
int m_sockfd
Definition: NI6008.h:141

Member Function Documentation

◆ addDevice()

StatusCode NI6008::addDevice ( std::string  path)
inline

Definition at line 114 of file NI6008.h.

References Object::info(), m_device, and StatusCode::SUCCESS.

Referenced by BOOST_PYTHON_MODULE().

114  {
115  m_device.push_back( path );
116  info("Device associated.");
117  return StatusCode::SUCCESS;
118  };
void info(std::string mymsg)
Definition: Object.h:38
std::vector< std::string > m_device
Definition: NI6008.h:140
std::string path(std::string=std::string(""))
Definition: Hierarchy.cpp:344

◆ ai()

std::vector<double> NI6008::ai ( )

Referenced by setHostname().

◆ clearDevice()

StatusCode NI6008::clearDevice ( )
inline

Definition at line 128 of file NI6008.h.

References m_device, and StatusCode::SUCCESS.

Referenced by BOOST_PYTHON_MODULE().

128  {
129  m_device.clear();
130  return StatusCode::SUCCESS;
131  }
std::vector< std::string > m_device
Definition: NI6008.h:140

◆ cmd()

std::string NI6008::cmd ( std::string  dev,
std::string  mess 
)

Definition at line 38 of file NI6008.cpp.

References buffer, Object::error(), and m_sockfd.

Referenced by BOOST_PYTHON_MODULE(), CurrentMeasurement::execute(), ADCMeasurement::execute(), and update().

38  {
39  int n;
40  std::string cmd = dev + std::string(" ") + mess;
41  std::copy(cmd.begin(), cmd.end(), buffer);
42  // strcat(buffer, " ");
43  // strcat(buffer, mess.c_str());
44  buffer[cmd.size()] = '\0';
45  // std::cout<<"sending:"<<buffer<<" length="<<strlen(buffer)<<std::endl;
46  n = write(m_sockfd,buffer,strlen(buffer));
47  if (n < 0) error("ERROR writing to socket");
48  bzero(buffer,256);
49  n = read(m_sockfd,buffer,255);
50  if (n < 0) error("ERROR reading from socket");
51  // printf("%s\n",buffer);
52  return std::string(buffer);
53 }
char buffer[256]
Definition: NI6008.h:144
int m_sockfd
Definition: NI6008.h:141
void error(std::string mymsg)
Definition: Object.h:40
std::string cmd(std::string, std::string)
Definition: NI6008.cpp:38

◆ device()

std::string NI6008::device ( unsigned int  dev)
inline

Definition at line 120 of file NI6008.h.

References m_device, and Object::warning().

Referenced by BOOST_PYTHON_MODULE(), CurrentMeasurement::execute(), and CurrentMeasurement::initialize().

120  {
121  if (dev>m_device.size()-1){
122  warning("Device not defined.");
123  return NULL;
124  }
125  return m_device[dev];
126  }
std::vector< std::string > m_device
Definition: NI6008.h:140
void warning(std::string mymsg)
Definition: Object.h:39

◆ di()

int NI6008::di ( )

Referenced by setHostname().

◆ help()

void NI6008::help ( )
inlinevirtual

printout help for the element

Implements Element.

Definition at line 37 of file NI6008.h.

References Object::info(), and Object::name().

Referenced by BOOST_PYTHON_MODULE().

37 { info("NI6008 "+name()+". No help.","NI6008::help"); };
void info(std::string mymsg)
Definition: Object.h:38
std::string name() const
Definition: Object.h:28

◆ hostname()

std::string NI6008::hostname ( )
inline

Define/get device Define/get server hostname

Definition at line 108 of file NI6008.h.

References m_host.

Referenced by BOOST_PYTHON_MODULE().

108 { return m_host; }
std::string m_host
Definition: NI6008.h:139

◆ init()

StatusCode NI6008::init ( )
inlinevirtual

init the component

Returns
void

Implements Element.

Definition at line 43 of file NI6008.h.

References Object::error(), StatusCode::FAILURE, Object::info(), itos(), m_host, m_portno, m_serv_addr, m_server, m_sockfd, Object::name(), and StatusCode::SUCCESS.

Referenced by BOOST_PYTHON_MODULE().

43  {
44  info("NI6008 "+name()+" initialization.","NI6008:init");
45 
46  /* if (m_device==std::string("")){ */
47  /* error("Device has not been device before opening the server connection. Interrupt."); */
48  /* } */
49 
50  m_sockfd = socket(AF_INET, SOCK_STREAM, 0);
51  if (m_sockfd < 0) {
52  error("ERROR opening socket");
53  return StatusCode::FAILURE;
54  }
55  m_server = gethostbyname(m_host.c_str());
56  if (m_server == NULL) {
57  error("ERROR connecting to host "+m_host+".");
58  return StatusCode::FAILURE;
59  }
60  bzero((char *) &m_serv_addr, sizeof(m_serv_addr));
61  m_serv_addr.sin_family = AF_INET;
62  bcopy((char *)m_server->h_addr,
63  (char *)&m_serv_addr.sin_addr.s_addr,
64  m_server->h_length);
65  m_serv_addr.sin_port = htons(m_portno);
66  if (connect(m_sockfd,(struct sockaddr *) &m_serv_addr,sizeof(m_serv_addr)) < 0) {
67  error("ERROR connecting to the socket.");
68  return StatusCode::FAILURE;
69  }
70  info("Starting client, connecting to host "+m_host+" on port "+itos(m_portno));
71  return StatusCode::SUCCESS;
72  }
void info(std::string mymsg)
Definition: Object.h:38
std::string itos(int)
Definition: Tools.cpp:46
struct sockaddr_in m_serv_addr
Definition: NI6008.h:142
int m_sockfd
Definition: NI6008.h:141
int m_portno
Definition: NI6008.h:138
void error(std::string mymsg)
Definition: Object.h:40
struct hostent * m_server
Definition: NI6008.h:143
std::string name() const
Definition: Object.h:28
std::string m_host
Definition: NI6008.h:139

◆ numberOfDevices()

unsigned int NI6008::numberOfDevices ( )
inline

Definition at line 133 of file NI6008.h.

References m_device.

Referenced by BOOST_PYTHON_MODULE(), CurrentMeasurement::execute(), CurrentMeasurement::initialize(), and ADCMeasurement::numberOfDevices().

133  {
134  return m_device.size();
135  }
std::vector< std::string > m_device
Definition: NI6008.h:140

◆ port()

int NI6008::port ( )
inline

Define/get server port number

Definition at line 96 of file NI6008.h.

References m_portno.

Referenced by BOOST_PYTHON_MODULE().

96 { return m_portno; }
int m_portno
Definition: NI6008.h:138

◆ reset()

void NI6008::reset ( )
inlinevirtual

Resets the Element so that is is in a standard and safe situation. Different from Element::init which configure the Element. Element::reset() is more an Emergency pull. It is often/usually called by the recursiveInitElement method at the start of the program.

Implements Element.

Definition at line 81 of file NI6008.h.

References Object::info(), and Object::name().

Referenced by BOOST_PYTHON_MODULE().

81 { info("NI6008 "+name()+" reset.","NI6008::reset");};
void info(std::string mymsg)
Definition: Object.h:38
std::string name() const
Definition: Object.h:28

◆ setHostname()

void NI6008::setHostname ( std::string  host)
inline

Definition at line 109 of file NI6008.h.

References ai(), di(), and m_host.

Referenced by BOOST_PYTHON_MODULE().

109 { m_host = host; }
std::string m_host
Definition: NI6008.h:139

◆ setPort()

void NI6008::setPort ( int  portno)
inline

Definition at line 97 of file NI6008.h.

References m_portno.

Referenced by BOOST_PYTHON_MODULE().

97 { m_portno = portno; }
int m_portno
Definition: NI6008.h:138

◆ update()

void NI6008::update ( )
inlinevirtual

Update the Element configuration from the actual hardware

Implements Element.

Definition at line 86 of file NI6008.h.

References cmd(), Object::info(), and Object::name().

Referenced by BOOST_PYTHON_MODULE(), AppFrame.AppFrame::deleteHardware(), ConfFrame.ConfFrame::onChange(), GraphFrame.GraphFrame::onChange(), CfgFrame.CfgFrame::onChange(), ConfFrame.ConfFrame::onEdit(), AppFrame.AppFrame::onLoad(), ConfFrame.ConfFrame::onReLoad(), GraphFrame.GraphFrame::onReLoad(), CfgFrame.CfgFrame::onReLoad(), and AppFrame.AppFrame::onReLoad().

86 {info("NI6008 "+name()+". Nothing to do.","NI6008::update");};
void info(std::string mymsg)
Definition: Object.h:38
std::string name() const
Definition: Object.h:28

Member Data Documentation

◆ buffer

char NI6008::buffer[256]
protected

Definition at line 144 of file NI6008.h.

Referenced by cmd().

◆ m_device

std::vector<std::string> NI6008::m_device
protected

Definition at line 140 of file NI6008.h.

Referenced by addDevice(), clearDevice(), device(), and numberOfDevices().

◆ m_host

std::string NI6008::m_host
protected

Definition at line 139 of file NI6008.h.

Referenced by hostname(), init(), NI6008(), and setHostname().

◆ m_portno

int NI6008::m_portno
protected

Definition at line 138 of file NI6008.h.

Referenced by init(), port(), and setPort().

◆ m_serv_addr

struct sockaddr_in NI6008::m_serv_addr
protected

Definition at line 142 of file NI6008.h.

Referenced by init().

◆ m_server

struct hostent* NI6008::m_server
protected

Definition at line 143 of file NI6008.h.

Referenced by init().

◆ m_sockfd

int NI6008::m_sockfd
protected

Definition at line 141 of file NI6008.h.

Referenced by cmd(), init(), and ~NI6008().


The documentation for this class was generated from the following files: