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

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