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

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