Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

Modbus and double Floats...


PPeters Aug 22, 2018 02:42 AM

Hi, 

I am trialling a setup where we will interogate a Krohne Flow meter via modbus rather than pulse outputs. The modbus setup should allow for us to collect flow rates as well as the accumulating total and avoid inconsistancies that we see when reading pulses only.

The issue I have is that the Krohne IFC 050 signal converter is presenting the Counter data as double float..

I cant seem to get this to show in any sensible format with either a modbus test tool (modbusmat1.1) or with a cr1000x.

My Questions are...

Has anyone had any success in reading double float registers with the modbusmaster instruction? If so what is the strategy.. 

Second then is it possible?

and finally I see on the CR1000x that the control ports can be configured with the serial open function to be RS485, so I can use this to connect the signal converter directly? (not tested yet) currently using a rs232 to 485 converter from the rs232 port on the logger

the Krhone manual is here..

http://www.manualsdir.com/manuals/368267/krohne-ifc-050-converter-modbus-en.html, p12 for the register options

any ideas much appreciated

regards

Paul


JDavis Aug 22, 2018 02:50 PM

The CR1000X does support variables declared as Double. The ModbusMaster instruction does not have direct support for the data format.

Read the value in as two variables in ABCD byte order. Then use MoveBytes to do a binary copy from those variables into a variable declared as Double. Check the manual for the device, to check if you need to change the byte order. Changing the byte order can be done by using MoveBytes multiple times, one byte at a time.

 

Public LargeNumber As Double
Public SinglePrecision(2) As Float
Public ModbusResult As Long

BeginProg
  Scan (1,Sec,0,0)
    
    ModbusMaster (ModbusResult,ComC1,9600,1,3,SinglePrecision(),1,2,3,100,2)
    MoveBytes (LargeNumber,0,SinglePrecision(),0,8)

  NextScan
EndProg

 


Curt_Ingram Aug 22, 2018 06:00 PM

Yes, with a CR1000X and a CR6 you do NOT need a RS-485 converter.  Can be done directly with C Pair.  You will need to setup the pair in DevConfig to do this.


PPeters Aug 22, 2018 08:08 PM

excellent, thx both. was looking down the path of reading them in 2 sections but the float conversion, math and modbus format was doing my head in... good to see CSI 1 step ahead again..

much appreciated for code and strategy

cheers

Paul


PPeters Aug 24, 2018 12:20 AM

Ok.. I now have a successful code working in a test environment on a CR1000x.. took some head scratching and setting changes on the Krohne but I now have it resolving the count totals correctly. working in Big Endian output from the Meter.

the CR1000x code bits are..

Public ModbusCNT(2) As Float
Public LargeNumber As Double

..

ModbusMaster (Mod_Result,ComRS232,19200,1,4,ModbusCNT(),9,2,3,100,2)


MoveBytes (LargeNumber,0,ModbusCNT(1),0,8)
MoveBytes (LargeNumber,9,ModbusCNT(2),0,8)

and get this returned for a counter total of 706.467

ModbusCNT1 4.189909

ModbusCNT2 -6.912387e+13

LargeNumber 706.467205967539

now..

I was wanting to deploy a CR300 cell 200 for this monitoring project so I am now testing the Flow meter with this platform

same code


Public ModbusCNT(2) As Float
Public MeterCount1 As Double

ModbusMaster (Mod_Result,ComRS232,19200,1,4,ModbusCNT(),9,2,3,100,2)

MoveBytes (MeterCount1,0,ModbusCNT(1),0,8)
MoveBytes (MeterCount1,9,ModbusCNT(2),0,8)

once again for the Counter total on the flow meter of 706.467 i get these numbers

ModbusCNT(1) 4.189909

ModbusCNT(2) -6.912387e+13

but now the Double foramtted number is

MeterCount1 -4.03232949058767e+108

Any ideas why this is?

the source modbus format is consistant over both the CR1000x and CR300 but looks like either the moveBytes or application of the double format is operating differently in the cr300

I havent found anything in the help files so any assistance much appreciated

regards

Paul


JDavis Aug 24, 2018 03:45 PM

The CR300 datalogger is little endian, and the CR1000X is big endian. So, on the CR300 you need to move bytes differently.


PPeters Aug 27, 2018 04:28 AM

Thanks JDavis, 

I was able to change output from the flow meter to little endian and with subtle change to the modbus request all is now gold..

much appreciated


gemmalyly Mar 31, 2023 07:47 AM

This post is under review.

Log in or register to post/reply in the forum.