Typica is a free program for professional coffee roasters. https://typica.us
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

productionroaster.xml 33KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875
  1. <window id="basicWindow">
  2. <layout type="vertical">
  3. <splitter type = "vertical" id = "main">
  4. <splitter type = "horizontal" id = "indicators" />
  5. <widget id="widget">
  6. <layout type="horizontal" id="controlpanel">
  7. <button name="Start Batch" type="push" id="startbutton" />
  8. <button name="Stop Batch" type="annotation" id="stopbutton" annotation="End" />
  9. </layout>
  10. </widget>
  11. <splitter type="horizontal" id="logsplit">
  12. <measurementtable id="log" />
  13. <graph id="graph" />
  14. </splitter>
  15. </splitter>
  16. </layout>
  17. <menu name="File">
  18. <item id="open" shortcut="Ctrl+O">Open…</item>
  19. <item id="save" shortcut="Ctrl+S">Save…</item>
  20. <item id="print" shortcut="Ctrl+P">Print…</item>
  21. <item id="export">Export CSV…</item>
  22. <item id="svgexport">Export XHTML+SVG…</item>
  23. <item id="quit" shortcut="Ctrl+Q">Quit</item>
  24. </menu>
  25. <menu name="Batch">
  26. <item id="new" shortcut="Ctrl+N">New Batch…</item>
  27. <item id="compare">Load Additional Profiles...</item>
  28. </menu>
  29. <menu name="Log">
  30. <item id="showC">Display Celsius</item>
  31. <item id="showF">Display Fahrenheit</item>
  32. <item id="setSample">New Sample Parameters</item>
  33. <separator />
  34. <item id="clear" shortcut="Ctrl+L">Clear Log</item>
  35. <separator />
  36. <item id="ms">Millisecond View</item>
  37. <item id="1s">1 Second View</item>
  38. <item id="5s">5 Second View</item>
  39. <item id="10s">10 Second View</item>
  40. <item id="15s">15 Second View</item>
  41. <item id="30s">30 Second View</item>
  42. <item id="1m">1 Minute View</item>
  43. <separator />
  44. <item id="manual" shortcut="Ctrl+E">Manual Entry</item>
  45. </menu>
  46. <menu name="Graph">
  47. <item id="unshift">Reset Translation</item>
  48. </menu>
  49. <program>
  50. <![CDATA[
  51. var window = this;
  52. var targetOffset = 0;
  53. var gtrans = 0;
  54. var targetDetector = new ThresholdDetector;
  55. window.targetcolumnname = "";
  56. var currentDetector = new ThresholdDetector;
  57. var translationChannel = -1;
  58. targetDetector.timeForValue.connect(function(value) {
  59. targetOffset = value;
  60. });
  61. var epoch = new QTime;
  62. epoch = epoch.currentTime;
  63. var translationCurrentColumn = -1;
  64. var configModel = new DeviceTreeModel;
  65. var rootIndex = configModel.index(roasterlist.currentIndex, 0);
  66. var channels = new Array();
  67. var annotationButtons = new Array();
  68. var nidevices = new Array();
  69. var dataqsdkdevices = new Array();
  70. var temperatureDisplays = new Array();
  71. var columnNames = new Array();
  72. var modbusdevices = new Array();
  73. var rateCalculators = new Array();
  74. var rateadapters = new Array();
  75. var rateoffsets = new Array();
  76. var ratezeros = new Array();
  77. var channelType = new Array();
  78. window.scales = new Array();
  79. var indicatorPanel = findChildObject(this, 'indicators');
  80. var annotationPanel = findChildObject(this, 'controlpanel');
  81. var log = findChildObject(this, 'log');
  82. var tabControls = new Array();
  83. var start = findChildObject(this, 'startbutton');
  84. var stop = findChildObject(this, 'stopbutton');
  85. stop.enabled = false;
  86. tabControls.push(start);
  87. tabControls.push(stop);
  88. var nsparam = findChildObject(this, 'setSample');
  89. nsparam.enabled = false;
  90. var graph = findChildObject(this, 'graph');
  91. var hasTranslated = false;
  92. var externtrans = undefined;
  93. window.translateLoadedSeries = function(translation) {
  94. var lc = Number(QSettings.value("liveColumn"));
  95. for(var i = 1; i < lc - 1; i++)
  96. {
  97. graph.setSeriesTranslation(i, translation);
  98. }
  99. };
  100. window.translateCurrentSeries = function(translation) {
  101. var lc = Number(QSettings.value("liveColumn"));
  102. for(var i = 0; i < columnNames.length; i++)
  103. {
  104. graph.setSeriesTranslation(lc + i, translation);
  105. }
  106. };
  107. var selectedRoasterName = configModel.data(rootIndex, 0);
  108. var machineReference = configModel.referenceElement(configModel.data(rootIndex, 32));
  109. var selectedRoasterID = machineReference.databaseid;
  110. if(configModel.hasChildren(rootIndex)) {
  111. for(var i = 0; i < configModel.rowCount(rootIndex); i++) {
  112. var driverIndex = configModel.index(i, 0, rootIndex);
  113. var driverReference = configModel.referenceElement(configModel.data(driverIndex, 32));
  114. if(driverReference.driver == "nidaqmxbase" || driverReference.driver == "nidaqmx") {
  115. if(configModel.hasChildren(driverIndex)) {
  116. for(var j = 0; j < configModel.rowCount(driverIndex); j++) {
  117. var deviceIndex = configModel.index(j, 0, driverIndex);
  118. var deviceReference = configModel.referenceElement(configModel.data(deviceIndex, 32));
  119. if(deviceReference.driver == "nidaqmxbase9211series" || deviceReference.driver == "nidaqmx9211series") {
  120. var device = new DAQ(deviceReference.deviceID, driverReference.driver);
  121. nidevices.push(device);
  122. var DAQChannels = 0;
  123. if(configModel.hasChildren(deviceIndex)) {
  124. for(var k = 0; k < configModel.rowCount(deviceIndex); k++) {
  125. var channelIndex = configModel.index(k, 0, deviceIndex);
  126. var channelReference = configModel.referenceElement(configModel.data(channelIndex, 32));
  127. if(channelReference.driver == "ni9211seriestc") {
  128. var channel;
  129. if(channelReference.type == "J") {
  130. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeJ);
  131. }
  132. else if(channelReference.type == "K") {
  133. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeK);
  134. }
  135. else if(channelReference.type == "T") {
  136. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeT);
  137. }
  138. else if(channelReference.type == "B") {
  139. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeB);
  140. }
  141. else if(channelReference.type == "E") {
  142. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeE);
  143. }
  144. else if(channelReference.type == "N") {
  145. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeN);
  146. }
  147. else if(channelReference.type == "R") {
  148. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeR);
  149. }
  150. else if(channelReference.type == "S") {
  151. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeS);
  152. }
  153. channels.push(channel);
  154. channelType.push("T");
  155. columnNames.push(channelReference.columnname);
  156. DAQChannels++;
  157. var indicator = new TemperatureDisplay;
  158. temperatureDisplays.push(indicator);
  159. var decorator = new WidgetDecorator(indicator, configModel.data(channelIndex, 0), 2);
  160. channel.newData.connect(indicator.setValue);
  161. indicatorPanel.addWidget(decorator);
  162. }
  163. }
  164. switch(DAQChannels) {
  165. case 1:
  166. device.setClockRate(4);
  167. break;
  168. case 2:
  169. device.setClockRate(2);
  170. break;
  171. case 3:
  172. device.setClockRate(1.5);
  173. break;
  174. case 4:
  175. device.setClockRate(1);
  176. break;
  177. }
  178. device.start();
  179. }
  180. }
  181. else if(deviceReference.driver == "nidaqmxtc01")
  182. {
  183. var device = new DAQ(deviceReference.deviceID, "nidaqmx");
  184. var channel;
  185. if(deviceReference.type == "J")
  186. {
  187. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeJ);
  188. }
  189. else if(deviceReference.type == "K")
  190. {
  191. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeK);
  192. }
  193. else if(deviceReference.type == "T")
  194. {
  195. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeT);
  196. }
  197. else if(deviceReference.type == "B")
  198. {
  199. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeB);
  200. }
  201. else if(deviceReference.type == "E")
  202. {
  203. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeE);
  204. }
  205. else if(deviceReference.type == "N")
  206. {
  207. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeN);
  208. }
  209. else if(deviceReference.type == "R")
  210. {
  211. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeR);
  212. }
  213. else if(deviceReference.type == "S")
  214. {
  215. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeS);
  216. }
  217. channels.push(channel);
  218. channelType.push("T");
  219. columnNames.push(deviceReference.columnname);
  220. var indicator = new TemperatureDisplay;
  221. temperatureDisplays.push(indicator);
  222. var decorator = new WidgetDecorator(indicator, configModel.data(deviceIndex, 0), 2);
  223. channel.newData.connect(indicator.setValue);
  224. indicatorPanel.addWidget(decorator);
  225. device.start();
  226. nidevices.push(device);
  227. }
  228. }
  229. }
  230. }
  231. else if(driverReference.driver == "dataqsdk") {
  232. var device;
  233. if(driverReference.autoSelect == "true") {
  234. device = new DataqSdkDevice(driverReference.deviceNumber);
  235. }
  236. else {
  237. device = new DataqSdkDevice(driverReference.port);
  238. }
  239. var sampleRate = 6;
  240. if(configModel.hasChildren(driverIndex)) {
  241. for(var j = 0; j < configModel.rowCount(driverIndex); j++) {
  242. var channelIndex = configModel.index(j, 0, driverIndex);
  243. var channelReference = configModel.referenceElement(configModel.data(channelIndex, 32));
  244. var indicator = new TemperatureDisplay;
  245. var unit;
  246. if(channelReference.type == "Temperature") {
  247. unit = Units.Fahrenheit;
  248. channelType.push("T");
  249. temperatureDisplays.push(indicator);
  250. }
  251. else {
  252. unit = Units.Unitless;
  253. indicator.setDisplayUnits(Units.Unitless);
  254. channelType.push("C");
  255. indicator.digitCount = 6;
  256. }
  257. var channel = device.newChannel(unit);
  258. var calibrator = new LinearCalibrator;
  259. calibrator.measuredLower = channelReference.calibrationMeasuredLower;
  260. calibrator.measuredUpper = channelReference.calibrationMeasuredUpper;
  261. calibrator.mappedLower = channelReference.calibrationMappedLower;
  262. calibrator.mappedUpper = channelReference.calibrationMappedUpper;
  263. calibrator.sensitivity = channelReference.calibrationSensitivity;
  264. if(channelReference.calibrationClosedInterval == 'true') {
  265. calibrator.closedRange = true;
  266. }
  267. // device.setSmoothingEnabled(j) = channelReference.smoothing;
  268. channel.newData.connect(calibrator.newMeasurement)
  269. channels.push(calibrator);
  270. columnNames.push(channelReference.column);
  271. var decorator = new WidgetDecorator(indicator, configModel.data(channelIndex, 0), 2);
  272. calibrator.newData.connect(indicator.setValue);
  273. indicatorPanel.addWidget(decorator);
  274. }
  275. sampleRate /= configModel.rowCount(driverIndex);
  276. }
  277. device.setClockRate(sampleRate);
  278. device.start();
  279. dataqsdkdevices.push(device);
  280. }
  281. else if(driverReference.driver == "modbusrtu")
  282. {
  283. var device = new ModbusRTUDevice(configModel, driverIndex);
  284. modbusdevices.push(device);
  285. var pvchannel = device.pVChannel();
  286. channels.push(pvchannel);
  287. channelType.push("T");
  288. columnNames.push(driverReference.pvcolname);
  289. var indicator = new TemperatureDisplay;
  290. temperatureDisplays.push(indicator);
  291. var decorator = new WidgetDecorator(indicator, configModel.data(driverIndex, 0) + " PV", 2);
  292. pvchannel.newData.connect(indicator.setValue);
  293. indicatorPanel.addWidget(decorator);
  294. if(driverReference.sVEnabled == "true")
  295. {
  296. var svchannel = device.sVChannel();
  297. channels.push(svchannel);
  298. channelType.push("C");
  299. columnNames.push(driverReference.svcolname);
  300. var indicator = new TemperatureDisplay;
  301. temperatureDisplays.push(indicator);
  302. var decorator = new WidgetDecorator(indicator, configModel.data(driverIndex, 0) + " SV", 2);
  303. svchannel.newData.connect(indicator.setValue);
  304. indicatorPanel.addWidget(decorator);
  305. }
  306. if(driverReference.sVWritable == "true")
  307. {
  308. var outputControl = new AnnotationSpinBox;
  309. device.SVLowerChanged.connect(function(min) {
  310. outputControl.minimum = min;
  311. });
  312. outputControl.minimum = device.SVLower();
  313. device.SVUpperChanged.connect(function(max) {
  314. outputControl.maximum = max;
  315. });
  316. outputControl.maximum = device.SVUpper();
  317. device.SVDecimalChanged.connect(function(prec) {
  318. outputControl.decimals = prec;
  319. });
  320. outputControl.decimals = device.decimals();
  321. outputControl.editingFinished.connect(function() {
  322. device.outputSV(outputControl.value);
  323. });
  324. var layout = new QBoxLayout;
  325. var label = new QLabel("Change SV");
  326. layout.addWidget(label, 0, 2);
  327. layout.addWidget(outputControl, 0, 1);
  328. annotationPanel.addLayout(layout);
  329. tabControls.push(outputControl);
  330. }
  331. }
  332. else if(driverReference.driver == "annotationbutton")
  333. {
  334. var button = new AnnotationButton(driverReference.buttontext);
  335. button.setAnnotation(driverReference.annotationtext);
  336. annotationButtons.push(button);
  337. annotationPanel.addWidget(button);
  338. tabControls.push(button);
  339. }
  340. else if(driverReference.driver == "valueannotation")
  341. {
  342. var checker = new ValueAnnotation;
  343. var valuesSetting = driverReference.measuredValues;
  344. var notesSetting = driverReference.annotations;
  345. var valuesList = valuesSetting.slice(2, valuesSetting.length-2).split(",");
  346. var notesList = notesSetting.slice(2, notesSetting.length-2).split(",");
  347. if(valuesList.length > 1 && notesList.length == valuesList.length) {
  348. for(var j = 0; j < valuesList.length; j++) {
  349. checker.setAnnotation(Number(valuesList[j]), notesList[j]);
  350. }
  351. }
  352. if(driverReference.emitOnStart == "true") {
  353. start.clicked.connect(checker.annotate);
  354. }
  355. var colname = driverReference.source;
  356. for(var j = 0; j < columnNames.length; j++) {
  357. if(columnNames[j] == colname) {
  358. channels[j].newData.connect(checker.newMeasurement);
  359. break;
  360. }
  361. }
  362. annotationButtons.push(checker);
  363. }
  364. else if(driverReference.driver == "reconfigurablebutton")
  365. {
  366. var button = new AnnotationButton(driverReference.buttontext);
  367. button.setAnnotation(driverReference.annotationtext);
  368. annotationButtons.push(button);
  369. annotationPanel.addWidget(button);
  370. tabControls.push(button);
  371. nsparam.enabled = true;
  372. nsparam.triggered.connect(function() {
  373. var setParam = createWindow("sampleParameters");
  374. setParam.windowTitle = "Typica - Set Sample Parameters";
  375. setParam.button = button;
  376. });
  377. }
  378. else if(driverReference.driver == "annotationspinbox")
  379. {
  380. var layout = new QBoxLayout;
  381. var label = new QLabel(driverReference.label);
  382. layout.addWidget(label, 0, 2);
  383. var spinbox = new AnnotationSpinBox;
  384. spinbox.setPretext(driverReference.pretext);
  385. spinbox.setPosttext(driverReference.posttext);
  386. spinbox.minimum = driverReference.minimum;
  387. spinbox.maximum = driverReference.maximum;
  388. spinbox.decimals = driverReference.precision;
  389. layout.addWidget(spinbox, 0, 1);
  390. annotationPanel.addLayout(layout);
  391. annotationButtons.push(spinbox);
  392. tabControls.push(spinbox);
  393. }
  394. else if(driverReference.driver == "freeannotation")
  395. {
  396. var layout = new QBoxLayout;
  397. var label = new QLabel(driverReference.labeltext);
  398. var control = new QLineEdit;
  399. layout.addWidget(label, 0, 2);
  400. layout.addWidget(control, 0, 1);
  401. annotationPanel.addLayout(layout);
  402. tabControls.push(control);
  403. control.returnPressed.connect(function() {
  404. for(var i = window.firstTempColumn; i < window.annotationColumn; i++) {
  405. log.newAnnotation(control.text, i, window.annotationColumn);
  406. }
  407. });
  408. }
  409. else if(driverReference.driver == "linearspline")
  410. {
  411. var colname = driverReference.source;
  412. for(var j = 0; j < columnNames.length; j++)
  413. {
  414. if(columnNames[j] == colname)
  415. {
  416. var calibrator = new LinearSplineInterpolator;
  417. var sv = driverReference.sourcevalues;
  418. var dv = driverReference.destinationvalues;
  419. var sourcevalues = sv.slice(2, sv.length-2).split(",");
  420. var destvalues = dv.slice(2, dv.length-2).split(",");
  421. if(sourcevalues.length > 1 && destvalues.length == sourcevalues.length)
  422. {
  423. for(var k = 0; k < sourcevalues.length; k++)
  424. {
  425. calibrator.add_pair(Number(sourcevalues[k]),Number(destvalues[k]));
  426. }
  427. var indicator = new TemperatureDisplay;
  428. temperatureDisplays.push(indicator);
  429. var decorator = new WidgetDecorator(indicator, configModel.data(driverIndex, 0), 2);
  430. channels[j].newData.connect(calibrator.newMeasurement);
  431. calibrator.newData.connect(indicator.setValue);
  432. channels.push(calibrator);
  433. channelType.push(channelType[j]);
  434. columnNames.push(driverReference.destination);
  435. indicatorPanel.addWidget(decorator);
  436. }
  437. break;
  438. }
  439. }
  440. }
  441. else if(driverReference.driver == "translation")
  442. {
  443. var colname = driverReference.column;
  444. window.targetcolumnname = colname;
  445. for(var j = 0; j < columnNames.length; j++)
  446. {
  447. if(columnNames[j] == colname)
  448. {
  449. translationChannel = j;
  450. var indicator = new TemperatureDisplay;
  451. indicator.digitCount = 4;
  452. externtrans = indicator;
  453. indicator.display(0);
  454. var decorator = new WidgetDecorator(indicator, configModel.data(driverIndex, 0), 2);
  455. indicatorPanel.addWidget(decorator);
  456. currentDetector.timeForValue.connect(function(value) {
  457. if(!hasTranslated)
  458. {
  459. var currentOffset = value;
  460. if(targetOffset != 0)
  461. {
  462. var translation = currentOffset - targetOffset;
  463. externtrans.display(translation);
  464. gtrans = translation;
  465. if(translation > 0)
  466. {
  467. window.translateLoadedSeries(translation);
  468. }
  469. else
  470. {
  471. window.translateCurrentSeries(-translation);
  472. }
  473. }
  474. }
  475. hasTranslated = true;
  476. });
  477. var resetTranslation = findChildObject(this, 'unshift');
  478. resetTranslation.triggered.connect(function() {
  479. if(gtrans > 0) {
  480. window.translateLoadedSeries(-gtrans);
  481. }
  482. else {
  483. window.translateCurrentSeries(gtrans);
  484. }
  485. gtrans = 0;
  486. indicator.display(0);
  487. });
  488. }
  489. }
  490. targetDetector.setThreshold(driverReference.FValue);
  491. currentDetector.setThreshold(driverReference.FValue);
  492. }
  493. else if(driverReference.driver == "rate")
  494. {
  495. var primaryColumn = driverReference.column;
  496. for(var j = 0; j < columnNames.length; j++)
  497. {
  498. if(columnNames[j] == primaryColumn)
  499. {
  500. var rate = new RateOfChange(driverReference.cache, driverReference.scale);
  501. channels[j].newData.connect(rate.newMeasurement);
  502. var indicator = new TemperatureDisplay;
  503. indicator.setRelativeMode(true);
  504. indicator.display(0);
  505. indicator.digitCount = 9;
  506. var decorator = new WidgetDecorator(indicator, configModel.data(driverIndex, 0), 2);
  507. indicatorPanel.addWidget(decorator);
  508. rate.newData.connect(indicator.setValue);
  509. temperatureDisplays.push(indicator);
  510. channels.push(rate);
  511. channelType.push("T");
  512. columnNames.push(configModel.data(driverIndex, 0));
  513. }
  514. }
  515. }
  516. else if(driverReference.driver == "scale")
  517. {
  518. var scale = new SerialScale(driverReference.port);
  519. scale.setDataBits(8);
  520. scale.setBaudRate(driverReference.baudrate);
  521. scale.setParity(driverReference.parity);
  522. scale.setStopBits(driverReference.stopbits);
  523. scale.setFlowControl(driverReference.flowcontrol);
  524. scale.open(3);
  525. window.scales.push(scale);
  526. }
  527. }
  528. }
  529. for(var i = 1; i < tabControls.length; i++)
  530. {
  531. setTabOrder(tabControls[i-1], tabControls[i]);
  532. }
  533. log.setHeaderData(0, "Time");
  534. for(var i = 0; i < columnNames.length; i++) {
  535. log.setHeaderData(i + 1, columnNames[i]);
  536. }
  537. log.setHeaderData(columnNames.length + 1, "Note");
  538. for(var i = 0; i < channels.length; i++) {
  539. log.addToCurrentColumnSet(i + 1);
  540. }
  541. var timer = new TimerDisplay;
  542. timer.displayFormat = "mm:ss";
  543. timer.autoReset = true;
  544. var btdecorator = new WidgetDecorator(timer, "Batch Timer", 2);
  545. indicatorPanel.addWidget(btdecorator);
  546. var vsplit = findChildObject(this, 'main');
  547. var isplit = findChildObject(this, 'indicators');
  548. var lsplit = findChildObject(this, 'logsplit');
  549. window.aboutToClose.connect(function() {
  550. for(var i = 0; i < nidevices.length; i++)
  551. {
  552. nidevices[i].stop();
  553. nidevices[i].deleteLater();
  554. }
  555. for(var i = 0; i < modbusdevices.length; i++)
  556. {
  557. modbusdevices[i].deleteLater();
  558. }
  559. for(var i = 0; i < dataqsdkdevices.length; i++)
  560. {
  561. dataqsdkdevices[i].deleteLater();
  562. }
  563. delete nidevices;
  564. delete modbusdevices;
  565. delete dataqsdkdevices;
  566. window.saveSizeAndPosition("window");
  567. vsplit.saveState("script/mainSplitter");
  568. isplit.saveState("script/instrumentSplitter");
  569. lsplit.saveState("script/logSplitter");
  570. log.saveState("script/log", 7);
  571. window.navigationWindow.loggingWindow = undefined;
  572. });
  573. this.restoreSizeAndPosition('window');
  574. vsplit.restoreState("script/mainSplitter");
  575. isplit.restoreState("script/instrumentSplitter");
  576. lsplit.restoreState("script/logSplitter");
  577. log.restoreState("script/log", 7);
  578. var offsets = new Array();
  579. var zeroemitters = new Array();
  580. var adapters = new Array();
  581. for(var i = 0; i < channels.length; i++) {
  582. var offset = new MeasurementTimeOffset(epoch);
  583. offsets.push(offset);
  584. channels[i].newData.connect(offset.newMeasurement);
  585. var adapter = new MeasurementAdapter(i + 1);
  586. adapters.push(adapter);
  587. offset.measurement.connect(adapter.newMeasurement);
  588. var emitter = new ZeroEmitter(i + 1);
  589. zeroemitters.push(emitter);
  590. channels[i].newData.connect(emitter.newMeasurement);
  591. emitter.measurement.connect(log.newMeasurement);
  592. emitter.measurement.connect(graph.newMeasurement);
  593. }
  594. start.clicked.connect(function() {
  595. start.enabled = false;
  596. hasTranslated = false;
  597. var epoch = new QTime();
  598. epoch = epoch.currentTime();
  599. for(var i = 0; i < offsets.length; i++)
  600. {
  601. offsets[i].setZeroTime(epoch);
  602. zeroemitters[i].emitZero();
  603. adapters[i].measurement.connect(log.newMeasurement);
  604. adapters[i].measurement.connect(graph.newMeasurement);
  605. }
  606. for(var i = 0; i < rateadapters.length; i++)
  607. {
  608. rateoffsets[i].setZeroTime(epoch);
  609. ratezeros[i].emitZero();
  610. rateadapters[i].measurement.connect(graph.newMeasurement);
  611. }
  612. timer.startTimer();
  613. if(typeof(currentBatchInfo) == 'undefined') { } else {
  614. query = new QSqlQuery();
  615. query.exec("SELECT now()::timestamp without time zone");
  616. query.next();
  617. var result = query.value(0);
  618. query = query.invalidate();
  619. var timefield = findChildObject(currentBatchInfo, 'time');
  620. timefield.text = result.replace('T', ' ');
  621. }
  622. if(translationChannel >= 0)
  623. {
  624. offsets[translationChannel].measurement.connect(currentDetector.newMeasurement);
  625. }
  626. if(typeof(externtrans) != 'undefined') {
  627. externtrans.display(0);
  628. }
  629. stop.enabled = true;
  630. window.windowModified = true;
  631. graph.setTimeIndicatorEnabled(true);
  632. });
  633. for(var i = 0; i < annotationButtons.length; i++) {
  634. if(channels.length > 0)
  635. {
  636. annotationButtons[i].annotation.connect(log.newAnnotation);
  637. annotationButtons[i].setTemperatureColumn(1);
  638. annotationButtons[i].setAnnotationColumn(channels.length + 1);
  639. annotationButtons[i].annotation.connect(function(note, tcol, ncol) {
  640. for(var i = tcol; i < ncol; i++) {
  641. log.newAnnotation(note, i, ncol);
  642. }
  643. });
  644. }
  645. }
  646. start.setFocus();
  647. stop.annotation.connect(log.newAnnotation);
  648. stop.clicked.connect(timer.stopTimer);
  649. stop.setTemperatureColumn(1);
  650. stop.setAnnotationColumn(channels.length + 1);
  651. QSettings.setValue("liveColumn", 1);
  652. var lc = 1;
  653. stop.clicked.connect(function() {
  654. stop.enabled = false;
  655. for(var i = 0; i < adapters.length; i++)
  656. {
  657. adapters[i].measurement.disconnect(log.newMeasurement);
  658. adapters[i].measurement.disconnect(graph.newMeasurement);
  659. }
  660. for(var i = 0; i < rateadapters.length; i++)
  661. {
  662. rateadapters[i].measurement.disconnect(graph.newMeasurement);
  663. }
  664. if(typeof(currentBatchInfo) == 'undefined') { } else {
  665. lc = Number(QSettings.value("liveColumn"));
  666. var duration = log.lastTime(lc);
  667. var durfield = findChildObject(currentBatchInfo, 'duration');
  668. durfield.text = duration;
  669. log.clearOutputColumns();
  670. for(var i = 0; i < channels.length; i++) {
  671. if(channelType[i] == "T") {
  672. log.addOutputTemperatureColumn(lc + i);
  673. }
  674. else {
  675. log.addOutputControlColumn(lc + i);
  676. }
  677. }
  678. log.addOutputAnnotationColumn(lc + channels.length);
  679. var filename = log.saveTemporary();
  680. currentBatchInfo.tempData = filename;
  681. currentBatchInfo.raise();
  682. currentBatchInfo.activateWindow();
  683. }
  684. if(translationChannel >= 0)
  685. {
  686. offsets[translationChannel].measurement.disconnect(currentDetector.newMeasurement);
  687. }
  688. start.enabled = true;
  689. window.windowModified = false;
  690. graph.setTimeIndicatorEnabled(false);
  691. });
  692. stop.annotation.connect(function(note, tcol, ncol) {
  693. for(var i = tcol; i < ncol; i++) {
  694. log.newAnnotation(note, i, ncol);
  695. }
  696. });
  697. var quitMenu = findChildObject(this, 'quit');
  698. quitMenu.triggered.connect(function() {
  699. window.close();
  700. Application.quit();
  701. });
  702. var v1 = findChildObject(this, 'ms');
  703. v1.triggered.connect(log.LOD_ms);
  704. var v2 = findChildObject(this, '1s');
  705. v2.triggered.connect(log.LOD_1s);
  706. var v3 = findChildObject(this, '5s');
  707. v3.triggered.connect(log.LOD_5s);
  708. var v4 = findChildObject(this, '10s');
  709. v4.triggered.connect(log.LOD_10s);
  710. var v5 = findChildObject(this, '15s');
  711. v5.triggered.connect(log.LOD_15s);
  712. var v6 = findChildObject(this, '30s');
  713. v6.triggered.connect(log.LOD_30s);
  714. var v7 = findChildObject(this, '1m');
  715. v7.triggered.connect(log.LOD_1m);
  716. var showC = findChildObject(this, 'showC');
  717. showC.triggered.connect(function() {
  718. for(var i = 0; i < temperatureDisplays.length; i++)
  719. {
  720. temperatureDisplays[i].setDisplayUnits(Units.Celsius);
  721. }
  722. log.setDisplayUnits(Units.Celsius);
  723. graph.showC();
  724. });
  725. var showF = findChildObject(this, 'showF');
  726. showF.triggered.connect(function() {
  727. for(var i = 0; i < temperatureDisplays.length; i++)
  728. {
  729. temperatureDisplays[i].setDisplayUnits(Units.Fahrenheit);
  730. }
  731. log.setDisplayUnits(Units.Fahrenheit);
  732. graph.showF();
  733. });
  734. var clear = findChildObject(this, 'clear');
  735. clear.triggered.connect(log.clear);
  736. clear.triggered.connect(graph.clear);
  737. clear.triggered.connect(function() {
  738. window.windowTitle = "Typica [*]";
  739. log.setHeaderData(0, "Time");
  740. QSettings.setValue("liveColumn", 1);
  741. window.postLoadColumnSetup(0);
  742. if(typeof(externtrans) != 'undefined') {
  743. externtrans.display(0);
  744. }
  745. });
  746. var openMenu = findChildObject(this, 'open');
  747. var compareMenu = findChildObject(this, 'compare');
  748. compareMenu.triggered.connect(function() {
  749. QSettings.setValue('cseries', lc+1);
  750. var history = createWindow("history");
  751. history.windowTitle = 'Typica - Roasting Log';
  752. });
  753. var printMenu = findChildObject(this, 'print');
  754. printMenu.triggered.connect(function() {
  755. var exportWindow = createWindow("print");
  756. exportWindow.windowTitle = "Typica - Print";
  757. exportWindow.log = log;
  758. });
  759. var svgExportMenu = findChildObject(this, 'svgexport');
  760. svgExportMenu.triggered.connect(function() {
  761. var exportWindow = createWindow("exportWindow");
  762. exportWindow.windowTitle = "Typica - Export XHTML+SVG";
  763. exportWindow.log = log;
  764. });
  765. openMenu.triggered.connect(function() {
  766. var filename = QFileDialog.getOpenFileName(window, 'Open Log…', QSettings.value('script/lastDir', '') + '/');
  767. if(filename != '') {
  768. var file = new QFile(filename);
  769. var input = new XMLInput(file, 1);
  770. targetseries = -1;
  771. input.newTemperatureColumn.connect(log.setHeaderData);
  772. input.newTemperatureColumn.connect(function(col, text) {
  773. if(text == window.targetcolumnname) {
  774. targetseries = col;
  775. }
  776. });
  777. input.newAnnotationColumn.connect(log.setHeaderData);
  778. input.measure.connect(graph.newMeasurement);
  779. input.measure.connect(log.newMeasurement);
  780. input.measure.connect(function(data, series) {
  781. if(series == targetseries) {
  782. targetDetector.newMeasurement(data);
  783. }
  784. });
  785. input.annotation.connect(log.newAnnotation);
  786. input.annotation.connect(function(note, tcol, ncol) {
  787. for(var i = tcol; i < ncol; i++) {
  788. log.newAnnotation(note, i, ncol);
  789. }
  790. });
  791. var lc;
  792. input.lastColumn.connect(function(c) {
  793. lc = c;
  794. QSettings.setValue("liveColumn", c + 1);
  795. window.postLoadColumnSetup(c);
  796. });
  797. input.input();
  798. window.windowTitle = 'Typica - [*]' + baseName(filename);
  799. QSettings.setValue("script/lastDir", dir(filename));
  800. log.newAnnotation("End", 1, lc);
  801. }
  802. });
  803. window.postLoadColumnSetup = function(c) {
  804. for(var i = 0; i < adapters.length; i++)
  805. {
  806. adapters[i].setColumn(c + i + 1);
  807. zeroemitters[i].setColumn(c + i + 1);
  808. log.setHeaderData(c + i + 1, columnNames[i]);
  809. }
  810. log.setHeaderData(c + columnNames.length + 1, "Note");
  811. stop.setTemperatureColumn(c + 1);
  812. stop.setAnnotationColumn(c + columnNames.length + 1);
  813. for(var i = 0; i < annotationButtons.length; i++)
  814. {
  815. annotationButtons[i].setTemperatureColumn(c + 1);
  816. annotationButtons[i].setAnnotationColumn(c + columnNames.length + 1);
  817. }
  818. log.clearCurrentColumnSet();
  819. for(var i = 0; i < channels.length; i++) {
  820. log.addToCurrentColumnSet(c + i + 1);
  821. }
  822. window.firstTempColumn = c + 1;
  823. window.annotationColumn = c + columnNames.length + 1;
  824. }
  825. var saveMenu = findChildObject(this, 'save');
  826. saveMenu.triggered.connect(function() {
  827. var filename = QFileDialog.getSaveFileName(window, "Save Log As…", QSettings.value("script/lastDir", "") + "/");
  828. if(filename != "") {
  829. var lc = Number(QSettings.value("liveColumn"));
  830. var file = new QFile(filename);
  831. log.clearOutputColumns();
  832. for(var i = 0; i < columnNames.length; i++)
  833. {
  834. if(channelType[i] == "T") {
  835. log.addOutputTemperatureColumn(lc + i);
  836. }
  837. else {
  838. log.addOutputControlColumn(lc + i);
  839. }
  840. }
  841. log.addOutputAnnotationColumn(lc + columnNames.length);
  842. log.saveXML(file);
  843. QSettings.setValue("script/lastDir", dir(filename));
  844. }
  845. });
  846. var exportMenu = findChildObject(this, 'export');
  847. exportMenu.triggered.connect(function() {
  848. var filename = QFileDialog.getSaveFileName(window, "Export CSV As…", QSettings.value("script/lastDir", "") + "/");
  849. if(filename != "") {
  850. var lc = Number(QSettings.value("liveColumn"));
  851. var file = new QFile(filename);
  852. log.clearOutputColumns();
  853. for(var i = 0; i < columnNames.length; i++)
  854. {
  855. log.addOutputTemperatureColumn(lc + i);
  856. }
  857. log.addOutputAnnotationColumn(lc + columnNames.length);
  858. log.saveCSV(file);
  859. QSettings.setValue("script/lastDir", dir(filename));
  860. }
  861. });
  862. var manual = findChildObject(this, 'manual');
  863. manual.triggered.connect(function() {
  864. var entry = new LogEditWindow();
  865. entry.show();
  866. });
  867. var newMenu = findChildObject(this, 'new');
  868. newMenu.triggered.connect(function() {
  869. var bwindow = createWindow("batchWindow");
  870. bwindow.windowTitle = "Typica - [*]New Batch";
  871. });
  872. window.postLoadColumnSetup(0);
  873. ]]>
  874. </program>
  875. </window>