[{"data":1,"prerenderedAt":2000},["ShallowReactive",2],{"docs-nav-docs_cs":3,"docs-page-\u002Fcs\u002Fexamples\u002Fjson-signal-python":370,"docs-surround-\u002Fcs\u002Fexamples\u002Fjson-signal-python":1997},[4],{"title":5,"path":6,"stem":7,"children":8},"Cs","\u002Fcs","cs",[9,13,45,62,80,107,161,175,194,215,242,286,306],{"title":10,"path":6,"stem":11,"navTitle":12},"Dokumentace QInsight","cs\u002Findex","Přehled",{"title":14,"navTitle":15,"path":16,"stem":17,"children":18,"page":44},"Začínáme",null,"\u002Fcs\u002Fgetting-started","cs\u002F01.getting-started",[19,23,27,31,36,40],{"title":20,"path":21,"stem":22,"navTitle":20},"Co je QENEX Suite","\u002Fcs\u002Fgetting-started\u002Fwhat-is-qenex-suite","cs\u002F01.getting-started\u002F1.what-is-qenex-suite",{"title":24,"path":25,"stem":26,"navTitle":24},"Co je QInsight","\u002Fcs\u002Fgetting-started\u002Fwhat-is-qinsight","cs\u002F01.getting-started\u002F2.what-is-qinsight",{"title":28,"path":29,"stem":30,"navTitle":28},"Instalace","\u002Fcs\u002Fgetting-started\u002Finstallation","cs\u002F01.getting-started\u002F3.installation",{"title":32,"path":33,"stem":34,"navTitle":35},"Uživatelské rozhraní QInsight","\u002Fcs\u002Fgetting-started\u002Fthe-qinsight-interface","cs\u002F01.getting-started\u002F4.the-qinsight-interface","Uživatelské rozhraní",{"title":37,"path":38,"stem":39,"navTitle":37},"Licencování","\u002Fcs\u002Fgetting-started\u002Flicensing","cs\u002F01.getting-started\u002F5.licensing",{"title":41,"path":42,"stem":43,"navTitle":41},"Historie verzí","\u002Fcs\u002Fgetting-started\u002Frelease-notes","cs\u002F01.getting-started\u002F6.release-notes",false,{"title":46,"navTitle":15,"path":47,"stem":48,"children":49,"page":44},"První projekt","\u002Fcs\u002Ffirst-project","cs\u002F02.first-project",[50,54,58],{"title":51,"path":52,"stem":53,"navTitle":51},"Založení projektu","\u002Fcs\u002Ffirst-project\u002Fcreate-a-project","cs\u002F02.first-project\u002F1.create-a-project",{"title":55,"path":56,"stem":57,"navTitle":55},"Struktura projektu","\u002Fcs\u002Ffirst-project\u002Fproject-structure","cs\u002F02.first-project\u002F2.project-structure",{"title":59,"path":60,"stem":61,"navTitle":59},"Heslo projektu","\u002Fcs\u002Ffirst-project\u002Fproject-password","cs\u002F02.first-project\u002F3.project-password",{"title":63,"navTitle":15,"path":64,"stem":65,"children":66,"page":44},"Připojení zařízení","\u002Fcs\u002Fconnecting-a-device","cs\u002F03.connecting-a-device",[67,71,75],{"title":68,"path":69,"stem":70,"navTitle":68},"Přidání driveru","\u002Fcs\u002Fconnecting-a-device\u002Fadd-a-driver","cs\u002F03.connecting-a-device\u002F1.add-a-driver",{"title":72,"path":73,"stem":74,"navTitle":72},"Přidání protokolu","\u002Fcs\u002Fconnecting-a-device\u002Fadd-a-protocol","cs\u002F03.connecting-a-device\u002F2.add-a-protocol",{"title":76,"path":77,"stem":78,"navTitle":79},"Propojení driveru a protokolu","\u002Fcs\u002Fconnecting-a-device\u002Flink-driver-and-protocol","cs\u002F03.connecting-a-device\u002F3.link-driver-and-protocol","Propojení",{"title":81,"navTitle":15,"path":82,"stem":83,"children":84,"page":44},"Proměnné","\u002Fcs\u002Fvariables","cs\u002F04.variables",[85,89,93,97,102],{"title":86,"path":87,"stem":88,"navTitle":86},"Co je proměnná","\u002Fcs\u002Fvariables\u002Fwhat-is-a-variable","cs\u002F04.variables\u002F1.what-is-a-variable",{"title":90,"path":91,"stem":92,"navTitle":90},"Konverze a prezentace","\u002Fcs\u002Fvariables\u002Fconversion-and-presentation","cs\u002F04.variables\u002F2.conversion-and-presentation",{"title":94,"path":95,"stem":96,"navTitle":94},"Přidání proměnné","\u002Fcs\u002Fvariables\u002Fadd-a-variable","cs\u002F04.variables\u002F3.add-a-variable",{"title":98,"path":99,"stem":100,"navTitle":101},"Proměnná Matrix (pole, křivka, mapa)","\u002Fcs\u002Fvariables\u002Fmatrix-variable","cs\u002F04.variables\u002F4.matrix-variable","Proměnná Matrix",{"title":103,"path":104,"stem":105,"navTitle":106},"Události (Events)","\u002Fcs\u002Fvariables\u002Fevents","cs\u002F04.variables\u002F5.events","Události",{"title":108,"navTitle":15,"path":109,"stem":110,"children":111,"page":44},"Vizualizace","\u002Fcs\u002Fvisualization","cs\u002F05.visualization",[112,117,122,126,131,136,141,146,151,156],{"title":113,"path":114,"stem":115,"navTitle":116},"Vytvoření pracovní plochy","\u002Fcs\u002Fvisualization\u002Fcreate-a-workspace","cs\u002F05.visualization\u002F1.create-a-workspace","Pracovní plocha",{"title":118,"path":119,"stem":120,"navTitle":121},"Zápis hodnot do zařízení","\u002Fcs\u002Fvisualization\u002Fwrite-to-device","cs\u002F05.visualization\u002F10.write-to-device","Zápis do zařízení",{"title":123,"path":124,"stem":125,"navTitle":123},"Přidání controlu","\u002Fcs\u002Fvisualization\u002Fadd-a-control","cs\u002F05.visualization\u002F2.add-a-control",{"title":127,"path":128,"stem":129,"navTitle":130},"Navázání controlu na proměnnou","\u002Fcs\u002Fvisualization\u002Fbind-a-control","cs\u002F05.visualization\u002F3.bind-a-control","Navázání controlu",{"title":132,"path":133,"stem":134,"navTitle":135},"Graph — časový průběh signálů","\u002Fcs\u002Fvisualization\u002Fgraph-control","cs\u002F05.visualization\u002F4.graph-control","Graph",{"title":137,"path":138,"stem":139,"navTitle":140},"XY Graph — signál proti signálu","\u002Fcs\u002Fvisualization\u002Fxy-graph-control","cs\u002F05.visualization\u002F5.xy-graph-control","XY Graph",{"title":142,"path":143,"stem":144,"navTitle":145},"Gauge — ukazatel okamžité hodnoty","\u002Fcs\u002Fvisualization\u002Fgauge-control","cs\u002F05.visualization\u002F6.gauge-control","Gauge",{"title":147,"path":148,"stem":149,"navTitle":150},"Single-Signal — hodnota s popiskem","\u002Fcs\u002Fvisualization\u002Fsignal-control","cs\u002F05.visualization\u002F7.signal-control","Single-Signal",{"title":152,"path":153,"stem":154,"navTitle":155},"Watch Table — tabulka proměnných","\u002Fcs\u002Fvisualization\u002Fwatch-table-control","cs\u002F05.visualization\u002F8.watch-table-control","Watch Table",{"title":157,"path":158,"stem":159,"navTitle":160},"Matrix control — mapy a kalibrace","\u002Fcs\u002Fvisualization\u002Fmatrix-control","cs\u002F05.visualization\u002F9.matrix-control","Matrix control",{"title":162,"navTitle":15,"path":163,"stem":164,"children":165,"page":44},"Běh a sledování","\u002Fcs\u002Frunning","cs\u002F06.running",[166,170],{"title":167,"path":168,"stem":169,"navTitle":167},"Spuštění a zastavení","\u002Fcs\u002Frunning\u002Fstart-and-stop","cs\u002F06.running\u002F1.start-and-stop",{"title":171,"path":172,"stem":173,"navTitle":174},"Sledování živých dat","\u002Fcs\u002Frunning\u002Fwatching-live-data","cs\u002F06.running\u002F2.watching-live-data","Živá data",{"title":176,"navTitle":15,"path":177,"stem":178,"children":179,"page":44},"Logování a přehrávání","\u002Fcs\u002Flogging-and-replay","cs\u002F07.logging-and-replay",[180,184,189],{"title":181,"path":182,"stem":183,"navTitle":181},"Logování dat","\u002Fcs\u002Flogging-and-replay\u002Flogging-data","cs\u002F07.logging-and-replay\u002F1.logging-data",{"title":185,"path":186,"stem":187,"navTitle":188},"Přehrávání logu","\u002Fcs\u002Flogging-and-replay\u002Freplaying-a-log","cs\u002F07.logging-and-replay\u002F2.replaying-a-log","Přehrávání",{"title":190,"path":191,"stem":192,"navTitle":193},"Export dat","\u002Fcs\u002Flogging-and-replay\u002Fexporting-data","cs\u002F07.logging-and-replay\u002F3.exporting-data","Export",{"title":195,"navTitle":15,"path":196,"stem":197,"children":198,"page":44},"Python skripty","\u002Fcs\u002Fpython-scripts","cs\u002F08.python-scripts",[199,203,207,211],{"title":200,"path":201,"stem":202,"navTitle":12},"Přehled skriptů","\u002Fcs\u002Fpython-scripts\u002Fscripts-overview","cs\u002F08.python-scripts\u002F1.scripts-overview",{"title":204,"path":205,"stem":206,"navTitle":204},"Přístup k proměnným","\u002Fcs\u002Fpython-scripts\u002Faccessing-variables","cs\u002F08.python-scripts\u002F2.accessing-variables",{"title":208,"path":209,"stem":210,"navTitle":208},"Příklad skriptu","\u002Fcs\u002Fpython-scripts\u002Fexample-script","cs\u002F08.python-scripts\u002F3.example-script",{"title":212,"path":213,"stem":214,"navTitle":212},"Post-processing CSV","\u002Fcs\u002Fpython-scripts\u002Fcsv-post-processing","cs\u002F08.python-scripts\u002F4.csv-post-processing",{"title":216,"navTitle":15,"path":217,"stem":218,"children":219,"page":44},"Vlastní rozšíření","\u002Fcs\u002Fcustom-extensions","cs\u002F09.custom-extensions",[220,224,228,232,237],{"title":221,"path":222,"stem":223,"navTitle":221},"Vlastní driver","\u002Fcs\u002Fcustom-extensions\u002Fcustom-driver","cs\u002F09.custom-extensions\u002F1.custom-driver",{"title":225,"path":226,"stem":227,"navTitle":225},"Vlastní protokol","\u002Fcs\u002Fcustom-extensions\u002Fcustom-protocol","cs\u002F09.custom-extensions\u002F2.custom-protocol",{"title":229,"path":230,"stem":231,"navTitle":229},"Vlastní Control","\u002Fcs\u002Fcustom-extensions\u002Fcustom-control","cs\u002F09.custom-extensions\u002F3.custom-control",{"title":233,"path":234,"stem":235,"navTitle":236},"Kompletní ukázka — poloha ISS","\u002Fcs\u002Fcustom-extensions\u002Fiss-example","cs\u002F09.custom-extensions\u002F4.iss-example","Ukázka ISS",{"title":238,"path":239,"stem":240,"navTitle":241},"Kompletní ukázka — teploměr","\u002Fcs\u002Fcustom-extensions\u002Ftemp-sensor-example","cs\u002F09.custom-extensions\u002F5.temp-sensor-example","Ukázka teploměr",{"title":243,"navTitle":15,"path":244,"stem":245,"children":246,"page":44},"QFW SDK","\u002Fcs\u002Fdevice-sdk","cs\u002F10.device-sdk",[247,252,257,262,267,272,276,281],{"title":248,"path":249,"stem":250,"navTitle":251},"QFW SDK — úvod","\u002Fcs\u002Fdevice-sdk\u002Fintroduction","cs\u002F10.device-sdk\u002F1.introduction","Úvod",{"title":253,"path":254,"stem":255,"navTitle":256},"XCP v QFW SDK","\u002Fcs\u002Fdevice-sdk\u002Fxcp","cs\u002F10.device-sdk\u002F2.xcp","XCP",{"title":258,"path":259,"stem":260,"navTitle":261},"Integrace krok za krokem: XCP on TCP s FreeRTOS + lwIP","\u002Fcs\u002Fdevice-sdk\u002Fintegration-tcp","cs\u002F10.device-sdk\u002F3.integration-tcp","Integrace: XCP on TCP",{"title":263,"path":264,"stem":265,"navTitle":266},"XCP on classic CAN — co se mění","\u002Fcs\u002Fdevice-sdk\u002Fcan","cs\u002F10.device-sdk\u002F4.can","XCP on classic CAN",{"title":268,"path":269,"stem":270,"navTitle":271},"Integrace bez RTOS: XCP on TCP z hlavní smyčky","\u002Fcs\u002Fdevice-sdk\u002Fbaremetal","cs\u002F10.device-sdk\u002F5.baremetal","Integrace bez RTOS",{"title":273,"path":274,"stem":275,"navTitle":273},"Kontrakt enginu","\u002Fcs\u002Fdevice-sdk\u002Fengine-contract","cs\u002F10.device-sdk\u002F6.engine-contract",{"title":277,"path":278,"stem":279,"navTitle":280},"Adresy proměnných pro QInsight","\u002Fcs\u002Fdevice-sdk\u002Fvariable-addresses","cs\u002F10.device-sdk\u002F7.variable-addresses","Adresy proměnných",{"title":282,"path":283,"stem":284,"navTitle":285},"Řešení potíží při integraci SDK","\u002Fcs\u002Fdevice-sdk\u002Ftroubleshooting","cs\u002F10.device-sdk\u002F8.troubleshooting","Řešení potíží",{"title":287,"navTitle":15,"path":288,"stem":289,"children":290,"page":44},"Reference","\u002Fcs\u002Freference","cs\u002F11.reference",[291,295,299,303],{"title":292,"path":293,"stem":294,"navTitle":292},"Drivery","\u002Fcs\u002Freference\u002Fdrivers","cs\u002F11.reference\u002F1.drivers",{"title":296,"path":297,"stem":298,"navTitle":296},"Protokoly","\u002Fcs\u002Freference\u002Fprotocols","cs\u002F11.reference\u002F2.protocols",{"title":300,"path":301,"stem":302,"navTitle":300},"Controls","\u002Fcs\u002Freference\u002Fcontrols","cs\u002F11.reference\u002F3.controls",{"title":285,"path":304,"stem":305,"navTitle":285},"\u002Fcs\u002Freference\u002Ftroubleshooting","cs\u002F11.reference\u002F4.troubleshooting",{"title":307,"navTitle":15,"path":308,"stem":309,"children":310,"page":44},"Příklady","\u002Fcs\u002Fexamples","cs\u002F12.examples",[311,315,320,325,330,334,338,342,346,350,355,360,365],{"title":312,"path":313,"stem":314,"navTitle":312},"Simulace: všechny signály","\u002Fcs\u002Fexamples\u002Fsimulation-all-signals","cs\u002F12.examples\u002F01.simulation-all-signals",{"title":316,"path":317,"stem":318,"navTitle":319},"Modbus RTU master po sériové lince","\u002Fcs\u002Fexamples\u002Fserial-modbus-master","cs\u002F12.examples\u002F02.serial-modbus-master","Modbus RTU master",{"title":321,"path":322,"stem":323,"navTitle":324},"Modbus RTU slave se simulovanými senzory","\u002Fcs\u002Fexamples\u002Fserial-modbus-slave","cs\u002F12.examples\u002F03.serial-modbus-slave","Modbus RTU slave",{"title":326,"path":327,"stem":328,"navTitle":329},"Modbus TCP master přes TCP klienta","\u002Fcs\u002Fexamples\u002Ftcp-client-modbus-master","cs\u002F12.examples\u002F04.tcp-client-modbus-master","Modbus TCP master",{"title":331,"path":332,"stem":333,"navTitle":331},"Modbus TCP slave na TCP serveru","\u002Fcs\u002Fexamples\u002Ftcp-server-modbus-slave","cs\u002F12.examples\u002F05.tcp-server-modbus-slave",{"title":335,"path":336,"stem":337,"navTitle":335},"Bitové pole a skript","\u002Fcs\u002Fexamples\u002Fbit-field-script","cs\u002F12.examples\u002F08.bit-field-script",{"title":339,"path":340,"stem":341,"navTitle":339},"Dvě ECU najednou","\u002Fcs\u002Fexamples\u002Ftwo-ecus","cs\u002F12.examples\u002F09.two-ecus",{"title":343,"path":344,"stem":345,"navTitle":343},"Poloha ISS naživo","\u002Fcs\u002Fexamples\u002Fiss-live-tracking","cs\u002F12.examples\u002F10.iss-live-tracking",{"title":347,"path":348,"stem":349,"navTitle":347},"Simulovaný teploměr","\u002Fcs\u002Fexamples\u002Fsimul-temp-measure","cs\u002F12.examples\u002F11.simul-temp-measure",{"title":351,"path":352,"stem":353,"navTitle":354},"JSON signály z Python generátoru","\u002Fcs\u002Fexamples\u002Fjson-signal-python","cs\u002F12.examples\u002F12.json-signal-python","JSON signály z Pythonu",{"title":356,"path":357,"stem":358,"navTitle":359},"Raw CAN rámce z Raspberry","\u002Fcs\u002Fexamples\u002Fraw-can-python","cs\u002F12.examples\u002F13.raw-can-python","Raw CAN z Raspberry",{"title":361,"path":362,"stem":363,"navTitle":364},"XCP on TCP na NUCLEO-H723ZG: měření, stimulace a kalibrační mapy","\u002Fcs\u002Fexamples\u002Ftcp-client-xcp-nucleo-maps","cs\u002F12.examples\u002F14.tcp-client-xcp-nucleo-maps","XCP on TCP na NUCLEO-H723ZG",{"title":366,"path":367,"stem":368,"navTitle":369},"XCP on CAN na NUCLEO-H723ZG: měření, stimulace a kalibrační mapy","\u002Fcs\u002Fexamples\u002Fcan-xcp-nucleo-maps","cs\u002F12.examples\u002F15.can-xcp-nucleo-maps","XCP on CAN na NUCLEO-H723ZG",{"id":371,"title":351,"body":372,"description":1992,"extension":1993,"meta":1994,"navTitle":354,"navigation":837,"path":352,"seo":1995,"stem":353,"__hash__":1996},"docs_cs\u002Fcs\u002F12.examples\u002F12.json-signal-python.md",{"type":373,"value":374,"toc":1979},"minimark",[375,379,384,399,411,446,457,467,478,519,522,526,569,573,596,600,605,615,618,735,756,759,762,766,797,801,811,1949,1953,1975],[376,377,351],"h1",{"id":378},"json-signály-z-python-generátoru",[380,381,383],"h2",{"id":382},"princip-ukázky","Princip ukázky",[385,386,387,388,393,394,398],"p",{},"Ukázka předvádí protokol ",[389,390,392],"a",{"href":391},"\u002Fcs\u002Freference\u002Fprotocols#json-signal-stream","JSON Signal Stream",":\nnejjednodušší způsob, jak do QInsight přenést data z Arduina, ESP32,\nRaspberry nebo vlastního programu. Zařízení posílá jeden JSON objekt na\nřádek, například ",[395,396,397],"code",{},"{\"name\": \"sine1\", \"value\": 3.2, \"t\": 12.05}",", a QInsight\nz něj plní proměnné.",[385,400,401,402,405,406,410],{},"Protože takové zařízení nemusíte mít k vyzkoušení k dispozici, je ke QInsight\npřiložený Python skript ",[395,403,404],{},"Qenex_JsonSignal_SineGenerator.py",", který se\nchová jako takové zařízení. ",[407,408,409],"strong",{},"Generátor"," běží na vašem PC a:",[412,413,414,433],"ul",{},[415,416,417,420,421,424,425,428,429,432],"li",{},[407,418,419],{},"vysílá pět sinusových signálů"," ",[395,422,423],{},"sine1"," až ",[395,426,427],{},"sine5",", každý s jinou\namplitudou, offsetem, frekvencí a fází, 20× za sekundu, každý vzorek\njako jeden JSON řádek s časovou značkou ",[395,430,431],{},"t",",",[415,434,435,438,439,442,443,445],{},[407,436,437],{},"přijímá příkazy"," ve stejném formátu, kterými QInsight za běhu mění\namplitudu, frekvenci, offset nebo fázi kteréhokoli signálu, například\n",[395,440,441],{},"{\"name\": \"sine1_A\", \"value\": 2}"," nastaví amplitudu ",[395,444,423],{}," na 2.",[385,447,448,449,452,453,456],{},"Spojení mezi QInsight a generátorem je buď ",[407,450,451],{},"TCP"," (generátor je TCP\nserver, QInsight se k němu připojí driverem TCP Client), nebo ",[407,454,455],{},"sériová\nlinka"," (generátor otevře jeden konec COM páru, QInsight druhý driverem\nSerial Port). Datový tok je v obou případech stejný:",[458,459,464],"pre",{"className":460,"code":462,"language":463},[461],"language-text","Python generátor  ── {\"name\": \"sine1\", \"value\": 3.2, \"t\": 12.05}  ──►  QInsight (graf, watch table, log)\n                  ◄── {\"name\": \"sine1_A\", \"value\": 2}             ──   zápis z watch table\n","text",[395,465,462],{"__ignoreMap":466},"",[385,468,469,470,473,474,477],{},"Pro každý transport je ve složce ",[395,471,472],{},"Examples"," vedle ",[395,475,476],{},"QInsight.exe"," jeden\nprojekt; skript je tamtéž:",[412,479,480,500],{},[415,481,482,485,486,489,490,493,494],{},[407,483,484],{},"Po TCP"," — projekt ",[395,487,488],{},"Qenex_TcpClient_JsonSignal_PythonSines.qproj",",\ndriver TCP Client s ",[395,491,492],{},"ip=127.0.0.1;port=5000","; generátor spustíte\npříkazem",[458,495,498],{"className":496,"code":497,"language":463},[461],"python Qenex_JsonSignal_SineGenerator.py\n",[395,499,497],{"__ignoreMap":466},[415,501,502,485,505,508,509,512,513],{},[407,503,504],{},"Po sériové lince",[395,506,507],{},"Qenex_Serial_JsonSignal_PythonSines.qproj",",\ndriver Serial Port s ",[395,510,511],{},"port=COM6;baudRate=115200","; generátor běží na\ndruhém konci COM páru:",[458,514,517],{"className":515,"code":516,"language":463},[461],"python Qenex_JsonSignal_SineGenerator.py --serial COM3\n",[395,518,516],{"__ignoreMap":466},[385,520,521],{},"Skript je zároveň vzor, jak má vaše vlastní zařízení řádky posílat\na přijímat; celý je vypsaný na konci stránky.",[380,523,525],{"id":524},"co-ukázka-předvádí","Co ukázka předvádí",[412,527,528,534,563],{},[415,529,530,533],{},[407,531,532],{},"Čtení"," pěti sinusů s časovou značkou ze zařízení: v grafu vidíte\nskutečné rozestupy vzorků generátoru, ne okamžiky příjmu na PC.",[415,535,536,539,540,543,544,547,548,551,552,555,556,559,560,562],{},[407,537,538],{},"Zápis"," do zařízení: proměnné ",[395,541,542],{},"Sine1Amplitude",", ",[395,545,546],{},"Sine1Frequency",",\n",[395,549,550],{},"Sine2Amplitude"," a ",[395,553,554],{},"Sine2Frequency"," mají směr ",[395,557,558],{},"write",". Zápis z watch\ntable odešle generátoru řádek ",[395,561,441],{}," a\nsinus se okamžitě změní.",[415,564,565,568],{},[407,566,567],{},"Tentýž protokol na dvou transportech",": TCP i sériová linka, projekty\nse liší jen driverem.",[380,570,572],{"id":571},"co-potřebujete","Co potřebujete",[412,574,575,582,589],{},[415,576,577,578,581],{},"Python 3 na tomto nebo jiném PC. Pro sériový režim navíc pyserial:\n",[395,579,580],{},"python -m pip install pyserial",".",[415,583,584,585,588],{},"TCP: nic dalšího; generátor poslouchá na portu 5000, QInsight se\npřipojí jako klient. Na jiném PC změňte ",[395,586,587],{},"ip"," v nastavení driveru a\npovolte port ve firewallu.",[415,590,591,592,595],{},"Sériová linka: pár virtuálních COM portů (např. com0com) nebo dva\npřevodníky USB\u002Fsériová linka spojené křížem. Generátor běží na jednom\nkonci, QInsight na druhém; ",[395,593,594],{},"port"," v nastavení driveru upravte podle\nsvého páru, rychlost musí být na obou stranách stejná.",[380,597,599],{"id":598},"projekt","Projekt",[601,602,604],"h3",{"id":603},"driver-a-protokol","Driver a protokol",[385,606,607,608,551,611,614],{},"Protokol nemá nastavení. Nastavení driveru je uvedené výše; TCP driver\nmá navíc ",[395,609,610],{},"reconnectAttempts=-1",[395,612,613],{},"keepAliveMs=5000",", takže po ukončení\na novém spuštění generátoru se sám připojí.",[601,616,81],{"id":617},"proměnné",[619,620,621,642],"table",{},[622,623,624],"thead",{},[625,626,627,631,634,639],"tr",{},[628,629,630],"th",{},"Proměnná",[628,632,633],{},"Směr",[628,635,636],{},[395,637,638],{},"name",[628,640,641],{},"Význam",[643,644,645,667,684,701,718],"tbody",{},[625,646,647,655,658,664],{},[648,649,650,652,653],"td",{},[395,651,423],{}," … ",[395,654,427],{},[648,656,657],{},"read",[648,659,660,652,662],{},[395,661,423],{},[395,663,427],{},[648,665,666],{},"signály generátoru, O + A·sin(2πft + φ)",[625,668,669,674,676,681],{},[648,670,671],{},[395,672,673],{},"Params\u002FSine1Amplitude",[648,675,558],{},[648,677,678],{},[395,679,680],{},"sine1_A",[648,682,683],{},"amplituda sine1",[625,685,686,691,693,698],{},[648,687,688],{},[395,689,690],{},"Params\u002FSine1Frequency",[648,692,558],{},[648,694,695],{},[395,696,697],{},"sine1_f",[648,699,700],{},"frekvence sine1 v Hz",[625,702,703,708,710,715],{},[648,704,705],{},[395,706,707],{},"Params\u002FSine2Amplitude",[648,709,558],{},[648,711,712],{},[395,713,714],{},"sine2_A",[648,716,717],{},"amplituda sine2",[625,719,720,725,727,732],{},[648,721,722],{},[395,723,724],{},"Params\u002FSine2Frequency",[648,726,558],{},[648,728,729],{},[395,730,731],{},"sine2_f",[648,733,734],{},"frekvence sine2 v Hz",[385,736,737,738,741,742,543,745,543,748,751,752,755],{},"Generátor přijímá jména ",[395,739,740],{},"\u003Csignál>_\u003Cparametr>"," s parametry ",[395,743,744],{},"A",[395,746,747],{},"O",[395,749,750],{},"f","\na ",[395,753,754],{},"phi",", takže další zapisovatelné proměnné přidáte jen novým jménem.",[601,757,116],{"id":758},"pracovní-plocha",[385,760,761],{},"Graf všech pěti sinusů, watch table s parametry v zápisovém režimu a pět\nsignal controlů.",[380,763,765],{"id":764},"co-uvidíte-a-co-vyzkoušet","Co uvidíte a co vyzkoušet",[412,767,768,775,787,794],{},[415,769,770,771,774],{},"Po ",[407,772,773],{},"Startu"," se během jedné sekundy rozběhne pět sinusových signálů.\nV logu se objeví nejvýše jedno hlášení o zahozeném řádku: při otevření\nsériového portu uprostřed běžícího přenosu přijde nejprve zbytek\nneúplné zprávy. Ten protokol zahodí bez hlášení, další nečitelné řádky\nby již ohlásil.",[415,776,777,778,780,781,783,784,581],{},"Ve watch table zapište ",[395,779,542],{}," = 2 a ",[395,782,546],{}," = 0,2:\namplituda i frekvence signálu sine1 se sníží, generátor v konzoli vypíše\n",[395,785,786],{},"sine1.A = 2.0",[415,788,789,790,793],{},"Zapište neznámé jméno, například proměnnou s ",[395,791,792],{},"name=\"sine9_A\"",":\ngenerátor ji ignoruje, v QInsight se nic nestane. Naopak pošlete-li\ngenerátoru ručně řádek se jménem, které projekt nemá, protokol to\njednou ohlásí v logu.",[415,795,796],{},"Ukončete generátor (Ctrl+C) a spusťte znovu: TCP driver se znovu\npřipojí sám, sériový port zůstal otevřený a data přicházejí dál.",[380,798,800],{"id":799},"skript-generátoru","Skript generátoru",[385,802,803,804,806,807,810],{},"Celý ",[395,805,404],{},"; formát řádků je v docstringu.\nPro vlastní zařízení stačí převzít dva prvky: vysílání\n",[395,808,809],{},"{\"name\": ..., \"value\": ..., \"t\": ...}\\n"," a čtení řádků stejného tvaru.",[458,812,816],{"className":813,"code":814,"language":815,"meta":466,"style":466},"language-python shiki shiki-themes github-light github-dark-default","#!\u002Fusr\u002Fbin\u002Fenv python3\n\"\"\"Sine signal generator - the counterpart of QInsight's JSON Signal Stream protocol.\n\nShipped with QInsight in the Examples folder; used by the examples\nQenex_TcpClient_JsonSignal_PythonSines.qproj and Qenex_Serial_JsonSignal_PythonSines.qproj.\n\nRuns as a TCP server (default, QInsight connects with the TCP Client driver) or on a\nserial port (QInsight connects with the Serial Port driver):\n\n    python Qenex_JsonSignal_SineGenerator.py                  # TCP server on 0.0.0.0:5000\n    python Qenex_JsonSignal_SineGenerator.py --port 6000      # TCP server on another port\n    python Qenex_JsonSignal_SineGenerator.py --serial COM7    # serial port, 115200 baud\n    python Qenex_JsonSignal_SineGenerator.py --serial \u002Fdev\u002FttyUSB0 --baud 57600\n\nThe generator continuously sends 5 messages (one signal each), where each signal value\nis O + A * sin(2*pi*f*t + phi). It also listens for lines that change the offset (O),\namplitude (A), frequency (f) or phase (phi) of any signal at runtime.\n\nWire protocol (newline-delimited JSON, the same shape in both directions):\n  Generator -> QInsight: {\"name\": \"sine1\", \"value\": 0.7071, \"t\": 0.05}\\\\n   (5x per cycle)\n  QInsight -> generator: {\"name\": \"sine1_A\", \"value\": 2.0}\\\\n\n                         The name is \"\u003Csignal>_\u003Cparameter>\" with parameter A (amplitude),\n                         O (offset), f (frequency [Hz]) or phi (phase [rad]); one line\n                         changes one parameter of one signal. This is exactly what the\n                         JSON Signal Stream protocol sends for a variable with\n                         direction=\"write\" and name=\"sine1_A\".\n\nSerial mode needs pyserial (pip install pyserial).\n\"\"\"\nimport argparse\nimport json\nimport math\nimport socket\nimport threading\nimport time\n\nSEND_HZ = 20            # how often a full set of samples is sent, per second\n\n# Per-signal initial parameters.\n#   A   = amplitude\n#   O   = offset\n#   f   = frequency [Hz]\n#   phi = phase offset [rad]\n# The send order follows the order of keys below (dict preserves insertion order).\nINITIAL_PARAMS = {\n    \"sine1\": {\"A\": 10.0, \"O\": 2.0,  \"f\": 1.0,  \"phi\": 0.0},\n    \"sine2\": {\"A\": 20.0, \"O\": -5.0, \"f\": 0.5,  \"phi\": math.pi \u002F 4},\n    \"sine3\": {\"A\": 5.0,  \"O\": 8.0,  \"f\": 10.0, \"phi\": math.pi \u002F 2},\n    \"sine4\": {\"A\": 30.0, \"O\": 0.5,  \"f\": 0.25, \"phi\": math.pi},\n    \"sine5\": {\"A\": 15.0, \"O\": 2.0,  \"f\": 2.0,  \"phi\": 3 * math.pi \u002F 2},\n}\nSIGNAL_NAMES = list(INITIAL_PARAMS.keys())\nPARAM_NAMES = (\"A\", \"O\", \"f\", \"phi\")\n\n\nclass SignalStore:\n    \"\"\"Thread-safe store of per-signal parameters.\"\"\"\n\n    def __init__(self, initial):\n        self._lock = threading.Lock()\n        # deep-ish copy so INITIAL_PARAMS is not mutated by runtime commands\n        self._sig = {n: dict(p) for n, p in initial.items()}\n\n    def value(self, name, t):\n        with self._lock:\n            p = self._sig[name]\n            A, O, f, phi = p[\"A\"], p[\"O\"], p[\"f\"], p[\"phi\"]\n        return O + A * math.sin(2.0 * math.pi * f * t + phi)\n\n    def set_param(self, name, param, value):\n        with self._lock:\n            if name not in self._sig or param not in PARAM_NAMES:\n                return False\n            self._sig[name][param] = float(value)\n            return True\n\n\ndef apply_line(store, raw):\n    \"\"\"One incoming line: {\"name\": \"sine1_A\", \"value\": 2.0} -> sine1.A = 2.0.\"\"\"\n    line = raw.strip()\n    if not line:\n        return\n    try:\n        msg = json.loads(line.decode(\"utf-8\"))\n    except (json.JSONDecodeError, UnicodeDecodeError):\n        return\n    name, value = msg.get(\"name\"), msg.get(\"value\")\n    if not isinstance(name, str) or \"_\" not in name or value is None:\n        return\n    signal, param = name.rsplit(\"_\", 1)\n    if store.set_param(signal, param, value):\n        print(f\"{signal}.{param} = {value}\", flush=True)\n\n\ndef reader_thread(readable, store, stop):\n    \"\"\"Listen for lines from QInsight and apply parameter changes.\"\"\"\n    try:\n        for raw in readable:                 # read line by line (socket file \u002F serial port)\n            if stop.is_set():\n                break\n            apply_line(store, raw)\n    except (OSError, ValueError):\n        pass\n    finally:\n        stop.set()\n\n\ndef send_loop(write, store, stop):\n    \"\"\"Send all signals SEND_HZ times per second until stop is set or the link breaks.\"\"\"\n    t0 = time.monotonic()\n    period = 1.0 \u002F SEND_HZ\n    next_t = time.monotonic()\n    try:\n        while not stop.is_set():\n            now = time.monotonic() - t0\n            for name in SIGNAL_NAMES:                  # 5 messages, one signal each\n                msg = {\"name\": name, \"value\": store.value(name, now), \"t\": round(now, 4)}\n                write((json.dumps(msg) + \"\\n\").encode(\"utf-8\"))\n            next_t += period\n            time.sleep(max(0.0, next_t - time.monotonic()))\n    except OSError:\n        pass\n    except KeyboardInterrupt:\n        stop.set()\n        raise\n    finally:\n        stop.set()\n\n\ndef serve_tcp(host, port, store):\n    srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n    srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)\n    srv.bind((host, port))\n    srv.listen(1)\n    # Windows delivers Ctrl+C to the main thread only when it is not stuck in a blocking\n    # socket call, so accept() polls with a timeout instead of blocking forever.\n    srv.settimeout(0.5)\n    print(f\"Generator listening on {host}:{port} - connect QInsight with the TCP Client driver (Ctrl+C to stop)\", flush=True)\n    try:\n        while True:\n            try:\n                conn, addr = srv.accept()\n            except socket.timeout:\n                continue\n            conn.settimeout(None)\n            print(f\"QInsight connected: {addr}\", flush=True)\n            stop = threading.Event()\n            threading.Thread(target=reader_thread, args=(conn.makefile(\"rb\"), store, stop), daemon=True).start()\n            send_loop(conn.sendall, store, stop)\n            conn.close()\n            print(f\"QInsight disconnected: {addr}\")\n    except KeyboardInterrupt:\n        pass\n    finally:\n        srv.close()\n\n\ndef serve_serial(port, baud, store):\n    import serial  # pyserial\n    ser = serial.Serial(port, baud, timeout=1)\n    print(f\"Generator on {port} @ {baud} baud - connect QInsight with the Serial Port driver\")\n    stop = threading.Event()\n\n    def lines():\n        while not stop.is_set():\n            raw = ser.readline()\n            if raw:\n                yield raw\n\n    threading.Thread(target=reader_thread, args=(lines(), store, stop), daemon=True).start()\n    try:\n        send_loop(ser.write, store, stop)\n    except KeyboardInterrupt:\n        pass\n    finally:\n        stop.set()\n        ser.close()\n\n\ndef main():\n    parser = argparse.ArgumentParser(description=\"JSON Signal Stream sine generator (TCP server or serial port).\")\n    parser.add_argument(\"--host\", default=\"0.0.0.0\", help=\"TCP bind address (default 0.0.0.0)\")\n    parser.add_argument(\"--port\", type=int, default=5000, help=\"TCP port (default 5000)\")\n    parser.add_argument(\"--serial\", metavar=\"PORT\", help=\"use a serial port instead of TCP, e.g. COM7 or \u002Fdev\u002FttyUSB0\")\n    parser.add_argument(\"--baud\", type=int, default=115200, help=\"serial baud rate (default 115200)\")\n    args = parser.parse_args()\n\n    store = SignalStore(INITIAL_PARAMS)\n    if args.serial:\n        serve_serial(args.serial, args.baud, store)\n    else:\n        serve_tcp(args.host, args.port, store)\n\n\nif __name__ == \"__main__\":\n    main()\n","python",[395,817,818,826,832,839,845,851,856,862,868,873,879,885,891,897,902,908,914,920,925,931,937,943,949,955,961,967,973,978,984,990,996,1002,1008,1014,1020,1026,1031,1037,1042,1048,1054,1060,1066,1072,1078,1084,1090,1096,1102,1108,1114,1120,1126,1132,1137,1142,1148,1154,1159,1165,1171,1177,1183,1188,1194,1200,1206,1212,1218,1223,1229,1234,1240,1246,1252,1258,1263,1268,1274,1280,1286,1292,1298,1304,1310,1316,1321,1327,1333,1338,1344,1350,1356,1361,1366,1372,1378,1383,1389,1395,1401,1407,1413,1419,1425,1431,1436,1441,1447,1453,1459,1465,1471,1476,1482,1488,1494,1500,1506,1512,1518,1524,1529,1535,1540,1546,1551,1556,1561,1566,1572,1578,1584,1590,1596,1602,1608,1614,1620,1625,1631,1637,1643,1649,1655,1661,1667,1673,1679,1685,1691,1697,1702,1707,1712,1718,1723,1728,1734,1740,1746,1752,1758,1763,1769,1774,1780,1786,1792,1797,1803,1808,1814,1819,1824,1829,1834,1840,1845,1850,1856,1862,1868,1874,1880,1886,1892,1897,1903,1909,1915,1921,1927,1932,1937,1943],{"__ignoreMap":466},[819,820,823],"span",{"class":821,"line":822},"line",1,[819,824,825],{},"#!\u002Fusr\u002Fbin\u002Fenv python3\n",[819,827,829],{"class":821,"line":828},2,[819,830,831],{},"\"\"\"Sine signal generator - the counterpart of QInsight's JSON Signal Stream protocol.\n",[819,833,835],{"class":821,"line":834},3,[819,836,838],{"emptyLinePlaceholder":837},true,"\n",[819,840,842],{"class":821,"line":841},4,[819,843,844],{},"Shipped with QInsight in the Examples folder; used by the examples\n",[819,846,848],{"class":821,"line":847},5,[819,849,850],{},"Qenex_TcpClient_JsonSignal_PythonSines.qproj and Qenex_Serial_JsonSignal_PythonSines.qproj.\n",[819,852,854],{"class":821,"line":853},6,[819,855,838],{"emptyLinePlaceholder":837},[819,857,859],{"class":821,"line":858},7,[819,860,861],{},"Runs as a TCP server (default, QInsight connects with the TCP Client driver) or on a\n",[819,863,865],{"class":821,"line":864},8,[819,866,867],{},"serial port (QInsight connects with the Serial Port driver):\n",[819,869,871],{"class":821,"line":870},9,[819,872,838],{"emptyLinePlaceholder":837},[819,874,876],{"class":821,"line":875},10,[819,877,878],{},"    python Qenex_JsonSignal_SineGenerator.py                  # TCP server on 0.0.0.0:5000\n",[819,880,882],{"class":821,"line":881},11,[819,883,884],{},"    python Qenex_JsonSignal_SineGenerator.py --port 6000      # TCP server on another port\n",[819,886,888],{"class":821,"line":887},12,[819,889,890],{},"    python Qenex_JsonSignal_SineGenerator.py --serial COM7    # serial port, 115200 baud\n",[819,892,894],{"class":821,"line":893},13,[819,895,896],{},"    python Qenex_JsonSignal_SineGenerator.py --serial \u002Fdev\u002FttyUSB0 --baud 57600\n",[819,898,900],{"class":821,"line":899},14,[819,901,838],{"emptyLinePlaceholder":837},[819,903,905],{"class":821,"line":904},15,[819,906,907],{},"The generator continuously sends 5 messages (one signal each), where each signal value\n",[819,909,911],{"class":821,"line":910},16,[819,912,913],{},"is O + A * sin(2*pi*f*t + phi). It also listens for lines that change the offset (O),\n",[819,915,917],{"class":821,"line":916},17,[819,918,919],{},"amplitude (A), frequency (f) or phase (phi) of any signal at runtime.\n",[819,921,923],{"class":821,"line":922},18,[819,924,838],{"emptyLinePlaceholder":837},[819,926,928],{"class":821,"line":927},19,[819,929,930],{},"Wire protocol (newline-delimited JSON, the same shape in both directions):\n",[819,932,934],{"class":821,"line":933},20,[819,935,936],{},"  Generator -> QInsight: {\"name\": \"sine1\", \"value\": 0.7071, \"t\": 0.05}\\\\n   (5x per cycle)\n",[819,938,940],{"class":821,"line":939},21,[819,941,942],{},"  QInsight -> generator: {\"name\": \"sine1_A\", \"value\": 2.0}\\\\n\n",[819,944,946],{"class":821,"line":945},22,[819,947,948],{},"                         The name is \"\u003Csignal>_\u003Cparameter>\" with parameter A (amplitude),\n",[819,950,952],{"class":821,"line":951},23,[819,953,954],{},"                         O (offset), f (frequency [Hz]) or phi (phase [rad]); one line\n",[819,956,958],{"class":821,"line":957},24,[819,959,960],{},"                         changes one parameter of one signal. This is exactly what the\n",[819,962,964],{"class":821,"line":963},25,[819,965,966],{},"                         JSON Signal Stream protocol sends for a variable with\n",[819,968,970],{"class":821,"line":969},26,[819,971,972],{},"                         direction=\"write\" and name=\"sine1_A\".\n",[819,974,976],{"class":821,"line":975},27,[819,977,838],{"emptyLinePlaceholder":837},[819,979,981],{"class":821,"line":980},28,[819,982,983],{},"Serial mode needs pyserial (pip install pyserial).\n",[819,985,987],{"class":821,"line":986},29,[819,988,989],{},"\"\"\"\n",[819,991,993],{"class":821,"line":992},30,[819,994,995],{},"import argparse\n",[819,997,999],{"class":821,"line":998},31,[819,1000,1001],{},"import json\n",[819,1003,1005],{"class":821,"line":1004},32,[819,1006,1007],{},"import math\n",[819,1009,1011],{"class":821,"line":1010},33,[819,1012,1013],{},"import socket\n",[819,1015,1017],{"class":821,"line":1016},34,[819,1018,1019],{},"import threading\n",[819,1021,1023],{"class":821,"line":1022},35,[819,1024,1025],{},"import time\n",[819,1027,1029],{"class":821,"line":1028},36,[819,1030,838],{"emptyLinePlaceholder":837},[819,1032,1034],{"class":821,"line":1033},37,[819,1035,1036],{},"SEND_HZ = 20            # how often a full set of samples is sent, per second\n",[819,1038,1040],{"class":821,"line":1039},38,[819,1041,838],{"emptyLinePlaceholder":837},[819,1043,1045],{"class":821,"line":1044},39,[819,1046,1047],{},"# Per-signal initial parameters.\n",[819,1049,1051],{"class":821,"line":1050},40,[819,1052,1053],{},"#   A   = amplitude\n",[819,1055,1057],{"class":821,"line":1056},41,[819,1058,1059],{},"#   O   = offset\n",[819,1061,1063],{"class":821,"line":1062},42,[819,1064,1065],{},"#   f   = frequency [Hz]\n",[819,1067,1069],{"class":821,"line":1068},43,[819,1070,1071],{},"#   phi = phase offset [rad]\n",[819,1073,1075],{"class":821,"line":1074},44,[819,1076,1077],{},"# The send order follows the order of keys below (dict preserves insertion order).\n",[819,1079,1081],{"class":821,"line":1080},45,[819,1082,1083],{},"INITIAL_PARAMS = {\n",[819,1085,1087],{"class":821,"line":1086},46,[819,1088,1089],{},"    \"sine1\": {\"A\": 10.0, \"O\": 2.0,  \"f\": 1.0,  \"phi\": 0.0},\n",[819,1091,1093],{"class":821,"line":1092},47,[819,1094,1095],{},"    \"sine2\": {\"A\": 20.0, \"O\": -5.0, \"f\": 0.5,  \"phi\": math.pi \u002F 4},\n",[819,1097,1099],{"class":821,"line":1098},48,[819,1100,1101],{},"    \"sine3\": {\"A\": 5.0,  \"O\": 8.0,  \"f\": 10.0, \"phi\": math.pi \u002F 2},\n",[819,1103,1105],{"class":821,"line":1104},49,[819,1106,1107],{},"    \"sine4\": {\"A\": 30.0, \"O\": 0.5,  \"f\": 0.25, \"phi\": math.pi},\n",[819,1109,1111],{"class":821,"line":1110},50,[819,1112,1113],{},"    \"sine5\": {\"A\": 15.0, \"O\": 2.0,  \"f\": 2.0,  \"phi\": 3 * math.pi \u002F 2},\n",[819,1115,1117],{"class":821,"line":1116},51,[819,1118,1119],{},"}\n",[819,1121,1123],{"class":821,"line":1122},52,[819,1124,1125],{},"SIGNAL_NAMES = list(INITIAL_PARAMS.keys())\n",[819,1127,1129],{"class":821,"line":1128},53,[819,1130,1131],{},"PARAM_NAMES = (\"A\", \"O\", \"f\", \"phi\")\n",[819,1133,1135],{"class":821,"line":1134},54,[819,1136,838],{"emptyLinePlaceholder":837},[819,1138,1140],{"class":821,"line":1139},55,[819,1141,838],{"emptyLinePlaceholder":837},[819,1143,1145],{"class":821,"line":1144},56,[819,1146,1147],{},"class SignalStore:\n",[819,1149,1151],{"class":821,"line":1150},57,[819,1152,1153],{},"    \"\"\"Thread-safe store of per-signal parameters.\"\"\"\n",[819,1155,1157],{"class":821,"line":1156},58,[819,1158,838],{"emptyLinePlaceholder":837},[819,1160,1162],{"class":821,"line":1161},59,[819,1163,1164],{},"    def __init__(self, initial):\n",[819,1166,1168],{"class":821,"line":1167},60,[819,1169,1170],{},"        self._lock = threading.Lock()\n",[819,1172,1174],{"class":821,"line":1173},61,[819,1175,1176],{},"        # deep-ish copy so INITIAL_PARAMS is not mutated by runtime commands\n",[819,1178,1180],{"class":821,"line":1179},62,[819,1181,1182],{},"        self._sig = {n: dict(p) for n, p in initial.items()}\n",[819,1184,1186],{"class":821,"line":1185},63,[819,1187,838],{"emptyLinePlaceholder":837},[819,1189,1191],{"class":821,"line":1190},64,[819,1192,1193],{},"    def value(self, name, t):\n",[819,1195,1197],{"class":821,"line":1196},65,[819,1198,1199],{},"        with self._lock:\n",[819,1201,1203],{"class":821,"line":1202},66,[819,1204,1205],{},"            p = self._sig[name]\n",[819,1207,1209],{"class":821,"line":1208},67,[819,1210,1211],{},"            A, O, f, phi = p[\"A\"], p[\"O\"], p[\"f\"], p[\"phi\"]\n",[819,1213,1215],{"class":821,"line":1214},68,[819,1216,1217],{},"        return O + A * math.sin(2.0 * math.pi * f * t + phi)\n",[819,1219,1221],{"class":821,"line":1220},69,[819,1222,838],{"emptyLinePlaceholder":837},[819,1224,1226],{"class":821,"line":1225},70,[819,1227,1228],{},"    def set_param(self, name, param, value):\n",[819,1230,1232],{"class":821,"line":1231},71,[819,1233,1199],{},[819,1235,1237],{"class":821,"line":1236},72,[819,1238,1239],{},"            if name not in self._sig or param not in PARAM_NAMES:\n",[819,1241,1243],{"class":821,"line":1242},73,[819,1244,1245],{},"                return False\n",[819,1247,1249],{"class":821,"line":1248},74,[819,1250,1251],{},"            self._sig[name][param] = float(value)\n",[819,1253,1255],{"class":821,"line":1254},75,[819,1256,1257],{},"            return True\n",[819,1259,1261],{"class":821,"line":1260},76,[819,1262,838],{"emptyLinePlaceholder":837},[819,1264,1266],{"class":821,"line":1265},77,[819,1267,838],{"emptyLinePlaceholder":837},[819,1269,1271],{"class":821,"line":1270},78,[819,1272,1273],{},"def apply_line(store, raw):\n",[819,1275,1277],{"class":821,"line":1276},79,[819,1278,1279],{},"    \"\"\"One incoming line: {\"name\": \"sine1_A\", \"value\": 2.0} -> sine1.A = 2.0.\"\"\"\n",[819,1281,1283],{"class":821,"line":1282},80,[819,1284,1285],{},"    line = raw.strip()\n",[819,1287,1289],{"class":821,"line":1288},81,[819,1290,1291],{},"    if not line:\n",[819,1293,1295],{"class":821,"line":1294},82,[819,1296,1297],{},"        return\n",[819,1299,1301],{"class":821,"line":1300},83,[819,1302,1303],{},"    try:\n",[819,1305,1307],{"class":821,"line":1306},84,[819,1308,1309],{},"        msg = json.loads(line.decode(\"utf-8\"))\n",[819,1311,1313],{"class":821,"line":1312},85,[819,1314,1315],{},"    except (json.JSONDecodeError, UnicodeDecodeError):\n",[819,1317,1319],{"class":821,"line":1318},86,[819,1320,1297],{},[819,1322,1324],{"class":821,"line":1323},87,[819,1325,1326],{},"    name, value = msg.get(\"name\"), msg.get(\"value\")\n",[819,1328,1330],{"class":821,"line":1329},88,[819,1331,1332],{},"    if not isinstance(name, str) or \"_\" not in name or value is None:\n",[819,1334,1336],{"class":821,"line":1335},89,[819,1337,1297],{},[819,1339,1341],{"class":821,"line":1340},90,[819,1342,1343],{},"    signal, param = name.rsplit(\"_\", 1)\n",[819,1345,1347],{"class":821,"line":1346},91,[819,1348,1349],{},"    if store.set_param(signal, param, value):\n",[819,1351,1353],{"class":821,"line":1352},92,[819,1354,1355],{},"        print(f\"{signal}.{param} = {value}\", flush=True)\n",[819,1357,1359],{"class":821,"line":1358},93,[819,1360,838],{"emptyLinePlaceholder":837},[819,1362,1364],{"class":821,"line":1363},94,[819,1365,838],{"emptyLinePlaceholder":837},[819,1367,1369],{"class":821,"line":1368},95,[819,1370,1371],{},"def reader_thread(readable, store, stop):\n",[819,1373,1375],{"class":821,"line":1374},96,[819,1376,1377],{},"    \"\"\"Listen for lines from QInsight and apply parameter changes.\"\"\"\n",[819,1379,1381],{"class":821,"line":1380},97,[819,1382,1303],{},[819,1384,1386],{"class":821,"line":1385},98,[819,1387,1388],{},"        for raw in readable:                 # read line by line (socket file \u002F serial port)\n",[819,1390,1392],{"class":821,"line":1391},99,[819,1393,1394],{},"            if stop.is_set():\n",[819,1396,1398],{"class":821,"line":1397},100,[819,1399,1400],{},"                break\n",[819,1402,1404],{"class":821,"line":1403},101,[819,1405,1406],{},"            apply_line(store, raw)\n",[819,1408,1410],{"class":821,"line":1409},102,[819,1411,1412],{},"    except (OSError, ValueError):\n",[819,1414,1416],{"class":821,"line":1415},103,[819,1417,1418],{},"        pass\n",[819,1420,1422],{"class":821,"line":1421},104,[819,1423,1424],{},"    finally:\n",[819,1426,1428],{"class":821,"line":1427},105,[819,1429,1430],{},"        stop.set()\n",[819,1432,1434],{"class":821,"line":1433},106,[819,1435,838],{"emptyLinePlaceholder":837},[819,1437,1439],{"class":821,"line":1438},107,[819,1440,838],{"emptyLinePlaceholder":837},[819,1442,1444],{"class":821,"line":1443},108,[819,1445,1446],{},"def send_loop(write, store, stop):\n",[819,1448,1450],{"class":821,"line":1449},109,[819,1451,1452],{},"    \"\"\"Send all signals SEND_HZ times per second until stop is set or the link breaks.\"\"\"\n",[819,1454,1456],{"class":821,"line":1455},110,[819,1457,1458],{},"    t0 = time.monotonic()\n",[819,1460,1462],{"class":821,"line":1461},111,[819,1463,1464],{},"    period = 1.0 \u002F SEND_HZ\n",[819,1466,1468],{"class":821,"line":1467},112,[819,1469,1470],{},"    next_t = time.monotonic()\n",[819,1472,1474],{"class":821,"line":1473},113,[819,1475,1303],{},[819,1477,1479],{"class":821,"line":1478},114,[819,1480,1481],{},"        while not stop.is_set():\n",[819,1483,1485],{"class":821,"line":1484},115,[819,1486,1487],{},"            now = time.monotonic() - t0\n",[819,1489,1491],{"class":821,"line":1490},116,[819,1492,1493],{},"            for name in SIGNAL_NAMES:                  # 5 messages, one signal each\n",[819,1495,1497],{"class":821,"line":1496},117,[819,1498,1499],{},"                msg = {\"name\": name, \"value\": store.value(name, now), \"t\": round(now, 4)}\n",[819,1501,1503],{"class":821,"line":1502},118,[819,1504,1505],{},"                write((json.dumps(msg) + \"\\n\").encode(\"utf-8\"))\n",[819,1507,1509],{"class":821,"line":1508},119,[819,1510,1511],{},"            next_t += period\n",[819,1513,1515],{"class":821,"line":1514},120,[819,1516,1517],{},"            time.sleep(max(0.0, next_t - time.monotonic()))\n",[819,1519,1521],{"class":821,"line":1520},121,[819,1522,1523],{},"    except OSError:\n",[819,1525,1527],{"class":821,"line":1526},122,[819,1528,1418],{},[819,1530,1532],{"class":821,"line":1531},123,[819,1533,1534],{},"    except KeyboardInterrupt:\n",[819,1536,1538],{"class":821,"line":1537},124,[819,1539,1430],{},[819,1541,1543],{"class":821,"line":1542},125,[819,1544,1545],{},"        raise\n",[819,1547,1549],{"class":821,"line":1548},126,[819,1550,1424],{},[819,1552,1554],{"class":821,"line":1553},127,[819,1555,1430],{},[819,1557,1559],{"class":821,"line":1558},128,[819,1560,838],{"emptyLinePlaceholder":837},[819,1562,1564],{"class":821,"line":1563},129,[819,1565,838],{"emptyLinePlaceholder":837},[819,1567,1569],{"class":821,"line":1568},130,[819,1570,1571],{},"def serve_tcp(host, port, store):\n",[819,1573,1575],{"class":821,"line":1574},131,[819,1576,1577],{},"    srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n",[819,1579,1581],{"class":821,"line":1580},132,[819,1582,1583],{},"    srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)\n",[819,1585,1587],{"class":821,"line":1586},133,[819,1588,1589],{},"    srv.bind((host, port))\n",[819,1591,1593],{"class":821,"line":1592},134,[819,1594,1595],{},"    srv.listen(1)\n",[819,1597,1599],{"class":821,"line":1598},135,[819,1600,1601],{},"    # Windows delivers Ctrl+C to the main thread only when it is not stuck in a blocking\n",[819,1603,1605],{"class":821,"line":1604},136,[819,1606,1607],{},"    # socket call, so accept() polls with a timeout instead of blocking forever.\n",[819,1609,1611],{"class":821,"line":1610},137,[819,1612,1613],{},"    srv.settimeout(0.5)\n",[819,1615,1617],{"class":821,"line":1616},138,[819,1618,1619],{},"    print(f\"Generator listening on {host}:{port} - connect QInsight with the TCP Client driver (Ctrl+C to stop)\", flush=True)\n",[819,1621,1623],{"class":821,"line":1622},139,[819,1624,1303],{},[819,1626,1628],{"class":821,"line":1627},140,[819,1629,1630],{},"        while True:\n",[819,1632,1634],{"class":821,"line":1633},141,[819,1635,1636],{},"            try:\n",[819,1638,1640],{"class":821,"line":1639},142,[819,1641,1642],{},"                conn, addr = srv.accept()\n",[819,1644,1646],{"class":821,"line":1645},143,[819,1647,1648],{},"            except socket.timeout:\n",[819,1650,1652],{"class":821,"line":1651},144,[819,1653,1654],{},"                continue\n",[819,1656,1658],{"class":821,"line":1657},145,[819,1659,1660],{},"            conn.settimeout(None)\n",[819,1662,1664],{"class":821,"line":1663},146,[819,1665,1666],{},"            print(f\"QInsight connected: {addr}\", flush=True)\n",[819,1668,1670],{"class":821,"line":1669},147,[819,1671,1672],{},"            stop = threading.Event()\n",[819,1674,1676],{"class":821,"line":1675},148,[819,1677,1678],{},"            threading.Thread(target=reader_thread, args=(conn.makefile(\"rb\"), store, stop), daemon=True).start()\n",[819,1680,1682],{"class":821,"line":1681},149,[819,1683,1684],{},"            send_loop(conn.sendall, store, stop)\n",[819,1686,1688],{"class":821,"line":1687},150,[819,1689,1690],{},"            conn.close()\n",[819,1692,1694],{"class":821,"line":1693},151,[819,1695,1696],{},"            print(f\"QInsight disconnected: {addr}\")\n",[819,1698,1700],{"class":821,"line":1699},152,[819,1701,1534],{},[819,1703,1705],{"class":821,"line":1704},153,[819,1706,1418],{},[819,1708,1710],{"class":821,"line":1709},154,[819,1711,1424],{},[819,1713,1715],{"class":821,"line":1714},155,[819,1716,1717],{},"        srv.close()\n",[819,1719,1721],{"class":821,"line":1720},156,[819,1722,838],{"emptyLinePlaceholder":837},[819,1724,1726],{"class":821,"line":1725},157,[819,1727,838],{"emptyLinePlaceholder":837},[819,1729,1731],{"class":821,"line":1730},158,[819,1732,1733],{},"def serve_serial(port, baud, store):\n",[819,1735,1737],{"class":821,"line":1736},159,[819,1738,1739],{},"    import serial  # pyserial\n",[819,1741,1743],{"class":821,"line":1742},160,[819,1744,1745],{},"    ser = serial.Serial(port, baud, timeout=1)\n",[819,1747,1749],{"class":821,"line":1748},161,[819,1750,1751],{},"    print(f\"Generator on {port} @ {baud} baud - connect QInsight with the Serial Port driver\")\n",[819,1753,1755],{"class":821,"line":1754},162,[819,1756,1757],{},"    stop = threading.Event()\n",[819,1759,1761],{"class":821,"line":1760},163,[819,1762,838],{"emptyLinePlaceholder":837},[819,1764,1766],{"class":821,"line":1765},164,[819,1767,1768],{},"    def lines():\n",[819,1770,1772],{"class":821,"line":1771},165,[819,1773,1481],{},[819,1775,1777],{"class":821,"line":1776},166,[819,1778,1779],{},"            raw = ser.readline()\n",[819,1781,1783],{"class":821,"line":1782},167,[819,1784,1785],{},"            if raw:\n",[819,1787,1789],{"class":821,"line":1788},168,[819,1790,1791],{},"                yield raw\n",[819,1793,1795],{"class":821,"line":1794},169,[819,1796,838],{"emptyLinePlaceholder":837},[819,1798,1800],{"class":821,"line":1799},170,[819,1801,1802],{},"    threading.Thread(target=reader_thread, args=(lines(), store, stop), daemon=True).start()\n",[819,1804,1806],{"class":821,"line":1805},171,[819,1807,1303],{},[819,1809,1811],{"class":821,"line":1810},172,[819,1812,1813],{},"        send_loop(ser.write, store, stop)\n",[819,1815,1817],{"class":821,"line":1816},173,[819,1818,1534],{},[819,1820,1822],{"class":821,"line":1821},174,[819,1823,1418],{},[819,1825,1827],{"class":821,"line":1826},175,[819,1828,1424],{},[819,1830,1832],{"class":821,"line":1831},176,[819,1833,1430],{},[819,1835,1837],{"class":821,"line":1836},177,[819,1838,1839],{},"        ser.close()\n",[819,1841,1843],{"class":821,"line":1842},178,[819,1844,838],{"emptyLinePlaceholder":837},[819,1846,1848],{"class":821,"line":1847},179,[819,1849,838],{"emptyLinePlaceholder":837},[819,1851,1853],{"class":821,"line":1852},180,[819,1854,1855],{},"def main():\n",[819,1857,1859],{"class":821,"line":1858},181,[819,1860,1861],{},"    parser = argparse.ArgumentParser(description=\"JSON Signal Stream sine generator (TCP server or serial port).\")\n",[819,1863,1865],{"class":821,"line":1864},182,[819,1866,1867],{},"    parser.add_argument(\"--host\", default=\"0.0.0.0\", help=\"TCP bind address (default 0.0.0.0)\")\n",[819,1869,1871],{"class":821,"line":1870},183,[819,1872,1873],{},"    parser.add_argument(\"--port\", type=int, default=5000, help=\"TCP port (default 5000)\")\n",[819,1875,1877],{"class":821,"line":1876},184,[819,1878,1879],{},"    parser.add_argument(\"--serial\", metavar=\"PORT\", help=\"use a serial port instead of TCP, e.g. COM7 or \u002Fdev\u002FttyUSB0\")\n",[819,1881,1883],{"class":821,"line":1882},185,[819,1884,1885],{},"    parser.add_argument(\"--baud\", type=int, default=115200, help=\"serial baud rate (default 115200)\")\n",[819,1887,1889],{"class":821,"line":1888},186,[819,1890,1891],{},"    args = parser.parse_args()\n",[819,1893,1895],{"class":821,"line":1894},187,[819,1896,838],{"emptyLinePlaceholder":837},[819,1898,1900],{"class":821,"line":1899},188,[819,1901,1902],{},"    store = SignalStore(INITIAL_PARAMS)\n",[819,1904,1906],{"class":821,"line":1905},189,[819,1907,1908],{},"    if args.serial:\n",[819,1910,1912],{"class":821,"line":1911},190,[819,1913,1914],{},"        serve_serial(args.serial, args.baud, store)\n",[819,1916,1918],{"class":821,"line":1917},191,[819,1919,1920],{},"    else:\n",[819,1922,1924],{"class":821,"line":1923},192,[819,1925,1926],{},"        serve_tcp(args.host, args.port, store)\n",[819,1928,1930],{"class":821,"line":1929},193,[819,1931,838],{"emptyLinePlaceholder":837},[819,1933,1935],{"class":821,"line":1934},194,[819,1936,838],{"emptyLinePlaceholder":837},[819,1938,1940],{"class":821,"line":1939},195,[819,1941,1942],{},"if __name__ == \"__main__\":\n",[819,1944,1946],{"class":821,"line":1945},196,[819,1947,1948],{},"    main()\n",[380,1950,1952],{"id":1951},"související-kapitoly","Související kapitoly",[412,1954,1955,1960,1971],{},[415,1956,1957,1959],{},[389,1958,392],{"href":391}," v referenci protokolů",[415,1961,1962,551,1966,1970],{},[389,1963,1965],{"href":1964},"\u002Fcs\u002Freference\u002Fdrivers#tcp-client","TCP Client",[389,1967,1969],{"href":1968},"\u002Fcs\u002Freference\u002Fdrivers#serial-port-com","Serial Port"," v referenci driverů",[415,1972,1973],{},[389,1974,118],{"href":119},[1976,1977,1978],"style",{},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":466,"searchDepth":834,"depth":834,"links":1980},[1981,1982,1983,1984,1989,1990,1991],{"id":382,"depth":828,"text":383},{"id":524,"depth":828,"text":525},{"id":571,"depth":828,"text":572},{"id":598,"depth":828,"text":599,"children":1985},[1986,1987,1988],{"id":603,"depth":834,"text":604},{"id":617,"depth":834,"text":81},{"id":758,"depth":834,"text":116},{"id":764,"depth":828,"text":765},{"id":799,"depth":828,"text":800},{"id":1951,"depth":828,"text":1952},"Dvě ukázky protokolu JSON Signal Stream — pět sinusů z přiloženého Python skriptu po TCP nebo po sériové lince, zápis amplitudy a frekvence zpět do generátoru.","md",{},{"title":351,"description":1992},"FDAXEG0XTP02TwsU8c2kAgdAFZIhFvZp5j4wpOfYAKU",[1998,1999],{"title":347,"path":348,"stem":349,"navTitle":347,"children":-1},{"title":356,"path":357,"stem":358,"navTitle":359,"children":-1},1795105301238]