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

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