CVB++ 15.0
detail_digital_io.hpp
1#pragma once
2
3#include "../../global.hpp"
4
5#include "../../_decl/decl_device.hpp"
6
7#include "../_decl/decl_digital_io.hpp"
8
9namespace Cvb
10{
11
12 CVB_BEGIN_INLINE_NS
13
14 namespace Driver
15 {
16
17 inline int DigitalIO::InputCount() const
18 {
19 CExports::cvbval_t count = 0;
20 auto result = CExports::BDIOGetNumOutputs(parent_->Handle(), count);
21 if (result < 0)
22 std::rethrow_exception(CvbException::FromCvbResult(result, "failed to get number of digital inputs"));
23 return static_cast<int>(count);
24 }
25
26 inline int DigitalIO::OutputCount() const
27 {
28 CExports::cvbval_t count = 0;
29 auto result = CExports::BDIOGetNumInputs(parent_->Handle(), count);
30 if (result < 0)
31 std::rethrow_exception(CvbException::FromCvbResult(result, "failed to get number of digital outputs"));
32 return static_cast<int>(count);
33 }
34
35 inline bool DigitalIO::ReadInputBit(int port) const
36 {
37 CExports::cvbval_t bit = 0;
38 auto result = CExports::BDIOGetInBit(parent_->Handle(), static_cast<CExports::cvbval_t>(port), bit);
39 if (result < 0)
40 std::rethrow_exception(CvbException::FromCvbResult(result, "failed to read input bit"));
41 return (bit) ? true : false;
42 }
43
45 {
46 CExports::cvbuint32_t value = 0;
47 auto result = CExports::BDIOGetInDword(parent_->Handle(), static_cast<CExports::cvbval_t>(group), value);
48 if (result < 0)
49 std::rethrow_exception(CvbException::FromCvbResult(result, "failed to read input group"));
50 return std::bitset<32>(static_cast<std::uint32_t>(value));
51 }
52
53 inline bool DigitalIO::ReadOutputBit(int port) const
54 {
55 CExports::cvbval_t bit = 0;
56 auto result = CExports::BDIOGetOutBit(parent_->Handle(), static_cast<CExports::cvbval_t>(port), bit);
57 if (result < 0)
58 std::rethrow_exception(CvbException::FromCvbResult(result, "failed to read output bit"));
59 return (bit) ? true : false;
60 }
61
63 {
64 CExports::cvbuint32_t value = 0;
65 auto result = CExports::BDIOGetOutDword(parent_->Handle(), static_cast<CExports::cvbval_t>(group), value);
66 if (result < 0)
67 std::rethrow_exception(CvbException::FromCvbResult(result, "failed to read output group"));
68 return std::bitset<32>(static_cast<std::uint32_t>(value));
69 }
70
71 inline void DigitalIO::WriteOutputBit(int port, bool value)
72 {
73 auto result = CExports::BDIOSetOutBit(parent_->Handle(), static_cast<CExports::cvbval_t>(port),
74 static_cast<CExports::cvbval_t>(value));
75 if (result < 0)
76 std::rethrow_exception(CvbException::FromCvbResult(result, "failed to write output bit"));
77 }
78
80 {
81 auto result = CExports::BDIOSetOutDword(parent_->Handle(), static_cast<CExports::cvbval_t>(group),
82 static_cast<CExports::cvbval_t>(value.to_ulong()),
83 static_cast<CExports::cvbval_t>(mask.to_ulong()));
84 if (result < 0)
85 std::rethrow_exception(CvbException::FromCvbResult(result, "failed to write output group"));
86 }
87
88 } // namespace Driver
89
90 CVB_END_INLINE_NS
91
92} // namespace Cvb
bool ReadInputBit(int port) const
Reads a single input port from the device.
Definition detail_digital_io.hpp:35
void WriteOutputBit(int port, bool value)
Write a single output port to the device.
Definition detail_digital_io.hpp:71
int InputCount() const
Gets the number of digital input ports of the device.
Definition detail_digital_io.hpp:17
int OutputCount() const
Gets the number of digital output ports of the device.
Definition detail_digital_io.hpp:26
void WriteOutputGroup(int group, std::bitset< 32 > value)
Writes the output group to the device.
Definition decl_digital_io.hpp:99
std::bitset< 32 > ReadInputGroup(int group) const
Reads a group of input ports from the device.
Definition detail_digital_io.hpp:44
bool ReadOutputBit(int port) const
Reads a single output port from the device.
Definition detail_digital_io.hpp:53
std::bitset< 32 > ReadOutputGroup(int group) const
Reads a group of output ports from the device.
Definition detail_digital_io.hpp:62
Namespace for driver or device related operations.
Definition decl_composite.hpp:28
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
T rethrow_exception(T... args)