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 35KB

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