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

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