T
Let's say I have theese variables mapped to the beginning of the holding register area:
reg no
0x0000 [15.......a.....0] 16bit word
0x0001 [15.......b.....0] 16bit word
0x0002 [7..c..0][7..d..0] Array of four bytes
0x0003 [7..e..0][7..f..0]
0x0004 [31......g.....16] 32bit dword
0x0005 [15......g......0]
What I want is to make all theese variables available in the coils area as well.
Problem is, the holding register area is defined to be big endian, while the coil area is little endian by nature.
If I simply let the 12 most significant bits of the coil number represent the holding register, and the 4 least significant bits address the bits within the word, (bit 0-15), then the translation of register addresses to coil numbers becomes very easy, but the mapping would look as follows:
coil number
0x00-0x0F : word a, bit 0-15
0x10-0x1F : word b, bit 0-15
0x20-0x27 : byte d, bit 0-7
0x28-0x2F : byte c, bit 0-7
0x30-0x37 : byte f, bit 0-7
0x38-0x3F : byte e, bit 0-7
0x40-0x4F : dword g, bit 16-31
0x50-0x5F : dword g, bit 0-15
As can be seen, 16bit words are fine, but the order of arrays of bytes are byte swapped, and dwords are word-swapped. A "read coils" command reading coils 0x00-0x5F to PLC memory will however result in the same order of data in the PLC memory when compared to the equivalent "read holding registers 0x00-0x05" command. (at least on a modicon PLC).
The second alternative is to take into consideration the data types when translating coil numbers to register addresses:
coil number
0x00-0x0F : word a, bit 0-15
0x10-0x1F : word b, bit 0-15
0x20-0x27 : byte c, bit 0-7
0x28-0x2F : byte d, bit 0-7
0x30-0x37 : byte e, bit 0-7
0x38-0x3F : byte f, bit 0-7
0x40-0x4F : dword g, bit 0-15
0x50-0x5F : dword g, bit 16-31
This coil-number ordering makes a little more sense to humans, but the translation from coil-numbers to register addresses become non-linear and non-trivial to both humans and computers, and a read coils command reading coils 0x00-0x5F will result in the byte array as well as the dword beeing byte-swapped in the PLC's memory (at least on a modicon PLC).
What is the "standard" solution for mapping the register area to the coil area? Right now I'am favoring the first solution, since it is fairly logical once you tell the customers that the coil commands consider all data to be 16bit words.
Regards,
Timmy Brolin
reg no
0x0000 [15.......a.....0] 16bit word
0x0001 [15.......b.....0] 16bit word
0x0002 [7..c..0][7..d..0] Array of four bytes
0x0003 [7..e..0][7..f..0]
0x0004 [31......g.....16] 32bit dword
0x0005 [15......g......0]
What I want is to make all theese variables available in the coils area as well.
Problem is, the holding register area is defined to be big endian, while the coil area is little endian by nature.
If I simply let the 12 most significant bits of the coil number represent the holding register, and the 4 least significant bits address the bits within the word, (bit 0-15), then the translation of register addresses to coil numbers becomes very easy, but the mapping would look as follows:
coil number
0x00-0x0F : word a, bit 0-15
0x10-0x1F : word b, bit 0-15
0x20-0x27 : byte d, bit 0-7
0x28-0x2F : byte c, bit 0-7
0x30-0x37 : byte f, bit 0-7
0x38-0x3F : byte e, bit 0-7
0x40-0x4F : dword g, bit 16-31
0x50-0x5F : dword g, bit 0-15
As can be seen, 16bit words are fine, but the order of arrays of bytes are byte swapped, and dwords are word-swapped. A "read coils" command reading coils 0x00-0x5F to PLC memory will however result in the same order of data in the PLC memory when compared to the equivalent "read holding registers 0x00-0x05" command. (at least on a modicon PLC).
The second alternative is to take into consideration the data types when translating coil numbers to register addresses:
coil number
0x00-0x0F : word a, bit 0-15
0x10-0x1F : word b, bit 0-15
0x20-0x27 : byte c, bit 0-7
0x28-0x2F : byte d, bit 0-7
0x30-0x37 : byte e, bit 0-7
0x38-0x3F : byte f, bit 0-7
0x40-0x4F : dword g, bit 0-15
0x50-0x5F : dword g, bit 16-31
This coil-number ordering makes a little more sense to humans, but the translation from coil-numbers to register addresses become non-linear and non-trivial to both humans and computers, and a read coils command reading coils 0x00-0x5F will result in the byte array as well as the dword beeing byte-swapped in the PLC's memory (at least on a modicon PLC).
What is the "standard" solution for mapping the register area to the coil area? Right now I'am favoring the first solution, since it is fairly logical once you tell the customers that the coil commands consider all data to be 16bit words.
Regards,
Timmy Brolin