diff --git a/examples/Script/script_json_communication.cpp b/examples/Script/script_json_communication.cpp index 835ba92a4..b36215491 100644 --- a/examples/Script/script_json_communication.cpp +++ b/examples/Script/script_json_communication.cpp @@ -20,15 +20,16 @@ int main() { xin->out.link(script->inputs["in"]); script->setScript(R"( import json + # Recieve bytes from the host data = node.io['in'].get().getData() jsonStr = str(data, 'utf-8') dict = json.loads(jsonStr) + # Change initial dictionary a bit - node.warn('Original: ' + str(dict)) dict['one'] += 1 dict['foo'] = "baz" - node.warn('Changed: ' + str(dict)) + b = Buffer(30) b.setData(json.dumps(dict).encode('utf-8')) node.io['out'].send(b) @@ -41,12 +42,16 @@ int main() { // Connect to device with pipeline dai::Device device(pipeline); + // This dict will be serialized (JSON), sent to device (Script node), + // edited a bit and sent back to the host nlohmann::json dict{{"one", 1}, {"foo", "bar"}}; + cout << "dict: " << dict << "\n"; auto buffer = dai::Buffer(); auto data = dict.dump(); buffer.setData({data.begin(), data.end()}); device.getInputQueue("in")->send(buffer); + // Wait for the script to send the changed dictionary back auto jsonData = device.getOutputQueue("out")->get(); auto changedDict = nlohmann::json::parse(jsonData->getData()); cout << "changedDict: " << changedDict << "\n";