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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953
  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. channelSkip = 0;
  723. for(var i = 0; i < channels.length; i++) {
  724. if(channelVisibility[i]) {
  725. if(channelType[i] == "T") {
  726. log.addOutputTemperatureColumn(lc + i - channelSkip);
  727. }
  728. else {
  729. log.addOutputControlColumn(lc + i - channelSkip);
  730. }
  731. } else {
  732. channelSkip++;
  733. }
  734. }
  735. log.addOutputAnnotationColumn(lc + channels.length - channelSkip);
  736. var filename = log.saveTemporary();
  737. currentBatchInfo.tempData = filename;
  738. currentBatchInfo.raise();
  739. currentBatchInfo.activateWindow();
  740. }
  741. if(translationChannel >= 0)
  742. {
  743. offsets[offsetForChannel(translationChannel)].measurement.disconnect(currentDetector.newMeasurement);
  744. }
  745. start.enabled = true;
  746. window.windowModified = false;
  747. graph.setTimeIndicatorEnabled(false);
  748. });
  749. stop.annotation.connect(function(note, tcol, ncol) {
  750. for(var i = tcol; i < ncol; i++) {
  751. log.newAnnotation(note, i, ncol);
  752. }
  753. });
  754. var quitMenu = findChildObject(this, 'quit');
  755. quitMenu.triggered.connect(function() {
  756. window.close();
  757. Application.quit();
  758. });
  759. var v1 = findChildObject(this, 'ms');
  760. v1.triggered.connect(log.LOD_ms);
  761. var v2 = findChildObject(this, '1s');
  762. v2.triggered.connect(log.LOD_1s);
  763. var v3 = findChildObject(this, '5s');
  764. v3.triggered.connect(log.LOD_5s);
  765. var v4 = findChildObject(this, '10s');
  766. v4.triggered.connect(log.LOD_10s);
  767. var v5 = findChildObject(this, '15s');
  768. v5.triggered.connect(log.LOD_15s);
  769. var v6 = findChildObject(this, '30s');
  770. v6.triggered.connect(log.LOD_30s);
  771. var v7 = findChildObject(this, '1m');
  772. v7.triggered.connect(log.LOD_1m);
  773. var showC = findChildObject(this, 'showC');
  774. showC.triggered.connect(function() {
  775. for(var i = 0; i < temperatureDisplays.length; i++)
  776. {
  777. temperatureDisplays[i].setDisplayUnits(Units.Celsius);
  778. }
  779. log.setDisplayUnits(Units.Celsius);
  780. graph.showC();
  781. });
  782. var showF = findChildObject(this, 'showF');
  783. showF.triggered.connect(function() {
  784. for(var i = 0; i < temperatureDisplays.length; i++)
  785. {
  786. temperatureDisplays[i].setDisplayUnits(Units.Fahrenheit);
  787. }
  788. log.setDisplayUnits(Units.Fahrenheit);
  789. graph.showF();
  790. });
  791. var clear = findChildObject(this, 'clear');
  792. clear.triggered.connect(log.clear);
  793. clear.triggered.connect(graph.clear);
  794. clear.triggered.connect(function() {
  795. window.windowTitle = "Typica [*]";
  796. log.setHeaderData(0, "Time");
  797. QSettings.setValue("liveColumn", 1);
  798. window.postLoadColumnSetup(0);
  799. if(typeof(externtrans) != 'undefined') {
  800. externtrans.display(0);
  801. }
  802. });
  803. var openMenu = findChildObject(this, 'open');
  804. var compareMenu = findChildObject(this, 'compare');
  805. compareMenu.triggered.connect(function() {
  806. QSettings.setValue('cseries', lc+1);
  807. var history = createWindow("history");
  808. history.windowTitle = 'Typica - Roasting Log';
  809. });
  810. var printMenu = findChildObject(this, 'print');
  811. printMenu.triggered.connect(function() {
  812. var exportWindow = createWindow("print");
  813. exportWindow.windowTitle = "Typica - Print";
  814. exportWindow.log = log;
  815. });
  816. var svgExportMenu = findChildObject(this, 'svgexport');
  817. svgExportMenu.triggered.connect(function() {
  818. var exportWindow = createWindow("exportWindow");
  819. exportWindow.windowTitle = "Typica - Export XHTML+SVG";
  820. exportWindow.log = log;
  821. });
  822. openMenu.triggered.connect(function() {
  823. var filename = QFileDialog.getOpenFileName(window, 'Open Log…', QSettings.value('script/lastDir', '') + '/');
  824. if(filename != '') {
  825. var file = new QFile(filename);
  826. var input = new XMLInput(file, 1);
  827. targetseries = -1;
  828. input.newTemperatureColumn.connect(log.setHeaderData);
  829. input.newTemperatureColumn.connect(function(col, text) {
  830. if(text == window.targetcolumnname) {
  831. targetseries = col;
  832. }
  833. });
  834. input.newAnnotationColumn.connect(log.setHeaderData);
  835. input.measure.connect(graph.newMeasurement);
  836. input.measure.connect(log.newMeasurement);
  837. input.measure.connect(function(data, series) {
  838. if(series == targetseries) {
  839. targetDetector.newMeasurement(data);
  840. }
  841. });
  842. input.annotation.connect(log.newAnnotation);
  843. input.annotation.connect(function(note, tcol, ncol) {
  844. for(var i = tcol; i < ncol; i++) {
  845. log.newAnnotation(note, i, ncol);
  846. }
  847. });
  848. var lc;
  849. input.lastColumn.connect(function(c) {
  850. lc = c;
  851. QSettings.setValue("liveColumn", c + 1);
  852. window.postLoadColumnSetup(c);
  853. });
  854. input.input();
  855. window.windowTitle = 'Typica - [*]' + baseName(filename);
  856. QSettings.setValue("script/lastDir", dir(filename));
  857. log.newAnnotation("End", 1, lc);
  858. }
  859. });
  860. var columnName = function(c) {
  861. var visibleColumns = 0;
  862. for(var i = 0; i < channels.length; i++) {
  863. if(channelVisibility[i]) {
  864. visibleColumns++;
  865. }
  866. if(c == visibleColumns - 1) {
  867. return columnNames[i];
  868. }
  869. }
  870. return "";
  871. };
  872. window.postLoadColumnSetup = function(c) {
  873. for(var i = 0; i < adapters.length; i++)
  874. {
  875. adapters[i].setColumn(c + i + 1);
  876. zeroemitters[i].setColumn(c + i + 1);
  877. log.setHeaderData(c + i + 1, columnName(i));
  878. }
  879. log.setHeaderData(c + columnNames.length + 1 - channelSkip, "Note");
  880. stop.setTemperatureColumn(c + 1);
  881. stop.setAnnotationColumn(c + columnNames.length + 1 - channelSkip);
  882. for(var i = 0; i < annotationButtons.length; i++)
  883. {
  884. annotationButtons[i].setTemperatureColumn(c + 1);
  885. annotationButtons[i].setAnnotationColumn(c + columnNames.length + 1 - channelSkip);
  886. }
  887. log.clearCurrentColumnSet();
  888. for(var i = 0; i < channels.length - channelSkip; i++) {
  889. log.addToCurrentColumnSet(c + i + 1);
  890. }
  891. window.firstTempColumn = c + 1;
  892. window.annotationColumn = c + columnNames.length - channelSkip + 1;
  893. }
  894. var saveMenu = findChildObject(this, 'save');
  895. saveMenu.triggered.connect(function() {
  896. var filename = QFileDialog.getSaveFileName(window, "Save Log As…", QSettings.value("script/lastDir", "") + "/");
  897. if(filename != "") {
  898. var lc = Number(QSettings.value("liveColumn"));
  899. var file = new QFile(filename);
  900. log.clearOutputColumns();
  901. channelSkip = 0;
  902. for(var i = 0; i < columnNames.length - channelSkip; i++)
  903. {
  904. if(channelVisibility[i]) {
  905. if(channelType[i] == "T") {
  906. log.addOutputTemperatureColumn(lc + i - channelSkip);
  907. }
  908. else {
  909. log.addOutputControlColumn(lc + i - channelSkip);
  910. }
  911. } else {
  912. channelSkip++;
  913. }
  914. }
  915. log.addOutputAnnotationColumn(lc + columnNames.length - channelSkip);
  916. log.saveXML(file);
  917. QSettings.setValue("script/lastDir", dir(filename));
  918. }
  919. });
  920. var exportMenu = findChildObject(this, 'export');
  921. exportMenu.triggered.connect(function() {
  922. var filename = QFileDialog.getSaveFileName(window, "Export CSV As…", QSettings.value("script/lastDir", "") + "/");
  923. if(filename != "") {
  924. var lc = Number(QSettings.value("liveColumn"));
  925. var file = new QFile(filename);
  926. log.clearOutputColumns();
  927. for(var i = 0; i < columnNames.length - channelSkip; i++)
  928. {
  929. log.addOutputTemperatureColumn(lc + i);
  930. }
  931. log.addOutputAnnotationColumn(lc + columnNames.length - channelSkip);
  932. log.saveCSV(file);
  933. QSettings.setValue("script/lastDir", dir(filename));
  934. }
  935. });
  936. var manual = findChildObject(this, 'manual');
  937. manual.triggered.connect(function() {
  938. var entry = new LogEditWindow();
  939. entry.show();
  940. });
  941. var newMenu = findChildObject(this, 'new');
  942. newMenu.triggered.connect(function() {
  943. var bwindow = createWindow("batchWindow");
  944. bwindow.windowTitle = "Typica - [*]New Batch";
  945. });
  946. var newSampleMenu = findChildObject(this, 'newsample');
  947. newSampleMenu.triggered.connect(function() {
  948. var bwindow = createWindow("sampleRoastingBatch");
  949. });
  950. window.postLoadColumnSetup(0);
  951. ]]>
  952. </program>
  953. </window>