Repository navigation
Expand file tree
/
Copy pathtestEpicsProxy.cpp
More file actions
96 lines (77 loc) · 3.18 KB
/
Copy pathtestEpicsProxy.cpp
File metadata and controls
96 lines (77 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <iostream>
#include <string>
#include <unistd.h>
#include <bitset>
#include "EpicsProxy.h"
#include "epicsCallbacks.h"
using namespace epics;
int main() {
try {
struct caConfig conf;
conf.ca_addr_list = getenv("EPICS_CA_ADDR_LIST");
conf.ca_auto_addr_list = getenv("EPICS_CA_AUTO_ADDR_LIST");
conf.ca_conn_tmo = "30.0";
conf.ca_beacon_period = "15.0";
conf.ca_repeater_port = "5065";
conf.ca_server_port = "5064";
conf.ca_max_array_bytes = "16384";
conf.ts_min_west = "360";
//List of PVs to create
std::string pvDev = std::string("devices");
EpicsProxy proxy("name");
proxy.init("sans:",
{pvDev},
conf);
/*
std::string pvName = std::string(".VAL");
std::string pvStatus = std::string(".MSTA");
std::string pvReadback = std::string(".RBV");
std::string pvStop = std::string(".STOP");
std::vector<std::string> pvNames = {pvDev, pvName, pvStatus, pvReadback, pvStop};
//Initialize the EPICS context
EpicsProxy proxy("name");
proxy.init("sans:motor[sim_motor]:2-",
pvNames,
conf);
//Add a monitor to the status PV
proxy.add_monitor(pvStatus, &proxy, &epics::msta_monitor_callback);
//Read the current position
double pos = proxy.read_pv<double>(pvReadback);
std::cout << "Current position: " << pos << std::endl;
unsigned long stat = proxy.get_current_status();
std::cout << "Status: " << stat << std::endl;
//Write a new position
double new_position = 25.0;
proxy.write_pv<double>(pvName, new_position);
while (true) {
pos = proxy.read_pv<double>(pvReadback);
std::cout << "Current position: " << pos << std::endl;
stat = proxy.get_current_status();
std::cout << "Status: " << stat << std::endl;
sleep(1.0);
if (pos >= new_position - 0.1 && pos <= new_position + 0.1) {
break;
}
}
//Read the final position
std::cout << "Final position: " << proxy.read_pv<double>(pvReadback) << std::endl;
stat = proxy.get_current_status();
std::cout << "Status: " << stat << std::endl;
*/
//Read the array of char stored at sans:devices
std::vector<char> array = proxy.read_pv_array<char>(pvDev);
//Print the array as a string
std::cout << "Array: " << std::string(array.begin(), array.end()) << std::endl;
//Write a new array of char to sans:devices
std::cout << "Writing new array to PV " << pvDev << std::endl;
std::vector<char> new_array = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'j'};
proxy.write_pv_array<char>(pvDev, new_array);
//Read the array of char stored at sans:devices
array = proxy.read_pv_array<char>(pvDev);
//Print the new array as a string
std::cout << "Array: " << std::string(array.begin(), array.end()) << std::endl;
} catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
}
return 0;
}