JohnB315

SoMachine Basic Modbus Read_Var help

9 posts in this topic

Hi guys, I have an M221 and trying to read process data from a HACH controller via Modbus 485.

In the Read_Var function block I need to configure ObjType, FirstObj, Quantity and IndexData. Slave ID is 3 and I am using SL2.

So, say if I wanted to read to following registers,

Register #40001, Data Type Integer, Length 1, Description- Sensor Measure

Register #40005, Data Type Float, Length 2, Description - Sensor Temp

Register #40007, Data Type String, Length 6, Description - Sensor Name

what do I put into the Read_Var function ?

I am completely new to this and it's just not clear to me.

Thanks

John 

 

Share this post


Link to post
Share on other sites

@JohnB315 For easy example you could config each parameter on %READ_VAR each block as describe as follow

 

Id: Modbus Slave ID

ObjType: Type of data that you read

0 - Read 4xxxx address

1 - Read 1xxxx address

2 - Read 0xxxx address

3 - Read 3xxxx address

FirstObj: Which first register at you read (40001 means Holding Register at register 1)

Quantity: number of register that you read

IndexData: Which %MW number that you need to collect data (such as 1 means use %MW1)

 

If you have understand concept you can use one %READ_VAR block to read data from device by change FirstObj, Quantity and IndexData by use %READ_VAR0.FIRSTOBJ, %READ_VAR0.QUANTITY and %READ_VAR0.INDEXDATA

M221_Read_Var_01.jpg

M221_Read_Var_02.jpg

M221_Read_Var_03.jpg

M221_Read_Var_04.jpg

1 person likes this

Share this post


Link to post
Share on other sites

Thank you Wasan, I couldn't have asked for a better explanation.

It worked but I had to offset the address by -1 (40001 = 0, 40002 = 1 etc.) to get a response otherwise it will return an error.

Now, the next stage of my confusion, the value in the %MW I get back is random, anything from -322xx to +20000 or 30000. I was expecting something in line with the actual sensor measurement (pH), or do I need to scale it like a mA value ? If so could you please tell me the steps involved ?

Also, is there a simple way to view what value is in a %MW while I am online during testing in somachine basic?

Share this post


Link to post
Share on other sites

You use animation tables to view values online

Also it could be that the byte order is swapped around of the register you are reading. Try reading a register which has a constant small value in like date or something to do your tests

 

animation_table.JPG

1 person likes this

Share this post


Link to post
Share on other sites

Thanks cHud.

So, a little update, I have managed to figure out how to display any floating point variable. Take Register #40005, Float, Length 2, according to slave's Modbus map.

First, the ObjType is 0 - to access the 4xxxx registers like Wasan said.

Then, in my case #40005 - sensor temp. I needed to offset by -1, so FirstObj will be 4.

Quantity - the no. of %MW needed, 2 in this case, I used %MW0 and %MW1, IndexData is the starting point, %MW0

Now, I finally realised I need to look at the value of both memory locations combined, either a double or floating word, %MD or %MF

%MF0/%MD0 = %MW0 + %MW1, -----  %MF1/%MD1 = %MW1 + %MW2

%MF2/%MD2 = %MW2 + %MW3  ----  %MF3/%MD3 = %MW3 + %MW4 etc.

%MFx or %MDx = %MWx + %MW(x+1)

All I need to do is put the corresponding %MF in the animation table and boom....there's the sensor reading.

 

Following on from that, can anyone tell me what to do with  Register #40007, Data Type String, Length 6 ?

Share this post


Link to post
Share on other sites

@JohnB315 For string variable you should use Animation Table to show them by Example I have input "TEST STRING" to M0 for 10 words by use %MW0:10 = "TEST STRING" in operation box.

 

M221_String_01.thumb.jpg.d5591e412b36207

 

Then I create animation table for %MW0 to %MW10 then right click at %MW then select ASCII.

 

M221_String_02.jpg.e354abf8a2950b551aa7b

 

They will show data in ASCII string by start from right to left and for each %MW can collect 2 character.

 

M221_String_03.jpg.3d56eee458bd7318cfd5b

Share this post


Link to post
Share on other sites

hi guys

i am using my Schneider m221 plc

how modbus address write address i am trying put address but address accept only 4 digit for example i write %MW1:= 0001 like accept but i write %MW1:=10001 not accept this address what is problem can help me

Edited by sandy1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now