Typica is a free program for professional coffee roasters. https://typica.us
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

productionroaster.xml 39KB

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