Help getting Chinese Gas Analyzer (RS232) to communicate with DF Base


dmdodd

Recommended Posts

Azeotech

We recently bought a gas analyzer that gives gas compositions via RS232. The manufacturer is located in China and it is difficult to correspond with them (the time difference mainly, but also their lack of instructions/manuals/tech support and English etc).

They supplied a small *.exe program that will communicate via RS232 with the device, display the readings in a on-screen panel meter and also save the readings to a *.txt file which is useful. But we need to be able to use the readings for process control algorithms, hence I want it to integrate with DAQFactory.

I asked the manufacturer many days ago for instructions and they only just sent me the difficult-to-understand document attached to this post.

I followed the "DAQFactory: Serial Communications guide", but it was no-use without their Baud rate, other settings and communications protocol. They've now sent that to me but I'm still confused (and I certainly can't work in hexadecimal!)

Please scan the attached document and see if any of it makes sense.

commnucation_protocol__coal_gas_6gases_.pdf

Thanks in advance, :D

Daniel

Link to comment
Share on other sites

That doc is actually pretty specific. Assuming it is actually correct, this code should do it. You might have to use to.word instead of to.rword depending on the byte ordering. I've shown an example of adding it to one H2 channel, and then used just ? statements so you can immediate see the results in the command/alert window to see if its working (and possible change the byte ordering by using to.word). You may need some scaling too (like I did with H2). Its not completely clear in the docs. When you are ready, just create Test A/D channels with Timing = 0 for each desired value, then create a corresponding AddValue() line like I did for H2 to shove the reading into the channel.

private string stin
private in
while(1)
   try
	  device.gas.Purge()
	  device.gas.Write(chra({0x11, 0x01, 0x01, 0xed}))
	  stin = device.gas.Read(20)
	  in = asca(stin)

	  H2.addvalue(to.rWord(in[11,12])/100)

	  ? "CO2: " + to.rWord(in[3,4])
	  ? "CH4: " + to.rWord(in[5,6])
	  ? "CnHm: " + to.rWord(in[7,8])
	  ? "CO: " + to.rWord(in[9,10])
	  ? "H2: " + to.rWord(in[11,12])
	  ? "O2: " + to.rWord(in[13,14])
	  ? "HHV: " + to.rWord(in[15,16])
	  ? ""
   catch()
	  ? strLastError	  
   endcatch
   delay(1)
endwhile

Link to comment
Share on other sites

Excellent! It worked perfectly with to.rword. Indeed it was wierd, the gas channels I needed to divide by 100 and the HHV (BTU/scf) only by 10... perhaps it's because gas compositions will only be less that 100%, where as HHV can get over 1000 BTU/scf, hence they wanted to keep everything in the same Hex range? (again, not a Hex guy, but might make sense).

The only thing now...

The gas analyzer can give negative readings from the unit (due to calibration settings stored in its memory). Is there anyway to condition the RS232 with boolean in the addvalue line, something like (so if the value was negative, it merely sends "0" to the H2 channel):

H2.addvalue(to.rWord(in[11,12])/100*((to.rWord(in[11,12])/100) >= 0))

(I'm trying to use as few channels as possible, so would prefer to do this processing on the raw incoming stream, rather than with an additional channel with boolean in its conversion)

Thanks in advance,

Daniel

Link to comment
Share on other sites

Yes, that would work, though there are some shortcuts you can take:

1) you don't need to /100 in the second part since it has no affect on the sign of the result

2) technically you can simply look and see if the high order bit of the in[11] is set to find out if its negative. That can be done just by seeing if its > 127. (this is standard integer format stuff, not DF specific)

So the expression can be reduced to:

H2.addValue(to.rword(in[11,12])/100*(in[11]<128))

or use the inline iif function:

H2.addValue(iif(in[11]<128, to.rword(in[11,12]/100), 0)

iif() is better especially if you want to put something other than 0 in there when its negative

Link to comment
Share on other sites

Archived

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