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