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

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