Skip to content

Commit a9692d6

Browse files
committed
Updated and fixed some Script examples
1 parent 152935b commit a9692d6

File tree

5 files changed

+42
-5
lines changed

5 files changed

+42
-5
lines changed

examples/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ dai_add_example(script_http_server Script/script_http_server.cpp OFF)
304304
dai_add_example(script_mjpeg_server Script/script_mjpeg_server.cpp OFF)
305305
dai_add_example(script_nndata_example Script/script_nndata_example.cpp ON)
306306
dai_add_example(script_json_communication Script/script_json_communication.cpp ON)
307+
dai_add_example(script_get_device_info Script/script_get_device_info.cpp ON)
307308

308309
# SpatialDetection
309310
dai_add_example(spatial_location_calculator SpatialDetection/spatial_location_calculator.cpp ON)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <iostream>
2+
3+
// Includes common necessary includes for development using depthai library
4+
#include "depthai/depthai.hpp"
5+
6+
int main() {
7+
using namespace std;
8+
9+
// Start defining a pipeline
10+
dai::Pipeline pipeline;
11+
12+
// Script node
13+
auto script = pipeline.create<dai::node::Script>();
14+
script->setScript(R"(
15+
import json
16+
data = json.dumps({
17+
'deviceId': __device_id__,
18+
'fwVersion': __version__
19+
}).encode('utf-8')
20+
21+
b = Buffer(len(data))
22+
b.setData(data)
23+
node.io['info'].send(b)
24+
)");
25+
26+
// XLinkOut
27+
auto xout = pipeline.create<dai::node::XLinkOut>();
28+
xout->setStreamName("info");
29+
script->outputs["info"].link(xout->input);
30+
31+
// Connect to device with pipeline
32+
dai::Device device(pipeline);
33+
auto msg = device.getOutputQueue("info")->get<dai::Buffer>();
34+
auto data = nlohmann::json::parse(msg->getData());
35+
std::cout << data.dump(4) << std::endl;
36+
37+
return 0;
38+
}

examples/Script/script_get_ip.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ int main() {
2727
2828
ip = get_ip_address('re0') # '192.168.0.110'
2929
node.warn(f'IP of the device: {ip}')
30-
node.io['end'].send(Buffer())
30+
node.io['end'].send(Buffer(32))
3131
)");
3232

3333
// XLinkOut

examples/Script/script_http_client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ int main() {
2424
data1 = r1.read()
2525
node.warn(f'Public IP: {data1}')
2626
27-
node.io['end'].send(Buffer())
27+
node.io['end'].send(Buffer(32))
2828
)");
2929

3030
// XLinkOut

examples/Script/script_json_communication.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ int main() {
2929
# Change initial dictionary a bit
3030
dict['one'] += 1
3131
dict['foo'] = "baz"
32-
dict['fw_version'] = __version__
33-
dict['device_id'] = __device_id__
3432
35-
b = Buffer(256)
33+
b = Buffer(30)
3634
b.setData(json.dumps(dict).encode('utf-8'))
3735
node.io['out'].send(b)
3836
)");

0 commit comments

Comments
 (0)