qmca  0.0.20
epicsboolean.cpp
Go to the documentation of this file.
1 #include "epicsboolean.h"
2 
3 #include <stdio.h>
4 
5 EpicsBoolean::EpicsBoolean(QString pvName, QObject *parent, int debug)
6  : EpicsObject(pvName, parent, debug),
7  m_Value(0)
8 {
9 }
10 
12 {
13 }
14 
16 {
17  caput(true);
18 }
19 
21 {
22  caput(false);
23 }
24 
25 void EpicsBoolean::event_handler(struct event_handler_args args)
26 {
27  union db_access_val *pb = (union db_access_val *) args.dbr;
28 
29  bool res=0;
30 
31  switch (args.type) {
32  case DBR_SHORT:
33  res = pb->shrtval;
34  break;
35  case DBR_LONG:
36  res = pb->longval;
37  break;
38  case DBR_FLOAT:
39  res = pb->fltval;
40  break;
41  case DBR_ENUM:
42  res = pb->enmval;
43  break;
44  case DBR_CHAR:
45  res = pb->charval;
46  break;
47  case DBR_DOUBLE:
48  res = pb->doubleval;
49  break;
50  default:
51  printf("data type %ld not supported\n", args.type);
52  }
53 
54 // printf("%s Epics Boolean Event Handler called %ld = %d\n", ca_name(args.chid), args.type, res);
55 
56  ((EpicsBoolean*) args.usr) -> changeValue(res);
57 }
58 
59 caEventCallBackFunc *EpicsBoolean::get_event_handler()
60 {
62 }
63 
64 void EpicsBoolean::changeValue(bool newval)
65 {
66 // printf("ca_put(%d,%p,%g)\n", DBR_INT, channelID(), newval);
67 
68 // ca_put(DBR_INT, channelID(), &newval);
69 
70  QMutexLocker lock(&m_Mutex);
71 
72  if (m_Value != newval) {
73 
74  m_Value = newval;
75  emit valueChanged(m_Value);
76  }
77 }
78 
79 void EpicsBoolean::caput(bool val)
80 {
81  int nval = val;
82 
83  ca_put(DBR_INT, channelID(), &nval);
84  ca_pend_io(0.5);
85 }
86 
88 {
89  QMutexLocker lock(&m_Mutex);
90 
91  return m_Value;
92 }
virtual caEventCallBackFunc * get_event_handler()
EpicsBoolean(QString pvName, QObject *parent=0, int debug=0)
Definition: epicsboolean.cpp:5
void changeValue(bool val)
static void event_handler(struct event_handler_args arg)
void valueChanged()
static QMutex m_Mutex
Definition: epicsobject.h:42
chid channelID()
Definition: epicsobject.cpp:63
void ca_pend_io(double t)
virtual ~EpicsBoolean()
void caput(bool val)