hendrick Posted June 14, 2012 Share Posted June 14, 2012 Hi, I was hoping I could get help connecting an digital balance to DAQFactory, my digital balance can communicate with hyperterminal program on windows XP via COM port. I want use DAQFactory to communicate, first I choose Device Configuration -> New Serial (RS232/485)/Ethernet (TCP/IP) device and I try with "Null Protocol". A screenshot of the monitor window is attached here (with a mass of 100g). Now, I want save the value of the mass in a channel? Can you help please. Link to comment Share on other sites More sharing options...
AzeoTech Posted June 18, 2012 Share Posted June 18, 2012 If you don't care about the + / - in front its super simple. Let's assume your device you created is called "myDevice" and you created a channel called "weight" that is type "Test", "A to D" with TIming = 0. Then just create a script like this: private string datainprivate datadevice.myDevice.readuntil(10) // clear half framewhile(1) try datain = device.myDevice.readUntil(10) data = strToDouble(mid(datain,1,1000)) weight.addValue(data) catch() ? strLastError delay(0.1) endcatchendwhile[/CODE]You'll notice I don't put a delay() in my loop. That's because the readUntil() will block until it receives a line of data. Basically, the loop is paced by the serial input from the scale. Note that in the catch() I do put a delay() to avoid an infinite loop if you have a typo or something.To make this more robust, you probably should check that the left most character of datain is "+" or "-":[CODE]private string datainprivate datadevice.myDevice.readuntil(10) // clear half framewhile(1) try datain = device.myDevice.readUntil(10) data = strToDouble(mid(datain,1,1000)) if (left(datain,1) == "+") weight.addValue(data) endif if (left(datain,1) == "-") weight.addValue(data * -1) endif catch() ? strLastError delay(0.1) endcatchendwhile[/CODE]This also allows you to handle negative readings. Link to comment Share on other sites More sharing options...
hendrick Posted June 20, 2012 Author Share Posted June 20, 2012 Thanks a lot for your explanation. I tested as you said and finaly got the results. With this digital balance I want to measure the engine fuel consumption by weighing the fuel tank. For this it is necessary to determine the difference between the current and previous value. I have tried creating a new "Variable value component" with: weight[1]-weight[0] It is possible to save this variable using "logging sets" ? Sorry that these are basic questions. Thanks Hendrick Link to comment Share on other sites More sharing options...
AzeoTech Posted June 21, 2012 Share Posted June 21, 2012 Sure, just create another Test channel (timing = 0), call it dW or something, then in your script, right before the catch() do: if (numrows(weight) > 1) dW.addValue(insertTime(weight[0] - weight[1], weight.time[0],0))endif[/CODE]Then log dW. Link to comment Share on other sites More sharing options...
hendrick Posted June 21, 2012 Author Share Posted June 21, 2012 thanks so much! Link to comment Share on other sites More sharing options...
hendrick Posted June 21, 2012 Author Share Posted June 21, 2012 My channel "weight" has "timing = 0", how can I control the acquisition times? The picture shown the channel "weight" and another channel with "Timing = 1". In the channel "weight" It is possible to obtain the acquisition 1 times every second as the other channel? Thank you for your help in advance Hendrick Link to comment Share on other sites More sharing options...
AzeoTech Posted June 22, 2012 Share Posted June 22, 2012 You can't control the timing. The balance is sending data when it wants to. It controls the timing. If you want to align your data to the other channel, you can either use the align() function, let the logging set do it for you, or create yet another Test channel with Timing = 0, then have it updated with whatever the latest weight reading (or wT) when your channel with Timing = 1 updates (by using its Event script). Link to comment Share on other sites More sharing options...
hendrick Posted June 26, 2012 Author Share Posted June 26, 2012 Hi, The value "weight" and "dW" should decrease as a function of time, but the "dW" is presenting an oscillation is possible due to accuracy of the equipment. As the value of "weight" it's correct, it is possible to calculate "dW" every 10sec as shown in the picture? Again like to express my thanks and appreciation for your help. Hendrick Link to comment Share on other sites More sharing options...
AzeoTech Posted June 27, 2012 Share Posted June 27, 2012 Sure, just do: if (numrows(weight) > 9) dW.addValue(insertTime(weight[0] - weight[9], weight.time[0],0))endif[/CODE] Link to comment Share on other sites More sharing options...
hendrick Posted June 27, 2012 Author Share Posted June 27, 2012 I tested it and it works! But some data is missing for some times. In my "Logging set:" I'm using "Align threshold: 1" to align my data. It's correct that? Thanks Hendrick Link to comment Share on other sites More sharing options...
AzeoTech Posted June 28, 2012 Share Posted June 28, 2012 First, remember the acquisition rate in your case is determined by your scale, not DF. Most likely, its pushing out data at an interval slightly larger than one second and rounding makes it look like its skipping data points every so often. You probably could see it better if you had your data analysis tool show some decimal seconds. Link to comment Share on other sites More sharing options...
hendrick Posted June 28, 2012 Author Share Posted June 28, 2012 I understand now. Thank for your help Hendrick Link to comment Share on other sites More sharing options...
Hgazel Posted July 13, 2012 Share Posted July 13, 2012 Hi, I have similar digital balance and my configuration in the Daqfactory is: Device name: "EP001" and my test channel is "massa" The script code is: private string datainprivate datadevice.EP001.readuntil(61) // clear half framewhile(1) try datain = device.EP001.readUntil(61) data = strToDouble(mid(datain,1,1000)) if (left(datain,1) == "+") massa.addValue(data) endif if (left(datain,1) == "-") massa.addValue(data * -1) endif catch() ? strLastError delay(0.1) endcatchendwhile[/CODE][/size][/indent]Work fine with low weights, but don't with large weight.Can you help me?Thanks. Link to comment Share on other sites More sharing options...
AzeoTech Posted July 13, 2012 Share Posted July 13, 2012 Your scale is different. I don't see any + or -, and you are stripping the = with the readUntil(61), so you just need: private string datainprivate datadevice.EP001.readuntil(61) // clear half framewhile(1) try datain = device.EP001.readUntil(61) data = strToDouble(datain) massa.addValue(data) catch() ? strLastError delay(0.1) endcatchendwhile[/CODE] Link to comment Share on other sites More sharing options...
Hgazel Posted July 16, 2012 Share Posted July 16, 2012 I understand now Thanks very much for your help. Link to comment Share on other sites More sharing options...
hendrick Posted August 18, 2012 Author Share Posted August 18, 2012 Hi, In my script the acquisition rate of the channel “weight” is determined by my scale (it's OK). But the channel “dW” is calculated every second using 10 points. It is possible to calculate the channel “dW” using the 10 points, but storing only the "time" and "dW"of the tenth point? In the picture show the example. Thanks. Link to comment Share on other sites More sharing options...
AzeoTech Posted August 20, 2012 Share Posted August 20, 2012 Sure, probably the easiest way is in the Event for the Weight channel. Create another channel called "dW", device type Test, I/O type D to A. Then in the event for your weight channel put: if (numrows(weight) > 9) dW.addValue(weight[0] - weight[9])endif[/CODE] Link to comment Share on other sites More sharing options...
hendrick Posted August 21, 2012 Author Share Posted August 21, 2012 Thanks works fine!. But I need to calculate the mass flow, defined as "dW/dtime". In my previous script set dtime=10 (10 seconds for the 10 points), as shown below: private string datainprivate datadevice.digimed.readuntil(10) // clear half framewhile(1) try datain = device.digimed.readUntil(10) data = strToDouble(mid(datain,1,1000)) weight.addValue(data) if (numrows(weight) > 9) dWdTime.addValue(insertTime(Abs(weight[0] - weight[9])/10, weight.time[0],0)) endif catch() ? strLastError delay(0.1) endcatchendwhile[/CODE]But the time is determined by the digital balance and is not exactly 10 seconds. How can I determine the time elapsed since the point [0] to [9]?.I tried to replace "10" for "Abs(weight.time[9] - weight.time[0])", but don't work.The picture shows an example of calculation.[color=#282828][font=helvetica, arial, sans-serif]Thank you for your help in advance[/font][/color][color=#282828][font=helvetica, arial, sans-serif]Hendrick[/font][/color] Link to comment Share on other sites More sharing options...
AzeoTech Posted August 22, 2012 Share Posted August 22, 2012 I tried to replace "10" for "Abs(weight.time[9] - weight.time[0])", but don't work. That actually should be correct, though the Abs() is not necessary if you flip it since [0] time is always the biggest. The line should read: dWdTime.addValue(insertTime(Abs(weight[0] - weight[9])/(weight.time[0] - weight.time[9]), weight.time[0],0)) Link to comment Share on other sites More sharing options...
hendrick Posted August 23, 2012 Author Share Posted August 23, 2012 thanks so much I'll try now! Link to comment Share on other sites More sharing options...
hendrick Posted April 23, 2015 Author Share Posted April 23, 2015 You have really helped me before and I think I need it again. My previous script work fine, but the channel “dWdTime” is calculated every second using 10 points. It is possible to calculate the channel “dWdTime” using the 10 points, but storing only the "time" and "dWdTime"of the tenth point? In the picture show the example. : --- private string datainprivate datadevice.digimed.readuntil(10) // clear half framewhile(1)try datain = device.digimed.readUntil(10) data = strToDouble(mid(datain,1,1000)) weight.addValue(data) if (numrows(weight) > 9) dWdTime.addValue(insertTime(Abs(weight[] - weight[9])/(weight.time[0] - weight.time[9]), weight.time[0],0)) endifcatch() ? strLastError delay(0.1)endcatchendwhile --- ThanksHendrick Link to comment Share on other sites More sharing options...
AzeoTech Posted April 23, 2015 Share Posted April 23, 2015 Certainly, just use a counter instead of looking at the number of rows in weight. The problem is that once you get 10 rows in weight, the if() evaluates to true every time. You want more like: private string datainprivate datadevice.digimed.readuntil(10) // clear half frame private count = 0while(1)try datain = device.digimed.readUntil(10) data = strToDouble(mid(datain,1,1000)) weight.addValue(data) count++ if (count > 9) dWdTime.addValue(insertTime(Abs(weight[] - weight[9])/(weight.time[0] - weight.time[9]), weight.time[0],0)) count = 0 endifcatch() ? strLastError delay(0.1)endcatchendwhile Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.