Skip to content

Commit 312b69a

Browse files
kwang428yuyichao
authored andcommitted
update awg backend for timeout of messages
1 parent a33b3bd commit 312b69a

2 files changed

Lines changed: 32 additions & 11 deletions

File tree

lib/nacs-seq/awg/backend.cpp

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ void Backend::pre_run(HostSeq &host_seq)
606606
auto conf_reply = m_sock->send_msg([&] (auto &sock) {
607607
ZMQ::send_more(sock, ZMQ::str_msg("set_out_config"));
608608
ZMQ::send(sock, zmq::message_t(config_msg.data(), config_msg.size()));
609-
}).get();
609+
}, 1000).get();
610610
if (conf_reply.empty())
611611
throw std::runtime_error("did not get reply from server");
612612
std::string conf_reply_str((char*) conf_reply[0].data(), conf_reply[0].size());
@@ -678,7 +678,7 @@ void Backend::pre_run(HostSeq &host_seq)
678678
ZMQ::send_more(sock, ZMQ::bits_msg(version));
679679
ZMQ::send_more(sock, zmq::message_t(id_bc.data(), id_bc.size()));
680680
ZMQ::send(sock, zmq::message_t(next_msg.data(), next_msg.size()));
681-
}).get();
681+
}, 1000).get();
682682
// handle response
683683
if (reply.empty())
684684
throw std::runtime_error("did not get reply from server");
@@ -719,14 +719,28 @@ void Backend::cancel(HostSeq &host_seq)
719719
}
720720
void Backend::wait(HostSeq &host_seq)
721721
{
722-
m_sock->send_msg([&] (auto &sock) {
723-
ZMQ::send_more(sock, ZMQ::str_msg("wait_seq"));
724-
ZMQ::send(sock, ZMQ::bits_msg(m_cur_wait_id));
725-
}).wait();
722+
try {
723+
m_sock->send_msg([&] (auto &sock) {
724+
ZMQ::send_more(sock, ZMQ::str_msg("wait_seq"));
725+
ZMQ::send(sock, ZMQ::bits_msg(m_cur_wait_id));
726+
}, 1000).wait();
727+
}
728+
catch (...) {
729+
error_during_seq = true;
730+
}
726731
}
727732
void Backend::post_run(HostSeq &host_seq)
728733
{
729-
refresh_restart();
734+
try {
735+
refresh_restart();
736+
}
737+
catch (...) {
738+
error_during_seq = true;
739+
}
740+
if (error_during_seq) {
741+
throw awg_seq_error("AWG error during sequence execution. Most likely due to timeout.");
742+
error_during_seq = false;
743+
}
730744
}
731745
uint8_t Backend::get_pulse_type(Backend::ChnType type, bool is_fn, bool is_vector){
732746
// map from chn_info and whether it's a vector to a uint8_t describing the pulse type
@@ -831,21 +845,21 @@ NACS_EXPORT() void Backend::reqServerInfo()
831845
else {
832846
auto reply = m_sock->send_msg([&] (auto &sock) {
833847
ZMQ::send(sock, ZMQ::str_msg("req_client_id"));
834-
}).get();
848+
}, 1000).get();
835849
if (reply.empty())
836850
throw std::runtime_error("client id not obtained");
837851
auto rep_data = (const uint8_t*)reply[0].data();
838852
memcpy(&m_client_id, rep_data, sizeof(m_client_id));
839853
reply = m_sock->send_msg([&] (auto &sock) {
840854
ZMQ::send(sock, ZMQ::str_msg("req_server_id"));
841-
}).get();
855+
}, 1000).get();
842856
if (reply.empty())
843857
throw std::runtime_error("server id not obtained");
844858
rep_data = (const uint8_t*)reply[0].data();
845859
memcpy(&m_server_id, rep_data, sizeof(m_server_id));
846860
reply = m_sock->send_msg([&] (auto &sock) {
847861
ZMQ::send(sock, ZMQ::str_msg("req_triple"));
848-
}).get();
862+
}, 1000).get();
849863
if (reply.empty())
850864
throw std::runtime_error("triple not obtained");
851865
std::string triple_str((char*) reply[0].data(), reply[0].size());
@@ -868,7 +882,7 @@ NACS_EXPORT() uint32_t Backend::refresh_restart()
868882
throw std::runtime_error("Backend socket not configured");
869883
auto reply = m_sock->send_msg([&] (auto &sock) {
870884
ZMQ::send(sock, ZMQ::str_msg("req_restarts"));
871-
}).get();
885+
}, 1000).get();
872886
if (reply.empty())
873887
throw std::runtime_error("restart number not obtained");
874888
auto rep_data = (const uint8_t*)reply[0].data();

lib/nacs-seq/awg/backend.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ class Backend;
2020

2121
namespace AWG {
2222

23+
// Custom error class for request timeout.
24+
struct awg_seq_error : std::runtime_error {
25+
using std::runtime_error::runtime_error;
26+
};
27+
2328
//globals for all AWG backends
2429
uint64_t seqcount = 0;
2530

@@ -110,6 +115,8 @@ class Backend : public Device {
110115

111116
std::string m_trig_dev;
112117
Zynq::Backend *m_zynq_dev = nullptr;
118+
119+
bool error_during_seq = false;
113120
};
114121

115122
}

0 commit comments

Comments
 (0)