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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349
  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. </menu>
  45. <menu name="Graph">
  46. <item id="reshift" shortcut="Ctrl+T">Set Translation</item>
  47. <item id="unshift" shortcut="Ctrl+R">Reset Translation</item>
  48. </menu>
  49. <program>
  50. <![CDATA[
  51. var window = this;
  52. var targetOffset = 0;
  53. var gtrans = 0;
  54. var oldtrans = 0;
  55. var translationdelay = new Timer;
  56. translationdelay.interval = 0;
  57. translationdelay.singleShot = true;
  58. var targetDetector = new ThresholdDetector;
  59. window.targetDetector = targetDetector;
  60. window.targetcolumnname = "";
  61. var currentDetector = new ThresholdDetector;
  62. var translationChannel = -1;
  63. var resetTranslation = findChildObject(this, 'unshift');
  64. var setTranslation = findChildObject(this, 'reshift');
  65. resetTranslation.enabled = false;
  66. setTranslation.enabled = false;
  67. targetDetector.timeForValue.connect(function(value) {
  68. targetOffset = value;
  69. });
  70. var epoch = new QTime;
  71. epoch = epoch.currentTime;
  72. var translationCurrentColumn = -1;
  73. var configModel = new DeviceTreeModel;
  74. var rootIndex = configModel.index(roasterlist.currentIndex, 0);
  75. var roasterIndex = roasterlist.currentIndex;
  76. var channels = new Array();
  77. var annotationButtons = new Array();
  78. var rangetimers = new Array();
  79. var nidevices = new Array();
  80. var dataqsdkdevices = new Array();
  81. var jsdevices = new Array();
  82. var pdevices = new Array();
  83. var temperatureDisplays = new Array();
  84. var columnNames = new Array();
  85. var modbusdevices = new Array();
  86. var rateCalculators = new Array();
  87. var rateadapters = new Array();
  88. var rateoffsets = new Array();
  89. var ratezeros = new Array();
  90. var channelType = new Array();
  91. window.scales = new Array();
  92. var channelVisibility = new Array();
  93. var indicatorPanel = findChildObject(this, 'indicators');
  94. var annotationPanel = findChildObject(this, 'controlpanel');
  95. var log = findChildObject(this, 'log');
  96. var tabControls = new Array();
  97. var start = findChildObject(this, 'startbutton');
  98. var stop = findChildObject(this, 'stopbutton');
  99. stop.enabled = false;
  100. tabControls.push(start);
  101. tabControls.push(stop);
  102. var nsparam = findChildObject(this, 'setSample');
  103. nsparam.enabled = false;
  104. var graph = findChildObject(this, 'graph');
  105. var hasTranslated = false;
  106. var externtrans = undefined;
  107. window.translateLoadedSeries = function(translation) {
  108. var lc = Number(QSettings.value("liveColumn"));
  109. for(var i = 1; i < lc - 1; i++)
  110. {
  111. graph.setSeriesTranslation(i, translation);
  112. }
  113. };
  114. window.translateCurrentSeries = function(translation) {
  115. var lc = Number(QSettings.value("liveColumn"));
  116. for(var i = 0; i < columnNames.length; i++)
  117. {
  118. graph.setSeriesTranslation(lc + i, translation);
  119. }
  120. };
  121. var selectedRoasterName = configModel.data(rootIndex, 0);
  122. var machineReference = configModel.referenceElement(configModel.data(rootIndex, 32));
  123. var selectedRoasterID = machineReference.databaseid;
  124. var checkCapacity = machineReference.checkcapacity;
  125. var maxCapacity = machineReference.capacity;
  126. var capacityUnit = machineReference.capacityunit;
  127. var poundsCapacity;
  128. var convertToPounds = function(w, u) {
  129. switch(u) {
  130. case "g":
  131. return w * 0.0022;
  132. case "oz":
  133. return w * 0.0625;
  134. case "Kg":
  135. return w * 2.2;
  136. }
  137. return w;
  138. };
  139. if(checkCapacity == "true") {
  140. poundsCapacity = convertToPounds(maxCapacity, capacityUnit);
  141. }
  142. if(configModel.hasChildren(rootIndex)) {
  143. for(var i = 0; i < configModel.rowCount(rootIndex); i++) {
  144. var driverIndex = configModel.index(i, 0, rootIndex);
  145. var driverReference = configModel.referenceElement(configModel.data(driverIndex, 32));
  146. if(driverReference.driver == "nidaqmxbase" || driverReference.driver == "nidaqmx") {
  147. if(configModel.hasChildren(driverIndex)) {
  148. for(var j = 0; j < configModel.rowCount(driverIndex); j++) {
  149. var deviceIndex = configModel.index(j, 0, driverIndex);
  150. var deviceReference = configModel.referenceElement(configModel.data(deviceIndex, 32));
  151. if(deviceReference.driver == "nidaqmxbase9211series" || deviceReference.driver == "nidaqmx9211series") {
  152. var device = new DAQ(deviceReference.deviceID, driverReference.driver);
  153. nidevices.push(device);
  154. var DAQChannels = 0;
  155. if(configModel.hasChildren(deviceIndex)) {
  156. for(var k = 0; k < configModel.rowCount(deviceIndex); k++) {
  157. var channelIndex = configModel.index(k, 0, deviceIndex);
  158. var channelReference = configModel.referenceElement(configModel.data(channelIndex, 32));
  159. if(channelReference.driver == "ni9211seriestc") {
  160. var channel;
  161. if(channelReference.type == "J") {
  162. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeJ);
  163. }
  164. else if(channelReference.type == "K") {
  165. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeK);
  166. }
  167. else if(channelReference.type == "T") {
  168. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeT);
  169. }
  170. else if(channelReference.type == "B") {
  171. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeB);
  172. }
  173. else if(channelReference.type == "E") {
  174. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeE);
  175. }
  176. else if(channelReference.type == "N") {
  177. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeN);
  178. }
  179. else if(channelReference.type == "R") {
  180. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeR);
  181. }
  182. else if(channelReference.type == "S") {
  183. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeS);
  184. }
  185. channels.push(channel);
  186. channelType.push("T");
  187. columnNames.push(channelReference.columnname);
  188. DAQChannels++;
  189. if(channelReference.hidden == "true") {
  190. channelVisibility.push(false);
  191. } else {
  192. channelVisibility.push(true);
  193. var indicator = new TemperatureDisplay;
  194. temperatureDisplays.push(indicator);
  195. var decorator = new WidgetDecorator(indicator, configModel.data(channelIndex, 0), 2);
  196. channel.newData.connect(indicator.setValue);
  197. indicatorPanel.addWidget(decorator);
  198. }
  199. }
  200. }
  201. switch(DAQChannels) {
  202. case 1:
  203. device.setClockRate(4);
  204. break;
  205. case 2:
  206. device.setClockRate(2);
  207. break;
  208. case 3:
  209. device.setClockRate(1.5);
  210. break;
  211. case 4:
  212. device.setClockRate(1);
  213. break;
  214. }
  215. device.start();
  216. }
  217. }
  218. else if(deviceReference.driver == "nidaqmxtc01")
  219. {
  220. var device = new DAQ(deviceReference.deviceID, "nidaqmx");
  221. var channel;
  222. if(deviceReference.type == "J")
  223. {
  224. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeJ);
  225. }
  226. else if(deviceReference.type == "K")
  227. {
  228. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeK);
  229. }
  230. else if(deviceReference.type == "T")
  231. {
  232. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeT);
  233. }
  234. else if(deviceReference.type == "B")
  235. {
  236. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeB);
  237. }
  238. else if(deviceReference.type == "E")
  239. {
  240. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeE);
  241. }
  242. else if(deviceReference.type == "N")
  243. {
  244. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeN);
  245. }
  246. else if(deviceReference.type == "R")
  247. {
  248. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeR);
  249. }
  250. else if(deviceReference.type == "S")
  251. {
  252. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeS);
  253. }
  254. channels.push(channel);
  255. channelType.push("T");
  256. columnNames.push(deviceReference.columnname);
  257. if(deviceReference.hidden == "true") {
  258. channelVisibility.push(false);
  259. } else {
  260. channelVisibility.push(true);
  261. var indicator = new TemperatureDisplay;
  262. temperatureDisplays.push(indicator);
  263. var decorator = new WidgetDecorator(indicator, configModel.data(deviceIndex, 0), 2);
  264. channel.newData.connect(indicator.setValue);
  265. indicatorPanel.addWidget(decorator);
  266. }
  267. device.start();
  268. nidevices.push(device);
  269. }
  270. }
  271. }
  272. }
  273. else if(driverReference.driver == "dataqsdk") {
  274. var device;
  275. if(driverReference.autoSelect == "true") {
  276. device = new DataqSdkDevice(driverReference.deviceNumber);
  277. }
  278. else {
  279. device = new DataqSdkDevice(driverReference.port);
  280. }
  281. var sampleRate = 6;
  282. if(configModel.hasChildren(driverIndex)) {
  283. for(var j = 0; j < configModel.rowCount(driverIndex); j++) {
  284. var channelIndex = configModel.index(j, 0, driverIndex);
  285. var channelReference = configModel.referenceElement(configModel.data(channelIndex, 32));
  286. var indicator = new TemperatureDisplay;
  287. var unit;
  288. if(channelReference.type == "Temperature") {
  289. unit = Units.Fahrenheit;
  290. channelType.push("T");
  291. temperatureDisplays.push(indicator);
  292. }
  293. else {
  294. unit = Units.Unitless;
  295. indicator.setDisplayUnits(Units.Unitless);
  296. channelType.push("C");
  297. indicator.digitCount = 6;
  298. }
  299. var channel = device.newChannel(unit);
  300. var calibrator = new LinearCalibrator;
  301. calibrator.measuredLower = channelReference.calibrationMeasuredLower;
  302. calibrator.measuredUpper = channelReference.calibrationMeasuredUpper;
  303. calibrator.mappedLower = channelReference.calibrationMappedLower;
  304. calibrator.mappedUpper = channelReference.calibrationMappedUpper;
  305. calibrator.sensitivity = channelReference.calibrationSensitivity;
  306. if(channelReference.calibrationClosedInterval == 'true') {
  307. calibrator.closedRange = true;
  308. }
  309. // device.setSmoothingEnabled(j) = channelReference.smoothing;
  310. channel.newData.connect(calibrator.newMeasurement)
  311. channels.push(calibrator);
  312. columnNames.push(channelReference.column);
  313. if(channelReference.hidden == "true") {
  314. channelVisibility.push(false);
  315. } else {
  316. channelVisibility.push(true);
  317. var decorator = new WidgetDecorator(indicator, configModel.data(channelIndex, 0), 2);
  318. calibrator.newData.connect(indicator.setValue);
  319. indicatorPanel.addWidget(decorator);
  320. }
  321. }
  322. sampleRate /= configModel.rowCount(driverIndex);
  323. }
  324. device.setClockRate(sampleRate);
  325. device.start();
  326. dataqsdkdevices.push(device);
  327. }
  328. else if(driverReference.driver == "modbusrtu")
  329. {
  330. var device = new ModbusRTUDevice(configModel, driverIndex);
  331. modbusdevices.push(device);
  332. var pvchannel = device.pVChannel();
  333. channels.push(pvchannel);
  334. channelType.push("T");
  335. columnNames.push(driverReference.pvcolname);
  336. if(driverReference.pvhidden == "true") {
  337. channelVisibility.push(false);
  338. } else {
  339. channelVisibility.push(true);
  340. var indicator = new TemperatureDisplay;
  341. temperatureDisplays.push(indicator);
  342. var decorator = new WidgetDecorator(indicator, configModel.data(driverIndex, 0) + " PV", 2);
  343. pvchannel.newData.connect(indicator.setValue);
  344. indicatorPanel.addWidget(decorator);
  345. }
  346. if(driverReference.sVEnabled == "true")
  347. {
  348. var svchannel = device.sVChannel();
  349. channels.push(svchannel);
  350. channelType.push("C");
  351. columnNames.push(driverReference.svcolname);
  352. if(driverReference.svhidden == "true") {
  353. channelVisibility.push(false);
  354. } else {
  355. channelVisibility.push(true);
  356. var indicator = new TemperatureDisplay;
  357. temperatureDisplays.push(indicator);
  358. var decorator = new WidgetDecorator(indicator, configModel.data(driverIndex, 0) + " SV", 2);
  359. svchannel.newData.connect(indicator.setValue);
  360. indicatorPanel.addWidget(decorator);
  361. }
  362. }
  363. if(driverReference.sVWritable == "true")
  364. {
  365. var outputControl = new AnnotationSpinBox;
  366. device.SVLowerChanged.connect(function(min) {
  367. outputControl.minimum = min;
  368. });
  369. outputControl.minimum = device.SVLower();
  370. device.SVUpperChanged.connect(function(max) {
  371. outputControl.maximum = max;
  372. });
  373. outputControl.maximum = device.SVUpper();
  374. device.SVDecimalChanged.connect(function(prec) {
  375. outputControl.decimals = prec;
  376. });
  377. outputControl.decimals = device.decimals();
  378. outputControl.editingFinished.connect(function() {
  379. device.outputSV(outputControl.value);
  380. });
  381. var layout = new QBoxLayout;
  382. var label = new QLabel("Change SV");
  383. layout.addWidget(label, 0, 2);
  384. layout.addWidget(outputControl, 0, 1);
  385. annotationPanel.addLayout(layout);
  386. tabControls.push(outputControl);
  387. }
  388. }
  389. else if(driverReference.driver == "modbusngport")
  390. {
  391. var device = new ModbusNG(configModel, driverIndex);
  392. modbusdevices.push(device);
  393. for(var j = 0; j < device.channelCount(); j++) {
  394. channels.push(device.getChannel(j));
  395. columnNames.push(device.channelColumnName(j));
  396. channelType.push(device.channelType(j));
  397. if(device.isChannelHidden(j)) {
  398. channelVisibility.push(false);
  399. } else {
  400. channelVisibility.push(true);
  401. var indicator = new TemperatureDisplay;
  402. if(device.channelType(j) == "C") {
  403. indicator.setDisplayUnits(Units.Unitless);
  404. indicator.digitCount = 6;
  405. }
  406. temperatureDisplays.push(indicator);
  407. var decorator = new WidgetDecorator(indicator, device.channelIndicatorText(j), 2);
  408. device.getChannel(j).newData.connect(indicator.setValue);
  409. indicatorPanel.addWidget(decorator);
  410. }
  411. }
  412. }
  413. else if(driverReference.driver == "unsupporteddevice")
  414. {
  415. var device = createDevice(driverIndex);
  416. for(var j = 0; j < device.channelCount(); j++) {
  417. channels.push(device.getChannel(j));
  418. columnNames.push(device.channelColumnName(j));
  419. var unit = device.expectedChannelUnit(j);
  420. if(unit == Units.Fahrenheit) {
  421. channelType.push("T");
  422. } else {
  423. channelType.push("C");
  424. }
  425. if(device.isChannelHidden(j)) {
  426. channelVisibility.push(false);
  427. } else {
  428. channelVisibility.push(true);
  429. var indicator = new TemperatureDisplay;
  430. if(unit == Units.Unitless) {
  431. indicator.setDisplayUnits(Units.Unitless);
  432. indicator.digitCount = 6;
  433. }
  434. temperatureDisplays.push(indicator);
  435. var decorator = new WidgetDecorator(indicator, device.channelIndicatorText(j), 2);
  436. device.getChannel(j).newData.connect(indicator.setValue);
  437. indicatorPanel.addWidget(decorator);
  438. }
  439. }
  440. device.start();
  441. jsdevices.push(device);
  442. }
  443. else if(driverReference.driver == "phidgets1048")
  444. {
  445. var device = new PhidgetsTemperatureSensor(driverIndex);
  446. for(var j = 0; j < device.channelCount(); j++) {
  447. channels.push(device.getChannel(j));
  448. columnNames.push(device.channelColumnName(j));
  449. channelType.push("T");
  450. if(device.isChannelHidden(j)) {
  451. channelVisibility.push(false);
  452. } else {
  453. channelVisibility.push(true);
  454. var indicator = new TemperatureDisplay;
  455. temperatureDisplays.push(indicator);
  456. var decorator = new WidgetDecorator(indicator, device.channelIndicatorText(j), 2);
  457. device.getChannel(j).newData.connect(indicator.setValue);
  458. indicatorPanel.addWidget(decorator);
  459. }
  460. }
  461. device.start();
  462. pdevices.push(device);
  463. }
  464. else if(driverReference.driver == "phidget22")
  465. {
  466. var device = new Phidget22(driverIndex);
  467. for(var j = 0; j < device.channelCount(); j++) {
  468. channels.push(device.getChannel(j));
  469. columnNames.push(device.channelColumnName(j));
  470. channelType.push(device.channelType(j));
  471. if(device.isChannelHidden(j)) {
  472. channelVisibility.push(false);
  473. } else {
  474. channelVisibility.push(true);
  475. var indicator = new TemperatureDisplay;
  476. if(device.channelType(j) == "C")
  477. {
  478. indicator.setDisplayUnits(Units.Unitless);
  479. indicator.digitCount = 5;
  480. indicator.setDecimalPlaces(2);
  481. }
  482. temperatureDisplays.push(indicator);
  483. var decorator = new WidgetDecorator(indicator, device.channelIndicatorText(j), 2);
  484. device.getChannel(j).newData.connect(indicator.setValue);
  485. indicatorPanel.addWidget(decorator);
  486. }
  487. }
  488. device.start();
  489. pdevices.push(device);
  490. }
  491. else if(driverReference.driver == "annotationbutton")
  492. {
  493. var button = new AnnotationButton(driverReference.buttontext);
  494. button.setAnnotation(driverReference.annotationtext);
  495. annotationButtons.push(button);
  496. annotationPanel.addWidget(button);
  497. tabControls.push(button);
  498. }
  499. else if(driverReference.driver == "thresholdannotation")
  500. {
  501. var noteDetector = new ThresholdDetector();
  502. var noteEmitter = new Annotator(driverReference.annotation);
  503. noteDetector.setThreshold(Number(driverReference.value));
  504. for(var j = 0; j < columnNames.length; j++) {
  505. if(columnNames[j] == driverReference.source) {
  506. channels[j].newData.connect(noteDetector.newMeasurement);
  507. break;
  508. }
  509. }
  510. if(Number(driverReference.direction) == 1) {
  511. noteDetector.setEdgeDirection(ThresholdDetector.Descending);
  512. } else {
  513. noteDetector.setEdgeDirection(ThresholdDetector.Ascending);
  514. }
  515. var scope = new Object;
  516. scope.invoke = function() {
  517. if(timer.running) {
  518. arguments.callee.noteEmitter.annotate();
  519. }
  520. }
  521. scope.invoke.noteEmitter = noteEmitter;
  522. noteDetector.timeForValue.connect(scope.invoke);
  523. annotationButtons.push(noteEmitter);
  524. }
  525. else if(driverReference.driver == "valueannotation")
  526. {
  527. var checker = new ValueAnnotation;
  528. var valuesSetting = driverReference.measuredValues;
  529. var notesSetting = driverReference.annotations;
  530. var valuesList = valuesSetting.slice(2, valuesSetting.length-2).split(",");
  531. var notesList = notesSetting.slice(2, notesSetting.length-2).split(",");
  532. if(valuesList.length > 1 && notesList.length == valuesList.length) {
  533. for(var j = 0; j < valuesList.length; j++) {
  534. checker.setAnnotation(Number(valuesList[j]), notesList[j]);
  535. }
  536. }
  537. if(driverReference.emitOnStart == "true") {
  538. start.clicked.connect(checker.annotate);
  539. }
  540. var colname = driverReference.source;
  541. for(var j = 0; j < columnNames.length; j++) {
  542. if(columnNames[j] == colname) {
  543. channels[j].newData.connect(checker.newMeasurement);
  544. break;
  545. }
  546. }
  547. annotationButtons.push(checker);
  548. }
  549. else if(driverReference.driver == "reconfigurablebutton")
  550. {
  551. var button = new AnnotationButton(driverReference.buttontext);
  552. button.setAnnotation(driverReference.annotationtext);
  553. annotationButtons.push(button);
  554. annotationPanel.addWidget(button);
  555. tabControls.push(button);
  556. nsparam.enabled = true;
  557. nsparam.triggered.connect(function() {
  558. var setParam = createWindow("sampleParameters");
  559. setParam.windowTitle = TTR("basicWindow", "Typica - Set Sample Parameters");
  560. setParam.button = button;
  561. });
  562. stop.clicked.connect(button.incrementBatch);
  563. stop.clicked.connect(button.resetCount);
  564. }
  565. else if(driverReference.driver == "annotationspinbox")
  566. {
  567. var layout = new QBoxLayout;
  568. var label = new QLabel(driverReference.label);
  569. layout.addWidget(label, 0, 2);
  570. var spinbox = new AnnotationSpinBox;
  571. spinbox.setPretext(driverReference.pretext);
  572. spinbox.setPosttext(driverReference.posttext);
  573. spinbox.minimum = driverReference.minimum;
  574. spinbox.maximum = driverReference.maximum;
  575. spinbox.decimals = driverReference.precision;
  576. layout.addWidget(spinbox, 0, 1);
  577. annotationPanel.addLayout(layout);
  578. annotationButtons.push(spinbox);
  579. tabControls.push(spinbox);
  580. }
  581. else if(driverReference.driver == "freeannotation")
  582. {
  583. var layout = new QBoxLayout;
  584. var label = new QLabel(driverReference.labeltext);
  585. var control = new QLineEdit;
  586. layout.addWidget(label, 0, 2);
  587. layout.addWidget(control, 0, 1);
  588. annotationPanel.addLayout(layout);
  589. tabControls.push(control);
  590. control.returnPressed.connect(function() {
  591. for(var i = window.firstTempColumn; i < window.annotationColumn; i++) {
  592. log.newAnnotation(control.text, i, window.annotationColumn);
  593. }
  594. });
  595. }
  596. else if(driverReference.driver == "linearspline")
  597. {
  598. var colname = driverReference.source;
  599. for(var j = 0; j < columnNames.length; j++)
  600. {
  601. if(columnNames[j] == colname)
  602. {
  603. var calibrator = new LinearSplineInterpolator;
  604. var sv = driverReference.sourcevalues;
  605. var dv = driverReference.destinationvalues;
  606. var sourcevalues = sv.slice(2, sv.length-2).split(",");
  607. var destvalues = dv.slice(2, dv.length-2).split(",");
  608. if(sourcevalues.length > 1 && destvalues.length == sourcevalues.length)
  609. {
  610. for(var k = 0; k < sourcevalues.length; k++)
  611. {
  612. calibrator.add_pair(Number(sourcevalues[k]),Number(destvalues[k]));
  613. }
  614. var indicator = new TemperatureDisplay;
  615. if(channelType[j] == "C") {
  616. indicator.setDisplayUnits(Units.Unitless);
  617. indicator.setDecimalPlaces(2);
  618. }
  619. temperatureDisplays.push(indicator);
  620. var decorator = new WidgetDecorator(indicator, configModel.data(driverIndex, 0), 2);
  621. channels[j].newData.connect(calibrator.newMeasurement);
  622. calibrator.newData.connect(indicator.setValue);
  623. channels.push(calibrator);
  624. // Channel hiding is not yet configurable for this.
  625. // I'm not sure if there's any need to allow this
  626. // to be hidden at present.
  627. channelVisibility.push(true);
  628. channelType.push(channelType[j]);
  629. columnNames.push(driverReference.destination);
  630. indicatorPanel.addWidget(decorator);
  631. }
  632. break;
  633. }
  634. }
  635. }
  636. else if(driverReference.driver == "translation")
  637. {
  638. var colname = driverReference.column;
  639. window.targetcolumnname = colname;
  640. if(driverReference.delay)
  641. {
  642. translationdelay.interval = Number(driverReference.delay) * 1000;
  643. }
  644. for(var j = 0; j < columnNames.length; j++)
  645. {
  646. if(columnNames[j] == colname)
  647. {
  648. translationChannel = j;
  649. var indicator = new TemperatureDisplay;
  650. indicator.digitCount = 4;
  651. externtrans = indicator;
  652. indicator.display(0);
  653. var decorator = new WidgetDecorator(indicator, configModel.data(driverIndex, 0), 2);
  654. indicatorPanel.addWidget(decorator);
  655. currentDetector.timeForValue.connect(function(value) {
  656. if(!hasTranslated)
  657. {
  658. var currentOffset = value;
  659. if(targetOffset != 0)
  660. {
  661. var translation = currentOffset - targetOffset;
  662. externtrans.display(translation);
  663. gtrans = translation;
  664. if(translation > 0)
  665. {
  666. window.translateLoadedSeries(translation);
  667. }
  668. else
  669. {
  670. window.translateCurrentSeries(-translation);
  671. }
  672. }
  673. }
  674. hasTranslated = true;
  675. resetTranslation.enabled = true;
  676. });
  677. resetTranslation.triggered.connect(function() {
  678. if(gtrans > 0) {
  679. window.translateLoadedSeries(-gtrans);
  680. }
  681. else {
  682. window.translateCurrentSeries(gtrans);
  683. }
  684. oldtrans = gtrans;
  685. gtrans = 0;
  686. externtrans.display(0);
  687. hasTranslated = false;
  688. setTranslation.enabled = true;
  689. });
  690. setTranslation.triggered.connect(function() {
  691. externtrans.display(oldtrans);
  692. gtrans = oldtrans;
  693. if(gtrans > 0) {
  694. window.translateLoadedSeries(gtrans);
  695. }
  696. else {
  697. window.translateCurrentSeries(-gtrans);
  698. }
  699. hasTranslated = true;
  700. resetTranslation.enabled = true;
  701. setTranslation.enabled = false;
  702. });
  703. }
  704. }
  705. targetDetector.setThreshold(driverReference.FValue);
  706. currentDetector.setThreshold(driverReference.FValue);
  707. }
  708. else if(driverReference.driver == "rate")
  709. {
  710. var primaryColumn = driverReference.column;
  711. for(var j = 0; j < columnNames.length; j++)
  712. {
  713. if(columnNames[j] == primaryColumn)
  714. {
  715. var rate = new RateOfChange(driverReference.cache, driverReference.scale);
  716. channels[j].newData.connect(rate.newMeasurement);
  717. var indicator = new TemperatureDisplay;
  718. indicator.setRelativeMode(true);
  719. indicator.display(0);
  720. indicator.digitCount = 9;
  721. var decorator = new WidgetDecorator(indicator, configModel.data(driverIndex, 0), 2);
  722. indicatorPanel.addWidget(decorator);
  723. rate.newData.connect(indicator.setValue);
  724. temperatureDisplays.push(indicator);
  725. channels.push(rate);
  726. // This cannot at present be configured to be
  727. // hidden.
  728. channelVisibility.push(true);
  729. channelType.push("T");
  730. columnNames.push(configModel.data(driverIndex, 0));
  731. }
  732. }
  733. }
  734. else if(driverReference.driver == "mergeseries")
  735. {
  736. var mergeSeries;
  737. var indicator = new TemperatureDisplay;
  738. if(driverReference.type == "Difference") {
  739. mergeSeries = new DifferenceSeries();
  740. indicator.setRelativeMode(true);
  741. } else {
  742. mergeSeries = new MeanSeries();
  743. }
  744. var firstColumn = driverReference.column1;
  745. var secondColumn = driverReference.column2;
  746. for(var j = 0; j < columnNames.length; j++) {
  747. if(columnNames[j] == firstColumn) {
  748. channels[j].newData.connect(mergeSeries.in1);
  749. } else if (columnNames[j] == secondColumn) {
  750. channels[j].newData.connect(mergeSeries.in2);
  751. }
  752. }
  753. indicator.display(0);
  754. indicator.digitCount = 9;
  755. var decorator = new WidgetDecorator(indicator, configModel.data(driverIndex, 0), 2);
  756. indicatorPanel.addWidget(decorator);
  757. mergeSeries.newData.connect(indicator.setValue);
  758. temperatureDisplays.push(indicator);
  759. channels.push(mergeSeries);
  760. // This cannot at present be configured to be hidden.
  761. channelVisibility.push(true);
  762. channelType.push("T");
  763. columnNames.push(driverReference.output);
  764. }
  765. else if(driverReference.driver == "scale")
  766. {
  767. var scale = new SerialScale(driverReference.port);
  768. scale.setDataBits(8);
  769. scale.setBaudRate(driverReference.baudrate);
  770. scale.setParity(driverReference.parity);
  771. scale.setStopBits(driverReference.stopbits);
  772. scale.setFlowControl(driverReference.flowcontrol);
  773. scale.setWeighCommand(driverReference.weighcommand);
  774. scale.setCommandTerminator(driverReference.commandterminator);
  775. scale.open(3);
  776. window.scales.push(scale);
  777. }
  778. else if(driverReference.driver == "coolingtimer")
  779. {
  780. var coolingTimer = new TimerDisplay();
  781. coolingTimer.setDisplayFormat("mm:ss");
  782. var decorator = new WidgetDecorator(coolingTimer, configModel.data(driverIndex, 0), 2);
  783. indicatorPanel.addWidget(decorator);
  784. coolingTimer.setTimerMode(1);
  785. coolingTimer.setAutoReset(true);
  786. var timeValue = new QTime();
  787. timeValue = timeValue.fromString(driverReference.reset, "mm:ss");
  788. coolingTimer.setResetValue(timeValue);
  789. stop.clicked.connect(coolingTimer.startTimer);
  790. }
  791. else if(driverReference.driver == "rangetimer")
  792. {
  793. rangetimers.push(new TimerDisplay());
  794. var rangeTimer = rangetimers[rangetimers.length - 1];
  795. rangeTimer.setDisplayFormat("mm:ss");
  796. var decorator = new WidgetDecorator(rangeTimer, configModel.data(driverIndex, 0), 2);
  797. indicatorPanel.addWidget(decorator);
  798. stop.clicked.connect(rangeTimer.stopTimer);
  799. start.clicked.connect(rangeTimer.reset);
  800. if(driverReference.starttrigger == "batch")
  801. {
  802. start.clicked.connect(rangeTimer.startTimer);
  803. }
  804. else if(driverReference.starttrigger == "manual")
  805. {
  806. var startButton = new AnnotationButton(driverReference.startbuttontext);
  807. startButton.clicked.connect(rangeTimer.startTimer);
  808. annotationPanel.addWidget(startButton);
  809. tabControls.push(button);
  810. }
  811. else if(driverReference.starttrigger == "value")
  812. {
  813. var startTrigger = new ThresholdDetector();
  814. startTrigger.setThreshold(Number(driverReference.startvalue));
  815. var scope = new Object;
  816. scope.invoke = function() {
  817. if(timer.running && !(arguments.callee.rangeTimer.running))
  818. {
  819. arguments.callee.rangeTimer.startTimer();
  820. }
  821. };
  822. scope.invoke.rangeTimer = rangeTimer;
  823. startTrigger.timeForValue.connect(scope.invoke);
  824. for(var j = 0; j < columnNames.length; j++)
  825. {
  826. if(columnNames[j] == driverReference.startcolumnname)
  827. {
  828. channels[j].newData.connect(startTrigger.newMeasurement);
  829. }
  830. }
  831. }
  832. stop.clicked.connect(rangeTimer.stopTimer)
  833. if(driverReference.stoptrigger == "manual")
  834. {
  835. var stopButton = new AnnotationButton(driverReference.stopbuttontext);
  836. stopButton.clicked.connect(rangeTimer.stopTimer);
  837. annotationPanel.addWidget(stopButton);
  838. tabControls.push(button);
  839. }
  840. else if(driverReference.stoptrigger == "value")
  841. {
  842. var stopTrigger = new ThresholdDetector();
  843. stopTrigger.setThreshold(Number(driverReference.stopvalue));
  844. stopTrigger.timeForValue.connect(rangeTimer.stopTimer);
  845. for(var j = 0; j < columnNames.length; j++)
  846. {
  847. if(columnNames[j] == driverReference.stopcolumnname)
  848. {
  849. channels[j].newData.connect(stopTrigger.newMeasurement);
  850. }
  851. }
  852. }
  853. rangeTimer.reportingName = configModel.data(driverIndex, 0);
  854. rangeTimer.report = function() {
  855. return "" + this.reportingName + ": " + this.value;
  856. };
  857. }
  858. else if(driverReference.driver = "multirangetimer")
  859. {
  860. var rangeTimer = new TimerDisplay();
  861. rangeTimer.setDisplayFormat("mm:ss");
  862. var decorator = new WidgetDecorator(rangeTimer, configModel.data(driverIndex, 0), 2);
  863. indicatorPanel.addWidget(decorator);
  864. var rangenames = driverReference.rangenames;
  865. var endtemps = driverReference.endtemps;
  866. var names = rangenames.slice(2, rangenames.length - 2).split(", ");
  867. rangeTimer.rangeNames = new Array();
  868. for(var j = 0; j < names.length; j++)
  869. {
  870. var name = names[j].slice(1, names[j].length - 1);
  871. rangeTimer.rangeNames.push(name);
  872. }
  873. rangeTimer.rangeEnds = new Array();
  874. var ends = endtemps.slice(2, endtemps.length - 2).split(", ");
  875. for(var j = 0; j < ends.length; j++)
  876. {
  877. rangeTimer.rangeEnds.push(Number(ends[j]));
  878. }
  879. rangeTimer.currentRange = 0;
  880. rangeTimer.results = new Array();
  881. rangeTimer.trigger = new ThresholdDetector();
  882. for(var j = 0; j < columnNames.length; j++)
  883. {
  884. if(columnNames[j] == driverReference.trigger)
  885. {
  886. channels[j].newData.connect(rangeTimer.trigger.newMeasurement);
  887. }
  888. }
  889. rangeTimer.startRanges = function() {
  890. arguments.callee.timer.currentRange = 0;
  891. arguments.callee.timer.results.splice(0, arguments.callee.timer.results.length);
  892. arguments.callee.timer.trigger.setThreshold(arguments.callee.timer.rangeEnds[0]);
  893. };
  894. rangeTimer.startRanges.timer = rangeTimer;
  895. start.clicked.connect(rangeTimer.startTimer);
  896. start.clicked.connect(rangeTimer.startRanges);
  897. rangeTimer.transition = function() {
  898. arguments.callee.timer.stopTimer();
  899. arguments.callee.timer.results.push(arguments.callee.timer.value);
  900. arguments.callee.timer.reset();
  901. arguments.callee.timer.startTimer();
  902. arguments.callee.timer.currentRange++;
  903. if(arguments.callee.timer.currentRange <= arguments.callee.timer.rangeEnds.length)
  904. {
  905. arguments.callee.timer.trigger.setThreshold(arguments.callee.timer.rangeEnds[arguments.callee.timer.currentRange]);
  906. }
  907. };
  908. rangeTimer.transition.timer = rangeTimer;
  909. rangeTimer.trigger.timeForValue.connect(rangeTimer.transition);
  910. stop.clicked.connect(rangeTimer.transition);
  911. stop.clicked.connect(rangeTimer.stopTimer);
  912. rangeTimer.report = function() {
  913. var retval = "";
  914. for(var j = 0; j < arguments.callee.timer.results.length; j++)
  915. {
  916. retval += arguments.callee.timer.rangeNames[j] + ": " + arguments.callee.timer.results[j] + "\n";
  917. }
  918. return retval;
  919. };
  920. rangeTimer.report.timer = rangeTimer;
  921. rangetimers.push(rangeTimer);
  922. }
  923. }
  924. }
  925. for(var i = 1; i < tabControls.length; i++)
  926. {
  927. setTabOrder(tabControls[i-1], tabControls[i]);
  928. }
  929. log.setHeaderData(0, "Time");
  930. var channelSkip = 0;
  931. for(var i = 0; i < columnNames.length; i++) {
  932. if(channelVisibility[i]) {
  933. log.setHeaderData(i + 1 - channelSkip, columnNames[i]);
  934. log.addToCurrentColumnSet(i + 1 - channelSkip);
  935. }
  936. else {
  937. channelSkip++;
  938. }
  939. }
  940. log.setHeaderData(columnNames.length + 1 - channelSkip, TTR("basicWindow", "Note"));
  941. var timer = new TimerDisplay;
  942. timer.displayFormat = "mm:ss";
  943. timer.autoReset = true;
  944. var btdecorator = new WidgetDecorator(timer, TTR("basicWindow", "Batch Timer"), 2);
  945. indicatorPanel.addWidget(btdecorator);
  946. var vsplit = findChildObject(this, 'main');
  947. var isplit = findChildObject(this, 'indicators');
  948. var lsplit = findChildObject(this, 'logsplit');
  949. window.aboutToClose.connect(function() {
  950. for(var i = 0; i < nidevices.length; i++)
  951. {
  952. nidevices[i].stop();
  953. nidevices[i].deleteLater();
  954. }
  955. for(var i = 0; i < modbusdevices.length; i++)
  956. {
  957. modbusdevices[i].deleteLater();
  958. }
  959. for(var i = 0; i < dataqsdkdevices.length; i++)
  960. {
  961. dataqsdkdevices[i].deleteLater();
  962. }
  963. for(var i = 0; i < jsdevices.length; i++)
  964. {
  965. jsdevices[i].stop();
  966. jsdevices[i].deleteLater();
  967. }
  968. for(var i = 0; i < pdevices.length; i++)
  969. {
  970. pdevices[i].stop();
  971. pdevices[i].deleteLater();
  972. }
  973. delete nidevices;
  974. delete modbusdevices;
  975. delete dataqsdkdevices;
  976. delete jsdevices;
  977. delete pdevices;
  978. window.saveSizeAndPosition("window");
  979. vsplit.saveState("script/loggingView/" + roasterIndex + "/mainSplitter");
  980. QSettings.setValue("script/loggingView/" + roasterIndex + "/instrumentCount", isplit.count());
  981. isplit.saveState("script/loggingView/" + roasterIndex + "/instrumentSplitter");
  982. lsplit.saveState("script/loggingView/" + roasterIndex + "/logSplitter");
  983. log.saveState("script/log", 7);
  984. window.navigationWindow.loggingWindow = undefined;
  985. Windows.loggingWindow = undefined;
  986. });
  987. this.restoreSizeAndPosition('window');
  988. vsplit.restoreState("script/loggingView/" + roasterIndex + "/mainSplitter");
  989. if(QSettings.value("script/loggingView/" + roasterIndex + "/instrumentCount") == isplit.count()) {
  990. isplit.restoreState("script/loggingView/" + roasterIndex + "/instrumentSplitter");
  991. }
  992. lsplit.restoreState("script/loggingView/" + roasterIndex + "/logSplitter");
  993. log.restoreState("script/log", 7);
  994. var offsets = new Array();
  995. var zeroemitters = new Array();
  996. var adapters = new Array();
  997. channelSkip = 0;
  998. for(var i = 0; i < channels.length; i++) {
  999. if(channelVisibility[i]) {
  1000. var offset = new MeasurementTimeOffset(epoch);
  1001. offsets.push(offset);
  1002. channels[i].newData.connect(offset.newMeasurement);
  1003. var adapter = new MeasurementAdapter(i + 1 - channelSkip);
  1004. adapters.push(adapter);
  1005. offset.measurement.connect(adapter.newMeasurement);
  1006. var emitter = new ZeroEmitter(i + 1);
  1007. zeroemitters.push(emitter);
  1008. channels[i].newData.connect(emitter.newMeasurement);
  1009. emitter.measurement.connect(log.newMeasurement);
  1010. emitter.measurement.connect(graph.newMeasurement);
  1011. } else {
  1012. channelSkip++;
  1013. }
  1014. }
  1015. var offsetForChannel = function(c) {
  1016. var retval = -1;
  1017. for(var i = 0; i <= c; i++) {
  1018. if(channelVisibility[i]) {
  1019. retval++;
  1020. }
  1021. }
  1022. return retval;
  1023. };
  1024. translationdelay.timeout.connect(function() {
  1025. offsets[offsetForChannel(translationChannel)].measurement.connect(currentDetector.newMeasurement);
  1026. });
  1027. start.clicked.connect(function() {
  1028. start.enabled = false;
  1029. hasTranslated = false;
  1030. resetTranslation.enabled = false;
  1031. setTranslation.enabled = false;
  1032. var epoch = new QTime();
  1033. epoch = epoch.currentTime();
  1034. for(var i = 0; i < offsets.length; i++) {
  1035. offsets[i].setZeroTime(epoch);
  1036. zeroemitters[i].emitZero();
  1037. adapters[i].measurement.connect(log.newMeasurement);
  1038. adapters[i].measurement.connect(graph.newMeasurement);
  1039. }
  1040. for(var i = 0; i < rateadapters.length; i++) {
  1041. rateoffsets[i].setZeroTime(epoch);
  1042. ratezeros[i].emitZero();
  1043. rateadapters[i].measurement.connect(graph.newMeasurement);
  1044. }
  1045. timer.startTimer();
  1046. if(typeof(currentBatchInfo) == 'undefined') { } else {
  1047. query = new QSqlQuery();
  1048. query.exec("SELECT now()::timestamp without time zone");
  1049. query.next();
  1050. var result = query.value(0);
  1051. query = query.invalidate();
  1052. var timefield = findChildObject(currentBatchInfo, 'time');
  1053. timefield.text = result.replace('T', ' ');
  1054. }
  1055. if(translationChannel >= 0) {
  1056. translationdelay.start();
  1057. }
  1058. if(typeof(externtrans) != 'undefined') {
  1059. externtrans.display(0);
  1060. }
  1061. stop.enabled = true;
  1062. window.windowModified = true;
  1063. graph.setTimeIndicatorEnabled(true);
  1064. });
  1065. for(var i = 0; i < annotationButtons.length; i++) {
  1066. if(channels.length > 0) {
  1067. annotationButtons[i].annotation.connect(log.newAnnotation);
  1068. annotationButtons[i].setTemperatureColumn(1);
  1069. annotationButtons[i].setAnnotationColumn(channels.length - channelSkip + 1);
  1070. annotationButtons[i].annotation.connect(function(note, tcol, ncol) {
  1071. for(var i = tcol; i < ncol; i++) {
  1072. log.newAnnotation(note, i, ncol);
  1073. }
  1074. });
  1075. }
  1076. }
  1077. start.setFocus();
  1078. stop.annotation.connect(log.newAnnotation);
  1079. stop.clicked.connect(timer.stopTimer);
  1080. stop.setTemperatureColumn(1);
  1081. stop.setAnnotationColumn(channels.length - channelSkip + 1);
  1082. QSettings.setValue("liveColumn", 1);
  1083. var lc = 1;
  1084. stop.clicked.connect(function() {
  1085. stop.enabled = false;
  1086. for(var i = 0; i < adapters.length; i++) {
  1087. adapters[i].measurement.disconnect(log.newMeasurement);
  1088. adapters[i].measurement.disconnect(graph.newMeasurement);
  1089. }
  1090. for(var i = 0; i < rateadapters.length; i++) {
  1091. rateadapters[i].measurement.disconnect(graph.newMeasurement);
  1092. }
  1093. targetOffset = 0;
  1094. if(typeof(currentBatchInfo) == 'undefined') { } else {
  1095. lc = Number(QSettings.value("liveColumn"));
  1096. var duration = log.lastTime(lc);
  1097. var durfield = findChildObject(currentBatchInfo, 'duration');
  1098. durfield.text = duration;
  1099. log.clearOutputColumns();
  1100. channelSkip = 0;
  1101. for(var i = 0; i < channels.length; i++) {
  1102. if(channelVisibility[i]) {
  1103. if(channelType[i] == "T") {
  1104. log.addOutputTemperatureColumn(lc + i - channelSkip);
  1105. } else {
  1106. log.addOutputControlColumn(lc + i - channelSkip);
  1107. }
  1108. } else {
  1109. channelSkip++;
  1110. }
  1111. }
  1112. log.addOutputAnnotationColumn(lc + channels.length - channelSkip);
  1113. var filename = log.saveTemporary();
  1114. currentBatchInfo.tempData = filename;
  1115. currentBatchInfo.endBatch();
  1116. var notes = findChildObject(currentBatchInfo, 'annotation');
  1117. for(var i = 0; i < rangetimers.length; i++) {
  1118. notes.append(rangetimers[i].report());
  1119. }
  1120. currentBatchInfo.raise();
  1121. currentBatchInfo.activateWindow();
  1122. }
  1123. if(translationChannel >= 0)
  1124. {
  1125. if(translationdelay.active) {
  1126. translationdelay.stop();
  1127. } else {
  1128. offsets[offsetForChannel(translationChannel)].measurement.disconnect(currentDetector.newMeasurement);
  1129. }
  1130. }
  1131. start.enabled = true;
  1132. window.windowModified = false;
  1133. graph.setTimeIndicatorEnabled(false);
  1134. });
  1135. stop.annotation.connect(function(note, tcol, ncol) {
  1136. for(var i = tcol; i < ncol; i++) {
  1137. log.newAnnotation(note, i, ncol);
  1138. }
  1139. });
  1140. var quitMenu = findChildObject(this, 'quit');
  1141. quitMenu.triggered.connect(function() {
  1142. window.close();
  1143. Application.quit();
  1144. });
  1145. var v1 = findChildObject(this, 'ms');
  1146. v1.triggered.connect(log.LOD_ms);
  1147. var v2 = findChildObject(this, '1s');
  1148. v2.triggered.connect(log.LOD_1s);
  1149. var v3 = findChildObject(this, '5s');
  1150. v3.triggered.connect(log.LOD_5s);
  1151. var v4 = findChildObject(this, '10s');
  1152. v4.triggered.connect(log.LOD_10s);
  1153. var v5 = findChildObject(this, '15s');
  1154. v5.triggered.connect(log.LOD_15s);
  1155. var v6 = findChildObject(this, '30s');
  1156. v6.triggered.connect(log.LOD_30s);
  1157. var v7 = findChildObject(this, '1m');
  1158. v7.triggered.connect(log.LOD_1m);
  1159. var showC = findChildObject(this, 'showC');
  1160. showC.triggered.connect(function() {
  1161. for(var i = 0; i < temperatureDisplays.length; i++) {
  1162. temperatureDisplays[i].setDisplayUnits(Units.Celsius);
  1163. }
  1164. log.setDisplayUnits(Units.Celsius);
  1165. graph.showC();
  1166. QSettings.setValue("temperatureUnit", "C");
  1167. });
  1168. var showF = findChildObject(this, 'showF');
  1169. showF.triggered.connect(function() {
  1170. for(var i = 0; i < temperatureDisplays.length; i++) {
  1171. temperatureDisplays[i].setDisplayUnits(Units.Fahrenheit);
  1172. }
  1173. log.setDisplayUnits(Units.Fahrenheit);
  1174. graph.showF();
  1175. QSettings.setValue("temperatureUnit", "F");
  1176. });
  1177. if(QSettings.value("temperatureUnit", "F") == "C") {
  1178. showC.trigger();
  1179. }
  1180. window.postLoadColumnSetup = function(c) {
  1181. for(var i = 0; i < adapters.length; i++) {
  1182. adapters[i].setColumn(c + i + 1);
  1183. zeroemitters[i].setColumn(c + i + 1);
  1184. log.setHeaderData(c + i + 1, columnName(i));
  1185. }
  1186. log.setHeaderData(c + columnNames.length + 1 - channelSkip, TTR("basicWindow", "Note"));
  1187. stop.setTemperatureColumn(c + 1);
  1188. stop.setAnnotationColumn(c + columnNames.length + 1 - channelSkip);
  1189. for(var i = 0; i < annotationButtons.length; i++) {
  1190. annotationButtons[i].setTemperatureColumn(c + 1);
  1191. annotationButtons[i].setAnnotationColumn(c + columnNames.length + 1 - channelSkip);
  1192. }
  1193. log.clearCurrentColumnSet();
  1194. for(var i = 0; i < channels.length - channelSkip; i++) {
  1195. log.addToCurrentColumnSet(c + i + 1);
  1196. }
  1197. window.firstTempColumn = c + 1;
  1198. window.annotationColumn = c + columnNames.length - channelSkip + 1;
  1199. }
  1200. var clear = findChildObject(this, 'clear');
  1201. window.clearLog = function() {
  1202. log.clear();
  1203. graph.clear();
  1204. window.windowTitle = "Typica [*]";
  1205. log.setHeaderData(0, "Time");
  1206. QSettings.setValue("liveColumn", 1);
  1207. window.postLoadColumnSetup(0);
  1208. if(typeof(externtrans) != 'undefined') {
  1209. externtrans.display(0);
  1210. }
  1211. resetTranslation.enabled = false;
  1212. setTranslation.enabled = false;
  1213. targetOffset = 0;
  1214. };
  1215. clear.triggered.connect(window.clearLog);
  1216. var openMenu = findChildObject(this, 'open');
  1217. var compareMenu = findChildObject(this, 'compare');
  1218. compareMenu.triggered.connect(function() {
  1219. QSettings.setValue('cseries', lc+1);
  1220. var history = createReport("historyreport.xml");
  1221. history.windowTitle = TTR("basicWindow", "Typica - Roasting Log");
  1222. });
  1223. var printMenu = findChildObject(this, 'print');
  1224. printMenu.triggered.connect(function() {
  1225. var exportWindow = createWindow("print");
  1226. exportWindow.windowTitle = TTR("basicWindow", "Typica - Print");
  1227. exportWindow.log = log;
  1228. });
  1229. var svgExportMenu = findChildObject(this, 'svgexport');
  1230. svgExportMenu.triggered.connect(function() {
  1231. var exportWindow = createWindow("exportWindow");
  1232. exportWindow.windowTitle = TTR("basicWindow", "Typica - Export XHTML+SVG");
  1233. exportWindow.log = log;
  1234. });
  1235. window.loadPlan = function(device, name) {
  1236. window.clearLog();
  1237. var input = new XMLInput(device, 1);
  1238. targetseries = -1;
  1239. input.newTemperatureColumn.connect(log.setHeaderData);
  1240. input.newTemperatureColumn.connect(function(col, text) {
  1241. if(text == window.targetcolumnname) {
  1242. targetseries = col;
  1243. }
  1244. });
  1245. input.newAnnotationColumn.connect(log.setHeaderData);
  1246. input.measure.connect(graph.newMeasurement);
  1247. input.measure.connect(log.newMeasurement);
  1248. input.measure.connect(function(data, series) {
  1249. if(series == targetseries) {
  1250. targetDetector.newMeasurement(data);
  1251. }
  1252. });
  1253. resetTranslation.enabled = false;
  1254. setTranslation.enabled = false;
  1255. input.annotation.connect(log.newAnnotation);
  1256. input.annotation.connect(function(note, tcol, ncol) {
  1257. for(var i = tcol; i < ncol; i++) {
  1258. log.newAnnotation(note, i, ncol);
  1259. }
  1260. });
  1261. var lc;
  1262. input.lastColumn.connect(function(c) {
  1263. lc = c;
  1264. QSettings.setValue("liveColumn", c + 1);
  1265. window.postLoadColumnSetup(c);
  1266. });
  1267. graph.updatesEnabled = false;
  1268. log.updatesEnabled = false;
  1269. input.input();
  1270. log.updatesEnabled = true;
  1271. graph.updatesEnabled = true;
  1272. window.windowTitle = 'Typica - [*]' + name;
  1273. log.newAnnotation(TTR("basicWindow", "End"), 1, lc);
  1274. window.raise();
  1275. window.activateWindow();
  1276. }
  1277. openMenu.triggered.connect(function() {
  1278. var filename = QFileDialog.getOpenFileName(window, TTR("basicWindow", "Open Log..."), QSettings.value('script/lastDir', '') + '/');
  1279. if(filename != '') {
  1280. var file = new QFile(filename);
  1281. window.loadPlan(file, baseName(filename));
  1282. QSettings.setValue("script/lastDir", dir(filename));
  1283. }
  1284. });
  1285. var columnName = function(c) {
  1286. var visibleColumns = 0;
  1287. for(var i = 0; i < channels.length; i++) {
  1288. if(channelVisibility[i]) {
  1289. visibleColumns++;
  1290. }
  1291. if(c == visibleColumns - 1) {
  1292. return columnNames[i];
  1293. }
  1294. }
  1295. return "";
  1296. };
  1297. var saveMenu = findChildObject(this, 'save');
  1298. saveMenu.triggered.connect(function() {
  1299. var filename = QFileDialog.getSaveFileName(window, TTR("basicWindow", "Save Log As..."), QSettings.value("script/lastDir", "") + "/");
  1300. if(filename != "") {
  1301. var lc = Number(QSettings.value("liveColumn"));
  1302. var file = new QFile(filename);
  1303. log.clearOutputColumns();
  1304. channelSkip = 0;
  1305. for(var i = 0; i < channels.length; i++) {
  1306. if(channelVisibility[i]) {
  1307. if(channelType[i] == "T") {
  1308. log.addOutputTemperatureColumn(lc + i - channelSkip);
  1309. } else {
  1310. log.addOutputControlColumn(lc + i - channelSkip);
  1311. }
  1312. } else {
  1313. channelSkip++;
  1314. }
  1315. }
  1316. log.addOutputAnnotationColumn(lc + columnNames.length - channelSkip);
  1317. log.saveXML(file);
  1318. QSettings.setValue("script/lastDir", dir(filename));
  1319. }
  1320. });
  1321. var exportMenu = findChildObject(this, 'export');
  1322. exportMenu.triggered.connect(function() {
  1323. var filename = QFileDialog.getSaveFileName(window, TTR("basicWindow", "Export CSV As..."), QSettings.value("script/lastDir", "") + "/");
  1324. if(filename != "") {
  1325. var lc = Number(QSettings.value("liveColumn"));
  1326. var file = new QFile(filename);
  1327. log.clearOutputColumns();
  1328. for(var i = 0; i < columnNames.length - channelSkip; i++) {
  1329. log.addOutputTemperatureColumn(lc + i);
  1330. }
  1331. log.addOutputAnnotationColumn(lc + columnNames.length - channelSkip);
  1332. log.saveCSV(file);
  1333. QSettings.setValue("script/lastDir", dir(filename));
  1334. }
  1335. });
  1336. var newMenu = findChildObject(this, 'new');
  1337. newMenu.triggered.connect(function() {
  1338. var bwindow = createWindow("batchWindow");
  1339. bwindow.windowTitle = TTR("basicWindow", "Typica - [*]New Batch");
  1340. });
  1341. var newSampleMenu = findChildObject(this, 'newsample');
  1342. newSampleMenu.triggered.connect(function() {
  1343. var bwindow = createWindow("sampleRoastingBatch");
  1344. });
  1345. window.postLoadColumnSetup(0);
  1346. Windows.loggingWindow = window;
  1347. ]]>
  1348. </program>
  1349. </window>