Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: Modbus float indian conversion

Modbus float indian conversion 1 year 3 months ago #11497

  • gcorbaz
  • gcorbaz's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 6
  • Karma: 0
Hello,

I'm new to Proview.

I'm trying to convert modbus float from big indian to small indian and vice versa. For this, I'm using a plc program with CArithm.

The idea is to get data from a Kostal Plenticore inverter. It works fine with integer, but not with float. According to the doc, data are sent in big indian as follow: abcd => cdab. I tried different ways, unfortunately without success.

plc.png

The node is defined as follow:

node.png


and the plant:

plant.png


Does anyone have already implemented such convertion ?

With kind regards, Guy.
The administrator has disabled public write access.

Modbus float indian conversion 1 year 3 months ago #11500

  • brunad
  • brunad's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 278
  • Karma: 0
Hello Guy,

Here is a sample code you can put in a CArithm object to reorder endian as you like (for a float):

union {
float f;
unsigned char b[4];
} dat1, dat2;

dat1.f = A1; // CArithm float input

dat2.b[0] = dat1.b[3]; // change order as you like
dat2.b[1] = dat1.b[2];
dat2.b[2] = dat1.b[1];
dat2.b[3] = dat1.b[0];

OA1 = dat2.f; // CArithm float output

}

/Bruno

You can use the search function to find it here:

www.proview.se/v3/index.php/forum/3-help...order-on-chanai#9933
The administrator has disabled public write access.

Modbus float indian conversion 1 year 3 months ago #11501

  • gcorbaz
  • gcorbaz's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 6
  • Karma: 0
Merci Bruno,

Cependant, j'ai encore une incompréhension: commend se passe la transformation des données entre ChanLi, du Node, et Li du Plant ?

Je lis le float Modbus avec un ChanLi UInt 32, et le lie avec un Li dans le Plant. Les valeurs semblent les mêmes.

Proview effectue-t-il des transformations de données quelquepart ?

Avec mes meilleures salutations, Guy.
The administrator has disabled public write access.

Modbus float indian conversion 1 year 3 months ago #11502

  • brunad
  • brunad's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 278
  • Karma: 0
Bonjour Guy,

Pour résumer:

Tu déclares les variables locales dans Plant


Vars.png



Tu déclares ta variable réseau de type Float32 dans Node et tu fais un lien avec la variable locale par
"Connect channel"


module.png


connect_chan.png


ana_ch2.png



Tu convertis dans un plc (api):


plcconv.png



/Bruno
Last Edit: 1 year 3 months ago by brunad.
The administrator has disabled public write access.
The following user(s) said Thank You: Allan

Modbus float indian conversion 1 year 3 months ago #11506

  • gcorbaz
  • gcorbaz's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 6
  • Karma: 0
Bonjour Bruno,

Merci pour l'aide: celà m'a mis sur la piste.

J'ai fait quelques modifications: je ne lis pas la valeur dans le noeud avec un Ai, mais avec un Li float32. Je convertit l'entier dans CArtithm d'entier vers float avec un type cast et un croisement des bytes et ça marche. Pas trivial ;-)

Avec mes meilleures salutations, Guy.
The administrator has disabled public write access.
  • Page:
  • 1
Time to create page: 1.010 seconds