Ask our Experts
Didn't find what you are looking for? Ask our experts!
A forum for topics related to the scope of Modicon PAC offers and ecosystem along the whole lifecycle: Modicon M580 and 340, EcoStruxure Control Expert, EcoStruxure Process Expert (Unity Pro) and more.
Search in
Link copied. Please paste this link to share this article on your social media post.
Posted: โ2025-09-12 03:02 AM
Hello,
I'm trying to read the values on a flow meter via Modbus TCP with a M340 CPU and a NOE card.
The hardware configuration goes like this: Flow meter -> Modbus RTU to TCP Gateway -> NOE.
When I use a Modbus TCP Client on my PC (simply Modbus), I can read the modbus register just fine.
I use the function 4 "Read Input Registers", and I'm reading for example the 30103 register.
To do this in Control Expert (License XL and V16.0 by the way), I wrote this code in the MAST task:
GEST_READVAR[2] := 50;
IF NOT GEST_READVAR[0].0 THEN
READ_VAR (ADR := ADDM('Ethernet_1{192.168.50.153}1'), OBJ := '%IW', NUM := 30103, NB := length_arint(RECP_READVAR), GEST := GEST_READVAR, RECP => RECP_READVAR);
END_IF;
reTest := WORD_AS_REAL(LOW := INT_TO_WORD(RECP_READVAR[0]), HIGH := INT_TO_WORD(RECP_READVAR[1]));
(RECP_READVAR is an ARRAY[0..1] OF INT, reTest is a REAL).
Currently, the values of lines 0 and 1 in the RECP array are both 0, but simply modbus displays other values, so something must be wrong but I don't know what.
Does anyone have an idea of what I can do to make this work?
(you can find the datasheet of the Modbus RTU module attached to the topic, with register numbers on pages 19 to 26)
Thanks a lot for the time anyone would take to look into this๐
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: โ2025-09-14 07:55 AM
Hello @SIGE_BMR
As per the above issue's description, I can guess almost sure that the issue is related to the NUM value which refers to the starting register index.
The correct value is NUM=102 which means Modbus 103 as M340/M580 are based on IEC0 but your device is based on IEC1, and the suffix 3 means the data type is Input Register which has already included in the OBJ="%IW".
You may try this and feedback me.
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: โ2025-09-14 07:55 AM
Hello @SIGE_BMR
As per the above issue's description, I can guess almost sure that the issue is related to the NUM value which refers to the starting register index.
The correct value is NUM=102 which means Modbus 103 as M340/M580 are based on IEC0 but your device is based on IEC1, and the suffix 3 means the data type is Input Register which has already included in the OBJ="%IW".
You may try this and feedback me.
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: โ2025-09-14 06:02 PM
"Modbus address 30103 actually corresponds to address 103 (0-based), so you should set NUM := 103."
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: โ2025-09-14 11:37 PM
Hello @ProfHameedi
I tried your suggestion of using 102 for the NUM parameter and it worked!
I also had other Modbus registers to read on the device, all within the 30XXX range, and everything worked by sustracting 30001 to the register value and using the result as the NUM parameter.
Thank you so much for your help ๐
Have a great day ๐ค
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: โ2025-09-15 03:51 AM
Thanks for your feedback.. It is nice to hear that.
Link copied. Please paste this link to share this article on your social media post.
Youโve reached the end of your document
Create your free account or log in to subscribe to the board - and gain access to more than 10,000+ support articles along with insights from experts and peers.