There aren’t any official standards (as far as I know) for how portability of 
floats works between machines with different endianness.

 

Usually however (AFAIK) they follow the same swapping rules as integers, so 
typically the best approach is to receive the possibly-wrong-endian value into 
a byte array or integer variable (never a float variable), then apply the 
conditional byte swap as if it were an integer, then reinterpret the bit 
pattern as a float (via a pointer cast, not a value cast nor union).  So the 
Etherlab macros should work fine for this purpose.  (Note that some compilers 
prefer that you perform an intermediate cast from integer to byte array then to 
float, rather than going directly from integer to float.)

 

Usually this will do the trick, assuming that the master and slave use 
compatible definitions of how floating point are represented (while rare, there 
are some processors around that don’t use IEEE floats).  The main thing is to 
never put data that might be byte-swapped into a float/double variable (not 
even temporarily), because you’ll run into trouble with special interpretation 
of particular bit patterns.

 

From: Eshwar Lal [mailto:eshwarkha...@gmail.com] 
Sent: Tuesday, 14 February 2017 06:06
To: Gavin Lambert <gavin.lamb...@compacsort.com>
Subject: Re: [etherlab-users] EtherCAT data size compatibility issue

 

Hi,

 

Thanks for your response, yes there are macros available for 64 bit read/write 
in ecrt.h.

 

one question, is it valid only for integer values or I could use them for 
floating point data types as well?

 

On Fri, Feb 10, 2017 at 12:22 AM, Gavin Lambert <gav...@compacsort.com 
<mailto:gav...@compacsort.com> > wrote:

64-bit macros are already defined in ecrt.h, so just use them.

 

In general though, if you want to deal with other data sizes, have a look at 
how the macros are defined, and define your own versions.  They’re just 
wrappers around standard conditional byte-swapping calculations.

 

Data on EtherCAT is little-endian by convention (although occasionally a slave 
will do something different), so the byte-swapping is only needed if your 
master code might run on a big-endian processor.

 

From: Eshwar Lal
Sent: Friday, 10 February 2017 02:26
To: etherlab-users@etherlab.org <mailto:etherlab-users@etherlab.org> 
Subject: [etherlab-users] EtherCAT data size compatibility issue

 

 

hello all,

 

I am using EtherCAT master with ESC FC1100 for performing HIL simulations, I am 
using ecrt.h api functions to send a receive data variables,

 

EC_READ_U32 and EC_WRITE_U32, which support only 32bit unsigned values, however 
my process variable is 64bit in size.

 

is there any possible solution to this problem? so that I can transfer the 
variables 64bit in size over etherCAT and perform calculation for my simulation 
or any other possible tip to convert the 64bit variable to 32bit just for 
transmit and receive purpose. Or a method to transfer and receive 64bit values 
over EtherCAT.

it would be great to hear a positive solution to rectify the issue.

 

Note: I am using Linux kernel with RTAI.


_______________________________________________
etherlab-users mailing list
etherlab-users@etherlab.org <mailto:etherlab-users@etherlab.org> 
http://lists.etherlab.org/mailman/listinfo/etherlab-users





 

-- 

Best Regards.
Eshwar Lal 

_______________________________________________
etherlab-users mailing list
etherlab-users@etherlab.org
http://lists.etherlab.org/mailman/listinfo/etherlab-users

Reply via email to