Lely core libraries 2.3.4
ixxat.hpp
Go to the documentation of this file.
1
24#ifndef LELY_IO2_WIN32_IXXAT_HPP_
25#define LELY_IO2_WIN32_IXXAT_HPP_
26
28#include <lely/io2/can.hpp>
29
30#include <utility>
31
32#include <windows.h>
33
34namespace lely {
35namespace io {
36
39 public:
40 IxxatGuard() {
41 if (io_ixxat_init() == -1) util::throw_errc("IxxatGuard");
42 }
43
44 IxxatGuard(const IxxatGuard&) = delete;
45 IxxatGuard& operator=(const IxxatGuard&) = delete;
46
47 ~IxxatGuard() noexcept { io_ixxat_fini(); }
48};
49
52 public:
55 int data = 0)
57 dwIndex, dwCanNo, static_cast<int>(flags), nominal, data)) {
58 if (!ctrl) util::throw_errc("IxxatController");
59 }
60
63 int nominal, int data = 0)
65 &rLuid, dwCanNo, static_cast<int>(flags), nominal, data)) {
66 if (!ctrl) util::throw_errc("IxxatController");
67 }
68
69 IxxatController(const IxxatController&) = delete;
70
72 : CanControllerBase(other.ctrl) {
73 other.ctrl = nullptr;
74 }
75
76 IxxatController& operator=(const IxxatController&) = delete;
77
78 IxxatController&
79 operator=(IxxatController&& other) noexcept {
80 using ::std::swap;
81 swap(ctrl, other.ctrl);
82 return *this;
83 }
84
87
89 HANDLE
91};
92
95 public:
97 IxxatChannel(io_ctx_t* ctx, ev_exec_t* exec, int rxtimeo = 0, int txtimeo = 0)
98 : CanChannelBase(io_ixxat_chan_create(ctx, exec, rxtimeo, txtimeo)) {
99 if (!chan) util::throw_errc("IxxatChannel");
100 }
101
102 IxxatChannel(const IxxatChannel&) = delete;
103
105 other.chan = nullptr;
106 other.dev = nullptr;
107 }
108
109 IxxatChannel& operator=(const IxxatChannel&) = delete;
110
111 IxxatChannel&
112 operator=(IxxatChannel&& other) noexcept {
113 using ::std::swap;
114 swap(chan, other.chan);
115 swap(dev, other.dev);
116 return *this;
117 }
118
121
123 HANDLE
125
127 void
129 ::std::error_code& ec) noexcept {
131 SetLastError(0);
132 if (!io_ixxat_chan_open(*this, ctrl, wRxFifoSize, wTxFifoSize))
133 ec.clear();
134 else
135 ec = util::make_error_code();
137 }
138
140 void
142 UINT16 wTxFifoSize = 0) {
143 ::std::error_code ec;
144 open(ctrl, wRxFifoSize, wTxFifoSize, ec);
145 if (ec) throw ::std::system_error(ec, "open");
146 }
147
149 void
151 ::std::error_code& ec) noexcept {
153 SetLastError(0);
155 ec.clear();
156 else
157 ec = util::make_error_code();
159 }
160
162 void
164 ::std::error_code ec;
166 if (ec) throw ::std::system_error(ec, "assign");
167 }
168
170 HANDLE
172
174 bool
176 return io_ixxat_chan_is_open(*this) != 0;
177 }
178
180 void
181 close(::std::error_code& ec) noexcept {
183 SetLastError(0);
184 if (!io_ixxat_chan_close(*this))
185 ec.clear();
186 else
187 ec = util::make_error_code();
189 }
190
192 void
194 ::std::error_code ec;
195 close(ec);
196 if (ec) throw ::std::system_error(ec, "close");
197 }
198};
199
200} // namespace io
201} // namespace lely
202
203#endif // !LELY_IO2_WIN32_IXXAT_HPP_
A CANopen value.
Definition val.hpp:42
A reference to an abstract CAN channel.
Definition can.hpp:430
A reference to an abstract CAN controller.
Definition can.hpp:286
An IXXAT CAN channel.
Definition ixxat.hpp:94
void open(const io_can_ctrl_t *ctrl, UINT16 wRxFifoSize=0, UINT16 wTxFifoSize=0)
Definition ixxat.hpp:141
void close(::std::error_code &ec) noexcept
Definition ixxat.hpp:181
HANDLE get_handle() const noexcept
Definition ixxat.hpp:124
IxxatChannel(io_ctx_t *ctx, ev_exec_t *exec, int rxtimeo=0, int txtimeo=0)
Definition ixxat.hpp:97
void assign(HANDLE hCanChn, UINT32 dwTscClkFreq, UINT32 dwTscDivisor, ::std::error_code &ec) noexcept
Definition ixxat.hpp:150
void open(const io_can_ctrl_t *ctrl, UINT16 wRxFifoSize, UINT16 wTxFifoSize, ::std::error_code &ec) noexcept
Definition ixxat.hpp:128
void assign(HANDLE hCanChn, UINT32 dwTscClkFreq=0, UINT32 dwTscDivisor=0)
Definition ixxat.hpp:163
HANDLE release() noexcept
Definition ixxat.hpp:171
bool is_open() const noexcept
Definition ixxat.hpp:175
An IXXAT CAN controller.
Definition ixxat.hpp:51
HANDLE get_handle() const noexcept
Definition ixxat.hpp:90
IxxatController(const LUID &rLuid, UINT32 dwCanNo, CanBusFlag flags, int nominal, int data=0)
Definition ixxat.hpp:62
IxxatController(UINT32 dwIndex, UINT32 dwCanNo, CanBusFlag flags, int nominal, int data=0)
Definition ixxat.hpp:54
A RAII-style wrapper around io_ixxat_init() and io_ixxat_fini().
Definition ixxat.hpp:38
const struct ev_exec_vtbl *const ev_exec_t
An abstract task executor.
Definition ev.h:29
const struct io_can_ctrl_vtbl *const io_can_ctrl_t
An abstract CAN controller.
Definition can.h:56
This header file is part of the I/O library; it contains the C++ interface for the abstract CAN bus.
CanBusFlag
The CAN bus flags.
Definition can.hpp:40
This header file is part of the I/O library; it contains the IXXAT CAN bus declarations for Windows.
io_can_ctrl_t * io_ixxat_ctrl_create_from_luid(const LUID *lpLuid, UINT32 dwCanNo, int flags, int nominal, int data)
Creates a new IXXAT CAN controller from a locally unique identifier (LUID).
HANDLE io_ixxat_ctrl_get_handle(const io_can_ctrl_t *ctrl)
Returns the native handle of the CAN controller.
io_can_ctrl_t * io_ixxat_ctrl_create_from_index(UINT32 dwIndex, UINT32 dwCanNo, int flags, int nominal, int data)
Creates a new IXXAT CAN controller from a device index.
io_can_chan_t * io_ixxat_chan_create(io_ctx_t *ctx, ev_exec_t *exec, int rxtimeo, int txtimeo)
Creates a new IXXAT CAN channel.
void io_ixxat_fini(void)
Frees the "vcinpl.dll" or "vcinpl2.dll" library and terminates the availability of the IXXAT function...
int io_ixxat_chan_assign(io_can_chan_t *chan, HANDLE hCanChn, UINT32 dwTscClkFreq, UINT32 dwTscDivisor)
Assigns an existing handle to a CAN channel, and activates the channel if necessary.
int io_ixxat_chan_open(io_can_chan_t *chan, const io_can_ctrl_t *ctrl, UINT16 wRxFifoSize, UINT16 wTxFifoSize)
Opens a CAN channel.
int io_ixxat_chan_close(io_can_chan_t *chan)
Closes a CAN channel.
void io_ixxat_ctrl_destroy(io_can_ctrl_t *ctrl)
Destroys an IXXAT CAN controller.
int io_ixxat_init(void)
Loads the "vcinpl.dll" or "vcinpl2.dll" library and makes the IXXAT functions available for use.
void io_ixxat_chan_destroy(io_can_chan_t *chan)
Destroys an IXXAT CAN channel.
int io_ixxat_chan_is_open(const io_can_chan_t *chan)
Returns 1 is the CAN channel is open and 0 if not.
HANDLE io_ixxat_chan_get_handle(const io_can_chan_t *chan)
Returns the native handle of the CAN channel, or NULL if the channel is closed.
HANDLE io_ixxat_chan_release(io_can_chan_t *chan)
Dissociates and returns the native handle from a CAN channel.
Definition ctx.c:38