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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938
  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. var offsetForChannel = function(c) {
  637. var retval = -1;
  638. for(var i = 0; i <= c; i++) {
  639. if(channelVisibility[i]) {
  640. retval++;
  641. }
  642. }
  643. return retval;
  644. };
  645. start.clicked.connect(function() {
  646. start.enabled = false;
  647. hasTranslated = false;
  648. var epoch = new QTime();
  649. epoch = epoch.currentTime();
  650. for(var i = 0; i < offsets.length; i++)
  651. {
  652. offsets[i].setZeroTime(epoch);
  653. zeroemitters[i].emitZero();
  654. adapters[i].measurement.connect(log.newMeasurement);
  655. adapters[i].measurement.connect(graph.newMeasurement);
  656. }
  657. for(var i = 0; i < rateadapters.length; i++)
  658. {
  659. rateoffsets[i].setZeroTime(epoch);
  660. ratezeros[i].emitZero();
  661. rateadapters[i].measurement.connect(graph.newMeasurement);
  662. }
  663. timer.startTimer();
  664. if(typeof(currentBatchInfo) == 'undefined') { } else {
  665. query = new QSqlQuery();
  666. query.exec("SELECT now()::timestamp without time zone");
  667. query.next();
  668. var result = query.value(0);
  669. query = query.invalidate();
  670. var timefield = findChildObject(currentBatchInfo, 'time');
  671. timefield.text = result.replace('T', ' ');
  672. }
  673. if(translationChannel >= 0)
  674. {
  675. offsets[offsetForChannel(translationChannel)].measurement.connect(currentDetector.newMeasurement);
  676. }
  677. if(typeof(externtrans) != 'undefined') {
  678. externtrans.display(0);
  679. }
  680. stop.enabled = true;
  681. window.windowModified = true;
  682. graph.setTimeIndicatorEnabled(true);
  683. });
  684. for(var i = 0; i < annotationButtons.length; i++) {
  685. if(channels.length > 0)
  686. {
  687. annotationButtons[i].annotation.connect(log.newAnnotation);
  688. annotationButtons[i].setTemperatureColumn(1);
  689. annotationButtons[i].setAnnotationColumn(channels.length - channelSkip + 1);
  690. annotationButtons[i].annotation.connect(function(note, tcol, ncol) {
  691. for(var i = tcol; i < ncol; i++) {
  692. log.newAnnotation(note, i, ncol);
  693. }
  694. });
  695. }
  696. }
  697. start.setFocus();
  698. stop.annotation.connect(log.newAnnotation);
  699. stop.clicked.connect(timer.stopTimer);
  700. stop.setTemperatureColumn(1);
  701. stop.setAnnotationColumn(channels.length - channelSkip + 1);
  702. QSettings.setValue("liveColumn", 1);
  703. var lc = 1;
  704. stop.clicked.connect(function() {
  705. stop.enabled = false;
  706. for(var i = 0; i < adapters.length; i++)
  707. {
  708. adapters[i].measurement.disconnect(log.newMeasurement);
  709. adapters[i].measurement.disconnect(graph.newMeasurement);
  710. }
  711. for(var i = 0; i < rateadapters.length; i++)
  712. {
  713. rateadapters[i].measurement.disconnect(graph.newMeasurement);
  714. }
  715. if(typeof(currentBatchInfo) == 'undefined') { } else {
  716. lc = Number(QSettings.value("liveColumn"));
  717. var duration = log.lastTime(lc);
  718. var durfield = findChildObject(currentBatchInfo, 'duration');
  719. durfield.text = duration;
  720. log.clearOutputColumns();
  721. for(var i = 0; i < channels.length; i++) {
  722. if(channelType[i] == "T") {
  723. log.addOutputTemperatureColumn(lc + i);
  724. }
  725. else {
  726. log.addOutputControlColumn(lc + i);
  727. }
  728. }
  729. log.addOutputAnnotationColumn(lc + channels.length);
  730. var filename = log.saveTemporary();
  731. currentBatchInfo.tempData = filename;
  732. currentBatchInfo.raise();
  733. currentBatchInfo.activateWindow();
  734. }
  735. if(translationChannel >= 0)
  736. {
  737. offsets[offsetForChannel(translationChannel)].measurement.disconnect(currentDetector.newMeasurement);
  738. }
  739. start.enabled = true;
  740. window.windowModified = false;
  741. graph.setTimeIndicatorEnabled(false);
  742. });
  743. stop.annotation.connect(function(note, tcol, ncol) {
  744. for(var i = tcol; i < ncol; i++) {
  745. log.newAnnotation(note, i, ncol);
  746. }
  747. });
  748. var quitMenu = findChildObject(this, 'quit');
  749. quitMenu.triggered.connect(function() {
  750. window.close();
  751. Application.quit();
  752. });
  753. var v1 = findChildObject(this, 'ms');
  754. v1.triggered.connect(log.LOD_ms);
  755. var v2 = findChildObject(this, '1s');
  756. v2.triggered.connect(log.LOD_1s);
  757. var v3 = findChildObject(this, '5s');
  758. v3.triggered.connect(log.LOD_5s);
  759. var v4 = findChildObject(this, '10s');
  760. v4.triggered.connect(log.LOD_10s);
  761. var v5 = findChildObject(this, '15s');
  762. v5.triggered.connect(log.LOD_15s);
  763. var v6 = findChildObject(this, '30s');
  764. v6.triggered.connect(log.LOD_30s);
  765. var v7 = findChildObject(this, '1m');
  766. v7.triggered.connect(log.LOD_1m);
  767. var showC = findChildObject(this, 'showC');
  768. showC.triggered.connect(function() {
  769. for(var i = 0; i < temperatureDisplays.length; i++)
  770. {
  771. temperatureDisplays[i].setDisplayUnits(Units.Celsius);
  772. }
  773. log.setDisplayUnits(Units.Celsius);
  774. graph.showC();
  775. });
  776. var showF = findChildObject(this, 'showF');
  777. showF.triggered.connect(function() {
  778. for(var i = 0; i < temperatureDisplays.length; i++)
  779. {
  780. temperatureDisplays[i].setDisplayUnits(Units.Fahrenheit);
  781. }
  782. log.setDisplayUnits(Units.Fahrenheit);
  783. graph.showF();
  784. });
  785. var clear = findChildObject(this, 'clear');
  786. clear.triggered.connect(log.clear);
  787. clear.triggered.connect(graph.clear);
  788. clear.triggered.connect(function() {
  789. window.windowTitle = "Typica [*]";
  790. log.setHeaderData(0, "Time");
  791. QSettings.setValue("liveColumn", 1);
  792. window.postLoadColumnSetup(0);
  793. if(typeof(externtrans) != 'undefined') {
  794. externtrans.display(0);
  795. }
  796. });
  797. var openMenu = findChildObject(this, 'open');
  798. var compareMenu = findChildObject(this, 'compare');
  799. compareMenu.triggered.connect(function() {
  800. QSettings.setValue('cseries', lc+1);
  801. var history = createWindow("history");
  802. history.windowTitle = 'Typica - Roasting Log';
  803. });
  804. var printMenu = findChildObject(this, 'print');
  805. printMenu.triggered.connect(function() {
  806. var exportWindow = createWindow("print");
  807. exportWindow.windowTitle = "Typica - Print";
  808. exportWindow.log = log;
  809. });
  810. var svgExportMenu = findChildObject(this, 'svgexport');
  811. svgExportMenu.triggered.connect(function() {
  812. var exportWindow = createWindow("exportWindow");
  813. exportWindow.windowTitle = "Typica - Export XHTML+SVG";
  814. exportWindow.log = log;
  815. });
  816. openMenu.triggered.connect(function() {
  817. var filename = QFileDialog.getOpenFileName(window, 'Open Log…', QSettings.value('script/lastDir', '') + '/');
  818. if(filename != '') {
  819. var file = new QFile(filename);
  820. var input = new XMLInput(file, 1);
  821. targetseries = -1;
  822. input.newTemperatureColumn.connect(log.setHeaderData);
  823. input.newTemperatureColumn.connect(function(col, text) {
  824. if(text == window.targetcolumnname) {
  825. targetseries = col;
  826. }
  827. });
  828. input.newAnnotationColumn.connect(log.setHeaderData);
  829. input.measure.connect(graph.newMeasurement);
  830. input.measure.connect(log.newMeasurement);
  831. input.measure.connect(function(data, series) {
  832. if(series == targetseries) {
  833. targetDetector.newMeasurement(data);
  834. }
  835. });
  836. input.annotation.connect(log.newAnnotation);
  837. input.annotation.connect(function(note, tcol, ncol) {
  838. for(var i = tcol; i < ncol; i++) {
  839. log.newAnnotation(note, i, ncol);
  840. }
  841. });
  842. var lc;
  843. input.lastColumn.connect(function(c) {
  844. lc = c;
  845. QSettings.setValue("liveColumn", c + 1);
  846. window.postLoadColumnSetup(c);
  847. });
  848. input.input();
  849. window.windowTitle = 'Typica - [*]' + baseName(filename);
  850. QSettings.setValue("script/lastDir", dir(filename));
  851. log.newAnnotation("End", 1, lc);
  852. }
  853. });
  854. var columnName = function(c) {
  855. var visibleColumns = 0;
  856. for(var i = 0; i < channels.length; i++) {
  857. if(channelVisibility[i]) {
  858. visibleColumns++;
  859. }
  860. if(c == visibleColumns - 1) {
  861. return columnNames[i];
  862. }
  863. }
  864. return "";
  865. };
  866. window.postLoadColumnSetup = function(c) {
  867. for(var i = 0; i < adapters.length; i++)
  868. {
  869. adapters[i].setColumn(c + i + 1);
  870. zeroemitters[i].setColumn(c + i + 1);
  871. log.setHeaderData(c + i + 1, columnName(i));
  872. }
  873. log.setHeaderData(c + columnNames.length + 1 - channelSkip, "Note");
  874. stop.setTemperatureColumn(c + 1);
  875. stop.setAnnotationColumn(c + columnNames.length + 1 - channelSkip);
  876. for(var i = 0; i < annotationButtons.length; i++)
  877. {
  878. annotationButtons[i].setTemperatureColumn(c + 1);
  879. annotationButtons[i].setAnnotationColumn(c + columnNames.length + 1 - channelSkip);
  880. }
  881. log.clearCurrentColumnSet();
  882. for(var i = 0; i < channels.length - channelSkip; i++) {
  883. log.addToCurrentColumnSet(c + i + 1);
  884. }
  885. window.firstTempColumn = c + 1;
  886. window.annotationColumn = c + columnNames.length - channelSkip + 1;
  887. }
  888. var saveMenu = findChildObject(this, 'save');
  889. saveMenu.triggered.connect(function() {
  890. var filename = QFileDialog.getSaveFileName(window, "Save Log As…", QSettings.value("script/lastDir", "") + "/");
  891. if(filename != "") {
  892. var lc = Number(QSettings.value("liveColumn"));
  893. var file = new QFile(filename);
  894. log.clearOutputColumns();
  895. for(var i = 0; i < columnNames.length - channelSkip; i++)
  896. {
  897. if(channelType[i] == "T") {
  898. log.addOutputTemperatureColumn(lc + i);
  899. }
  900. else {
  901. log.addOutputControlColumn(lc + i);
  902. }
  903. }
  904. log.addOutputAnnotationColumn(lc + columnNames.length - channelSkip);
  905. log.saveXML(file);
  906. QSettings.setValue("script/lastDir", dir(filename));
  907. }
  908. });
  909. var exportMenu = findChildObject(this, 'export');
  910. exportMenu.triggered.connect(function() {
  911. var filename = QFileDialog.getSaveFileName(window, "Export CSV As…", QSettings.value("script/lastDir", "") + "/");
  912. if(filename != "") {
  913. var lc = Number(QSettings.value("liveColumn"));
  914. var file = new QFile(filename);
  915. log.clearOutputColumns();
  916. for(var i = 0; i < columnNames.length - channelSkip; i++)
  917. {
  918. log.addOutputTemperatureColumn(lc + i);
  919. }
  920. log.addOutputAnnotationColumn(lc + columnNames.length - channelSkip);
  921. log.saveCSV(file);
  922. QSettings.setValue("script/lastDir", dir(filename));
  923. }
  924. });
  925. var manual = findChildObject(this, 'manual');
  926. manual.triggered.connect(function() {
  927. var entry = new LogEditWindow();
  928. entry.show();
  929. });
  930. var newMenu = findChildObject(this, 'new');
  931. newMenu.triggered.connect(function() {
  932. var bwindow = createWindow("batchWindow");
  933. bwindow.windowTitle = "Typica - [*]New Batch";
  934. });
  935. window.postLoadColumnSetup(0);
  936. ]]>
  937. </program>
  938. </window>