This example requires Qt5 >= 5.9 setup for building.
2import CvbQuick 1.0 as CvbQuick
3import QtQuick.Controls 2.2
4import QtQuick.Layouts 1.3
5import QtQuick.Dialogs 1.2
6import QtQuick.Controls.Universal 2.2
12 Layout.fillWidth: true
13 Layout.fillHeight: true
15 property var loadFile: true
16 property var enableSnapSend: false
18 Universal.theme: Universal.System
20 background: Rectangle {
23 color: Universal.background
29 title: loadFile ? "Select an image or driver to load" : "Save image"
30 selectExisting: loadFile
32 nameFilters: ["Drivers (*.vin *.emu)", "Image files (*png *.bmp)", "All files (*)"]
33 selectedNameFilter: loadFile ? "Drivers" : "Image files"
36 var path = fileUrl.toString();
37 // remove prefixed "file:///"
38 path = path.replace(/^(file:\/{3})/,"");
39 // unescape html codes like '%23' for '#'
40 var cleanPath = decodeURIComponent(path);
42 loadFile ? backEnd.LoadDevice(path) : backEnd.SaveImg(path)
49 flow: GridLayout.TopToBottom
55 enabled: btnStartServer.m_server_disabled
56 Layout.fillWidth: true
58 model: backEnd.ConnectionList()
67 Layout.fillHeight: true
68 Layout.fillWidth: true
69 uploadMode : CvbQuick.UploadMode.Viewport
76 enabled: btnStartServer.m_server_disabled
77 Layout.fillWidth: true
79 (Qt.platform.os == "windows") ?
81 qsTr("Socket Driver (loopback)"),
82 qsTr("Filter Driver (default)")
92 objectName: "btnStartServer"
94 implicitWidth: btnLoadDevice.width
95 property var m_server_disabled: true
96 text: m_server_disabled ? qsTr("Start Server") : qsTr("Stop Server")
98 m_server_disabled = m_server_disabled ? false : true
99 backEnd.StartServer(connectionCombo.currentIndex, driverTypeCombo.currentIndex)
109 objectName: "btnLoadDevice"
111 enabled: btnStartServer.m_server_disabled
112 text: qsTr("Load Device")
123 objectName: "btnSaveImg"
125 implicitWidth: btnLoadDevice.width
126 text: qsTr("Save Image")
136 objectName: "btnSnap"
138 implicitWidth: btnLoadDevice.width
139 width: btnSaveImg.width
140 enabled: btnStartServer.m_server_disabled
142 onClicked: backEnd.BtnSnap()
147 objectName: "switchEnableSnapSend"
148 id: switchEnableSnapSend
149 text: qsTr("Enable Snap Send")
151 enabled: !btnStartServer.m_server_disabled
154 enableSnapSend = enableSnapSend ? false : true
155 backEnd.SwitchEnableSnapSend(checked)
161 objectName: "btnSnapSend"
163 implicitWidth: btnLoadDevice.width
164 enabled: !btnStartServer.m_server_disabled && enableSnapSend
165 text: qsTr("Snap Send")
166 onClicked: backEnd.BtnSnapSend()
172 objectName: "switchGrab"
176 enabled: btnStartServer.m_server_disabled
177 onCheckedChanged: backEnd.SwitchGrab(checked)
5#include <cvb/data_type.hpp>
6#include <cvb/gevserver/node.hpp>
7#include <cvb/gevserver/node_map.hpp>
8#include <cvb/gevserver/server.hpp>
9#include <cvb/gevserver/stream.hpp>
10#include <cvb/size_2d.hpp>
12#include <cvb/device_factory.hpp>
13#include <cvb/image.hpp>
14#include <cvb/ui/image_view_item.hpp>
19 qRegisterMetaType<QWindow::Visibility>();
25 hasRingBuffer_ = !!device_->Stream()->RingBuffer();
29 streamHandler_->Create(device_->Stream());
33 device_->Stream()->GetSnapshot();
44 if (device_->Stream()->IsRunning())
45 device_->Stream()->Stop();
48void BackEnd::StartServer(
const int &addressIndex,
const int &driverTypeIndex)
50 qDebug() <<
"Starting server on address index " << addressIndex <<
" and driver type index " << driverTypeIndex;
56 startInProgress_ =
true;
67 device_->DeviceImage()->ColorModel(),
68 device_->DeviceImage()->Plane(0).DataType(),
74 server_->SetUserVersion(CVB_LIT(
"_C++GevServer"));
78 server_->Stream()->SetResendBuffersCount(2);
80 server_->Stream()->SetResendBuffersCount(0);
83 auto address = iFaces_.at(addressIndex).IPAddress();
84 server_->Start(address);
91 qDebug() <<
"Started server";
99 qDebug() <<
"Stopped server";
105 startInProgress_ =
false;
108void BackEnd::operator()() noexcept
111 device_->Stream()->Start();
114 if (grabSwitchSwitched_)
122 device_->Stream()->Wait();
134 bufferIndex_ = img.Image->BufferIndex();
135 imgMap_[bufferIndex_] = img.Image;
136 server_->Stream()->Send(img.Image, [
this](
const Cvb::ImagePtr &) {
137 imgMap_[bufferIndex_]->Unlock();
138 qDebug() <<
"unlocked buffer index " << std::to_string(bufferIndex_).c_str();
142 server_->Stream()->Send(*img.Image.get());
150 device_->Stream()->Stop();
153void BackEnd::SwitchGrab(
const bool &switched)
155 grabSwitchSwitched_ = switched;
157 if (grabSwitchSwitched_)
167 qDebug() <<
"Grab switch switched to" << switched;
170QVariantList BackEnd::ConnectionList()
178 for (
auto const &iFace : iFaces_)
181 ss << iFace.IPAddress() <<
" (" << iFace.IPv4Mask() <<
")";
188void BackEnd::LoadDevice(
const QString &path)
190 qDebug() <<
"Loading new device on path " << path;
197 device_->Stream()->GetSnapshot();
199 hasRingBuffer_ = !!device_->Stream()->RingBuffer();
206 qDebug() <<
"Failed to load new device";
210void BackEnd::SaveImg(
const QString &path)
212 qDebug() <<
"Saving new file on path " << path;
216void BackEnd::BtnSnap()
218 qDebug() <<
"Snap image";
221 device_->Stream()->GetSnapshot();
224void BackEnd::SwitchEnableSnapSend(
const bool &switched)
226 snapSend_ = switched;
233 qDebug() <<
"Enable snap switch switched to" << switched;
236void BackEnd::BtnSnapSend()
238 if (server_->State() == Cvb::GevServer::State::AcquisitionEnabled)
240 qDebug() <<
"Snap send";
243 auto img = device_->Stream()->GetSnapshot();
247 server_->Stream()->Send(img.Image,
nullptr);
251 auto img2 = device_->Stream()->GetSnapshot();
253 server_->Stream()->Send(*img2.Image);
261 qDebug() <<
"Acquisition not enabled on server";
264void BackEnd::StopGrab()
267 if (device_->Stream()->IsRunning() && grabSwitchSwitched_)
273 if (device_->Stream()->IsRunning() && acqStarted_)
281 switch (windowStateRegNode_->Value())
284 view_->showMinimized();
290 view_->showMaximized();
297void BackEnd::AddGenICamFeatures()
300 server_->NodeMap()->AddNode(catNode);
301 catNode->SetDisplayName(CVB_LIT(
"Custom Features"));
302 catNode->SetToolTip(CVB_LIT(
"Contains all application defined features."));
303 auto rootNode = server_->NodeMap()->Node(CVB_LIT(
"Root"));
307 server_->NodeMap()->AddNode(windowStateRegNode_);
314 windowStateRegNode_->SetValue(1);
315 windowStateRegNode_->RegisterEventWrittenUpdated(
319 server_->NodeMap()->AddNode(enumerationNode);
320 enumerationNode->SetDisplayName(CVB_LIT(
"Window State"));
321 enumerationNode->SetToolTip(CVB_LIT(
"Current window state of server application."));
325 minimized->SetNumericValue(0);
329 normalNode->SetNumericValue(1);
333 maxNode->SetNumericValue(2);
static std::shared_ptr< T > Open(const String &provider, AcquisitionStack acquisitionStack=AcquisitionStack::PreferVin)
Opens a device with the given provider with its default board and port (if applicable).
Definition: decl_device_factory.hpp:55
Stream image that is returned, when the ring buffer interface is available on a device.
Definition: decl_ring_buffer_image.hpp:29
Version information for GenICam related objects.
Definition: decl_node_map.hpp:58
static CategoryNodePtr Create(const String &name, const GevServer::Namespace &nameSpace)
Creates a new CategoryNode with the given name and nameSpace .
Definition: category_node.hpp:33
static EnumEntryNodePtr Create(const String &name, const GevServer::Namespace &nameSpace)
Creates a new EnumEntryNode with the given name and nameSpace .
Definition: enum_entry_node.hpp:35
static EnumerationNodePtr Create(const String &name, const GevServer::Namespace &nameSpace)
Creates a new EnumerationNode with the given name and nameSpace .
Definition: enumeration_node.hpp:41
static Int32RegNodePtr Create(const String &name, const GevServer::Namespace &nameSpace, const std::int64_t &address)
Creates a new int_32_reg_node with the given name and nameSpace .
Definition: int_32_reg_node.hpp:34
static ServerPtr CreateWithConstSize(Size2D< int > size, PfncFormat pixelFormat, GevServer::DriverType driverType=GevServer::DriverType::Auto)
Creates a new Server object with a constant width and height.
Definition: detail_server.hpp:37
Base class for all nodes that have a value.
Definition: value_node.hpp:24
@ Invisible
Node should not be displayed.
@ NoCache
No caching used.
DriverType
GigE Vision driver to use for communication and streaming.
Definition: gevserver.hpp:130
@ Ok
Everything is fine, a new image arrived.
std::string toStdString() const const
T findChild(const QString &name, Qt::FindChildOptions options) const const
bool setProperty(const char *name, const QVariant &value)
QByteArray toLatin1() const const
static std::vector< LogicalNetworkInterface > GetAllAvailable()
Gets all available network interfaces usable by the GevServer.
Definition: logical_network_interface.hpp:38