Digital balance communication via RS232


hendrick

Recommended Posts

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.

post-8698-0-07342000-1339705861_thumb.pn

post-8698-0-61959200-1339705878_thumb.pn

Link to comment
Share on other sites

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 datain
private data
device.myDevice.readuntil(10) // clear half frame
while(1)
try
datain = device.myDevice.readUntil(10)
data = strToDouble(mid(datain,1,1000))
weight.addValue(data)
catch()
? strLastError
delay(0.1)
endcatch
endwhile

[/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 datain
private data
device.myDevice.readuntil(10) // clear half frame
while(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)
endcatch
endwhile
[/CODE]

This also allows you to handle negative readings.

Link to comment
Share on other sites

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

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

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

post-8698-0-70928300-1340287489_thumb.pn

Link to comment
Share on other sites

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

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

post-8698-0-41786200-1340725702_thumb.pn

Link to comment
Share on other sites

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

  • 3 weeks later...

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 datain
private data
device.EP001.readuntil(61) // clear half frame
while(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)
endcatch
endwhile[/CODE]

[/size][/indent]

Work fine with low weights, but don't with large weight.

Can you help me?

Thanks.

post-8722-0-44436800-1342193872_thumb.pn

Link to comment
Share on other sites

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 datain
private data
device.EP001.readuntil(61) // clear half frame
while(1)
try
datain = device.EP001.readUntil(61)
data = strToDouble(datain)
massa.addValue(data)
catch()
? strLastError
delay(0.1)
endcatch
endwhile
[/CODE]

Link to comment
Share on other sites

  • 1 month later...

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.

post-8698-0-66773700-1345255592_thumb.pn

Link to comment
Share on other sites

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

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 datain
private data
device.digimed.readuntil(10) // clear half frame
while(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)
endcatch
endwhile
[/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]

post-8698-0-65142100-1345524062_thumb.pn

Link to comment
Share on other sites

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

  • 2 years later...

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 datain
private data
device
.digimed.readuntil(10) // clear half frame
while(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))
     endif
catch()
     ? strLastError
     delay
(0.1)
endcatch
endwhile

 

---

 

Thanks

Hendrick

 

post-8698-0-99275000-1429749322_thumb.jp

Link to comment
Share on other sites

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 datain
private data
device
.digimed.readuntil(10) // clear half frame

private count = 0
while(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
     endif
catch()
     ? strLastError
     delay
(0.1)
endcatch
endwhile

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.