Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched.
Close
good morning,
I have an arduino that runs a sct013 probe,
Its output value is of the float type.
How should I write it in the modbus register and then read the comma value in codesys?
Thanks, Alberto
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2018-05-25
Originally created by: Viacheslav Mezentsev
Arduino:
/** * Modbus slave example 1: * The purpose of this example is to link a data array * from the Arduino to an external device. * * Recommended Modbus Master: QModbus * http://qmodbus.sourceforge.net/ */\#include<ModbusRtu.h>// data array for modbus network sharinguint16_tau16data[16]={3,1415,9265,4,2,7182,28182,8,0,0,0,0,0,0,1,-1};/** * Modbus object declaration * u8id : node id = 0 for master, = 1..247 for slave * u8serno : serial port (use 0 for Serial) * u8txenpin : 0 for RS-232 and USB-FTDI * or any pin number > 1 for RS-485 */Modbusslave(1,0,0);// this is slave @1 and RS-232 or USB-FTDItypedefunion{struct{uint16_thi;uint16_tlo;}regs;floatvalue;}Data;Datadata;voidsetup(){slave.begin(19200);// baud-rate at 19200data.value=1.0f;au16data[0]=data.regs.hi;au16data[1]=data.regs.lo;}voidloop(){slave.poll(au16data,16);}
Thanks Viacheslav,
I've understood the Arduino part and applied it to my sketch and it seems to work.
In fact, from the modbus monitor I see the two bytes assigned.
The part in codesys is not clear to me, it's out of my reach.
You could eliminate the superfluous?
I use modbus tcp
Thanks, Alberto
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
good morning,
I have an arduino that runs a sct013 probe,
Its output value is of the float type.
How should I write it in the modbus register and then read the comma value in codesys?
Thanks, Alberto
Originally created by: Viacheslav Mezentsev
Arduino:
Codesys 3.5.12.20:
Raspberry.ReadHoldRegsSyncTest.ST.zip [58.72 KiB]
Thanks Viacheslav,
I've understood the Arduino part and applied it to my sketch and it seems to work.
In fact, from the modbus monitor I see the two bytes assigned.
The part in codesys is not clear to me, it's out of my reach.
You could eliminate the superfluous?
I use modbus tcp
Thanks, Alberto