Difference between revisions of "DIN Rail BUS Protocol"

From InCircuit
Jump to: navigation, search
(Request for current Status on a DIN Rail Relais 6I6S: colored example)
 
(57 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Under construction}}
+
== Railbus Protocol (standard ASCII format)==
 
+
== Railbus Protocol ==
+
  
 
The Railbus Protocol is designed to be as flexible as possible while being
 
The Railbus Protocol is designed to be as flexible as possible while being
 
as easy as possible.
 
as easy as possible.
  
All data is transmitted on the RS485 with a baudrate of 9600Baud; 8N1 as
+
All data is transmitted on the RS485 with a baudrate of 9600:8N1 as
 
printable ASCII characters. Any data is converted into the corresponding
 
printable ASCII characters. Any data is converted into the corresponding
hexadecimal notation.
+
hexadecimal notation.<br/>
 +
For convenient manual interaction Railbus devices append CRNL to responses.<br/>
 +
This behavior can be controled via the system registers starting at 250 (0xFA).
 +
<!--CR and LF characters are ignored (no ENTER at end of line needed).-->
  
 
=== Packet Layout ===
 
=== Packet Layout ===
Line 16: Line 17:
 
{| class="wikitable" style="text-align:center; "
 
{| class="wikitable" style="text-align:center; "
 
|-
 
|-
!style="width: 3em"| MW  
+
!style="width: 3em"| MW
 
!style="width: 4em"| ADDR
 
!style="width: 4em"| ADDR
!style="width: 3em"| CM  
+
!style="width: 3em"| CM
 
!style="width: 4em"| SADR
 
!style="width: 4em"| SADR
!style="width: 10em"| DATA  
+
!style="width: 10em"| DATA
 
!style="width: 4em"| CHKS
 
!style="width: 4em"| CHKS
!style="width: 4em"| CRNL
 
 
|}
 
|}
  
 +
==== MW - Magic word ====
  
=== MW - Magic word ===
+
The magic word is prepended to every packet and always consists of the
 +
two characters 'R' and 'P'. These characters never occour on the bus under normal conditions.
  
The Magic word is prepended to every package and always consists of the two characters '''<nowiki>'R'</nowiki>''' and '''<nowiki>'P'</nowiki>'''.
+
==== ADDR - Modul address as HEX====
  
=== ADDR - Modul address ===
+
Each modul on the bus has a address. In its delivery-state, a modules
 +
address is set to 0. On modules equipped with a BCD-Display, the modules
 +
address is shown there.
 +
The modul address is one byte long and is transmitted as two characters.
  
Each Modul on the bus has a unique address. If a Modul is in its delivery-state, it is set to address 0. On Modules which are equipped with
+
Example: "0A" for the module address 10(decimal), the Modules BCD-Display will show "0A"
a BCD-Display, the modules address is shown here.
+
  
In every packet the address of the requested board is transmitted. This means while in Request-packets the address of the destination,
+
==== CM - command ====
in acknowledge packets the address of the source is transmitted.
+
  
The module address is one byte long; it is transmitted as two characters.
+
The command consists of one byte, either an 'R', 'W', 'S', 'K', 'I' or 'N'.
 +
The value is not converted to hexadecimal notation. These command
 +
characters are not valid hexadecimal digits and therefore can not show
 +
up in the rest of the packet.
  
=== CM - command ===
+
The different characters define the type of the packet, as shown in the
 
+
the command consists of one byte, either an '''<nowiki>'R'</nowiki>''', '''<nowiki>'W'</nowiki>''', '''<nowiki>'K'</nowiki>''', '''<nowiki>'I'</nowiki>''' or '''<nowiki>'N'</nowiki>'''.
+
The value is not converted to hexadecimal notation. Any possible character
+
is not possible to show up in the rest of the package.  This way, a
+
definitive start of packet is generated.
+
 
+
The different Words define the mode of the package, as shown in the
+
 
following table:
 
following table:
 
  
 
{| class="wikitable" style="text-align:left; "
 
{| class="wikitable" style="text-align:left; "
 
|-
 
|-
 
!style="width: 4em"| '''<nowiki>'R'</nowiki>'''
 
!style="width: 4em"| '''<nowiki>'R'</nowiki>'''
|style="width: 48em"| Read Request. Asks the addressed device to send its register-content.
+
|style="width: 48em"| Read Request. Asks the addressed device to send the register-content.
 
|-
 
|-
 
!style="width: 4em"| '''<nowiki>'W'</nowiki>'''
 
!style="width: 4em"| '''<nowiki>'W'</nowiki>'''
|style="width: 48em"| Write Request. Asks the addressed device to write the data into its register.
+
|style="width: 48em"| Write Request. Asks the addressed device to write the data into the register
 +
|-
 +
!style="width: 4em"| '''<nowiki>'S'</nowiki>'''
 +
|style="width: 48em"| Sync. Is ACKed by 'n' and used to reset write queue
 
|-
 
|-
 
!style="width: 4em"| '''<nowiki>'K'</nowiki>'''
 
!style="width: 4em"| '''<nowiki>'K'</nowiki>'''
|style="width: 48em"| Read Acknowledge. Acknowledges a preceding Read Requests and transmits the corresponding data.
+
|style="width: 48em"| Read Acknowledge. Acknowledges a preceeding Read Request and transmits the corresponding data
 
|-
 
|-
 
!style="width: 4em"| '''<nowiki>'I'</nowiki>'''
 
!style="width: 4em"| '''<nowiki>'I'</nowiki>'''
|style="width: 48em"| Write Acknowledge. Acknowledges a preceding Write Request and the transferred data to be written.
+
|style="width: 48em"| Write Acknowledge. Acknowledges a preceeding Write Request and contains the new register content.
 
|-
 
|-
 
!style="width: 4em"| '''<nowiki>'N'</nowiki>'''
 
!style="width: 4em"| '''<nowiki>'N'</nowiki>'''
|style="width: 48em"|  Not Acknowledge. Is sent, if a read or write-request to an unknown or forbidden register was made.
+
|style="width: 48em"|  Not Acknowledge. Is sent, if a read or write-request to an unknown register was made.
 +
|-
 +
!style="width: 4em"| '''<nowiki>'n'</nowiki>'''
 +
|style="width: 48em"| Special nACK. Positive or negative ackknowledge of received requests. The data field contains further information of the reason and type
 
|}
 
|}
  
 +
==== SADR - Sub address or register address ====
  
=== SADR - Sub address or register address ===
+
The sub-address field selects the internal register choosed to be read or written.
 +
The sub-addresses 0 to 249 are interpreted device specific.Every module type has its own set of
 +
supported sub-addresses.
  
The Sub address is interpreted device specific. Only the Sub-address 255
+
Registers 250 to 255 are "special" sub addresses for common issues. Not all registers are used on every device. Refer to the devices datasheet.<br/>
is defined by the stack and used for identifying a device and set a
+
The sub-address 255(0xFF) is used for identifying a device (read command) and setting the module address (write command).<br/>
Modul address.
+
The sub-address 254(0xFE) is used for communication settings like CRNL append.<br/>
 +
The sub-address 253(0xFD) is used to set the baudrate the device uses.<br/>
 +
The sub-address 250(0xFA) is used to put the device in delivery state. All properties except the railbus settings are reset.
  
Every address can be read and written. Not implemented addresses should
+
Write requests to read only registers are NACKed by a special nACK with
respond by an Not Acknowledge.
+
status code "Forbidden", so are read requests to write only registers.
 
+
Not implemented addresses are responded by an Not Acknowledge.
=== SADR255 - Module identification ===
+
  
 +
===== SADR 255 (0xFF) - Modul identification =====
 
Layout :
 
Layout :
 
 
{| class="wikitable" style="text-align:left; "
 
{| class="wikitable" style="text-align:left; "
 
|-
 
|-
!style="width: 10em"| 31 - 8  
+
!style="width: 10em"| 31 - 8
 
!style="width: 10em"| 7 - 0
 
!style="width: 10em"| 7 - 0
 
!style="width: 2em"|
 
!style="width: 2em"|
Line 94: Line 102:
 
|-
 
|-
 
|style="width: 10em"| ==============
 
|style="width: 10em"| ==============
|style="width: 10em"|  
+
|style="width: 10em"|
 
|style="width: 2em"| W
 
|style="width: 2em"| W
 
|-
 
|-
 
|}
 
|}
  
Reading the register will transmit the devices ID and its current address.
+
Reading the register will transmit the Devices ID and its current address.
On writing the address the 24 higher bits are set and only the address will
+
On writing the address the 24 higher bits are ignored and only the address will
be set to a new value.
+
be set to a new value. The corresponding ACK will use the old address but new
 +
commands are only accepted on the new one.
  
The IDs can be like "R66" for the Din Rail Relais 6I6S.
+
The IDs can be like "R66" for the Din Rail Relais 6I6S. Refer to the devices datasheet for specific information.
  
=== DATA - the register data ===
+
===== SADR 254 (0xFE) - Communication Settings =====
 +
Layout:
 +
{| class="wikitable" style="text-align:left; "
 +
|-
 +
!style="width: 4em"| 31
 +
!style="width: 4em"| 30
 +
!style="width: 20em| 29-0
 +
|-
 +
| noCRNL
 +
| noACKS
 +
| notUsed
 +
|-
 +
|}
 +
 
 +
This register is set to zero during device reset or power on.
 +
 
 +
If bit '''noCRNL''' is set the device suppresses appending of CRNL to packets.<br/>
 +
If bit '''noACKs''' is set the device suppresses responses to succesful write commands.<br/>
 +
 
 +
===== SADR 253 (0xFD) - Baud Rate =====
 +
This register is set to the default baudrate of 9600 (0x2580) on power on or device reset.<br/>
 +
Setting the baudrate to zero forces use of the default railbus baudrate of 9600 (0x2580).<br/>
 +
The success response to a change in baudrate is transmitted using the new value.<br/>
 +
Most of our devices support the higher speed baudrate of 57600 (0xE100), some even higher ones. Consult the devices datasheet for specific information.<br/>
 +
Trying to set an unsupported baudrate is NACKed with the special nACK 0x09 (invalid Data).
 +
 
 +
===== SADR 250 (0xFA) - Factory Reset =====
 +
Write the value 0x1F2E3D4C to this register to put the device back into delivery state.<br/>
 +
All properties except the railbus settings (SADR 250-255) are reset.
 +
 
 +
==== DATA - the register data and (N)ACK types ====
 +
 
 +
In the 'K', 'I' and 'W' modes this field consists of 32bit hexadecimal notated
 +
data representing the register content and is transmitted in eight characters.
 +
In the 'n' Mode this field contains information about the type or reason for the (N)ACK.
 +
 
 +
==== CHK - Checksum ====
 +
 
 +
The checksum consists of one byte of data, transmitted as two hexadecimal
 +
notated characters.
 +
If the MSB is set, the checksumming is enabled, using CRC7 on all of the preceeding
 +
data.
 +
If the MSB isnt set, checksum is ignored.
 +
 
 +
=== Usage ===
  
This field is only transmitted in the '''<nowiki>'K'</nowiki>''' and '''<nowiki>'W'</nowiki>''' modes. It consists of
+
A write should be repeated as long as no corresponding (N)ACK is received.
32bit hexadecimal notated data and is transmitted in eight characters.
+
Devices should execute each Write command only once but deliver an Special ACK for each received copy.
 +
The special sync command counts as a write command and as such breaks this loop.
 +
If currently a command is processed and therefore the queue couldn't be cleared, the Sync is NACKed.
  
=== CHK - Checksum ===
+
Only one write can be executed at once.
 +
Reads can be executed any time.
  
The Checksum consists of one byte of data, transmitted as two hexadecimal notated characters.
+
=== Special ACKs 'n' ===
If the MSB is set, the checksumming is enabled, using CRC7 on all of the preceeding data.
+
*DATA: 0x01  - ACK Received. The command was received and will be executed.
If the MSB is not set, checksumming is disabled.
+
*DATA: 0x02  - ACK Retransmission. The command was received is currently executed.
 +
*DATA: 0x03  - ACK Done before. The command was already received and finished.
 +
*DATA: 0x06  - NACK Unknown. Unknown Register.
 +
*DATA: 0x07  - NACK Forbidden. Read on Writeonly Register or Write on Readonly one.
 +
*DATA: 0x08  - NACK Busy. Write received but already executing command.
 +
*DATA: 0x09  - NACK Invalid. Command could not be executed. Invalid Data.
 +
*DATA: 0x0A  - NACK Error. Command aborted.
 +
*DATA: 0x0B  - NACK Abort before. Command was already aborted in the past.
 +
*DATA: 0x10  - ACK Synced. The Sync was succesfully completed.
  
 
== Railbus Protocol binary extension ==
 
== Railbus Protocol binary extension ==
  
the binary extension to the railbus protocol is for automated transmissions of data only.
+
the binary extension to the railbus protocol is for automated transmissions of data
 +
only.
  
 
=== Packet Layout ===
 
=== Packet Layout ===
Line 127: Line 192:
 
{| class="wikitable" style="text-align:center; "
 
{| class="wikitable" style="text-align:center; "
 
|-
 
|-
!style="width: 3em"| MW  
+
!style="width: 3em"| MW
 
!style="width: 4em"| ADDR
 
!style="width: 4em"| ADDR
!style="width: 3em"| CM  
+
!style="width: 3em"| CM
 
!style="width: 5em"| LENGTH
 
!style="width: 5em"| LENGTH
 
!style="width: 4em"| SRCA
 
!style="width: 4em"| SRCA
 
!style="width: 2em"| SE
 
!style="width: 2em"| SE
!style="width: 10em"| DATA  
+
!style="width: 10em"| DATA
 
!style="width: 4em"| CHK
 
!style="width: 4em"| CHK
 
|}
 
|}
  
=== MW, ADDR and CHK ===
+
==== MW, ADDR ====
  
the Magic Word, the destination address and the checksum are encoded like in the railbus protocol.
+
the Magic Word and the destination address are encoded like in the
 +
standard ASCII railbus protocol.
  
=== CM - Command ===
+
==== CM - Command ====
  
 
The command for the binary extension always has the highest bit set
 
The command for the binary extension always has the highest bit set
Line 149: Line 215:
 
as one character.
 
as one character.
  
=== LENGTH - packet length ===
+
==== LENGTH - packet length ====
  
The length field specifies the number of character transmitted for the
+
The Length field specifies the number of character transmitted for the
complete packet. It is a 16bit integer transmitted in 4 hex-coded characters.
+
complete packet. It is a 16bit integer transmitted in 4 hex-coded
 +
characters.
  
=== SRCA - source address ===
+
==== SRCA - source address ====
  
 
The source address is defined as the address of the sender. Like the
 
The source address is defined as the address of the sender. Like the
ADDR-field it is transmitted in two characters.
+
ADDR-field is is transmitted in two characters.
  
=== SE - sequence number ===
+
==== SE - sequence number ====
  
 
An ongoing sequence number. Every packet in an ongoing stream has this
 
An ongoing sequence number. Every packet in an ongoing stream has this
Line 165: Line 232:
 
The number of the first packet in a stream should be used on a random
 
The number of the first packet in a stream should be used on a random
 
base.
 
base.
 +
 
The sequence number is represented as a 8bit integer, transmitted unencoded
 
The sequence number is represented as a 8bit integer, transmitted unencoded
 
in one character.
 
in one character.
  
=== DATA - variable length data ===
+
==== DATA - variable length data ====
  
 
the rest of the packet consists of unencoded databytes.
 
the rest of the packet consists of unencoded databytes.
  
== Examples ==
 
  
=== Request for current Status on a [[DIN Rail Relais 6I6S]] ===
+
==== CHK - variable length data ====
 +
 
 +
the checksum is encoded and calculated as in the
 +
standard ASCII railbus protocol.
 +
 
 +
= Examples =
 +
 
 +
=== Example 1: Request for current Status on a [[DIN Rail Relais 6I6S]] ===
  
 
For reading the current status on a Relais 6I6S, the first line of the following listing should be send; the board will answer
 
For reading the current status on a Relais 6I6S, the first line of the following listing should be send; the board will answer
Line 183: Line 257:
  
 
# Every packet starts with the <font color="red">magic characters</font> ''R'' and ''P''.
 
# Every packet starts with the <font color="red">magic characters</font> ''R'' and ''P''.
# The next two characters contain the hexadecimal encoded <font color="green">address</font> of the board. In this case, the board listens at the address 0xFF (or 255 in decimal notation).
+
# The next two characters contain the hexadecimal encoded <font color="green">address</font> of the board. In this case, the board listens at the address 0xFF (or 255 in decimal notation).  
 +
 
 +
''Note: The module address 255 is the default address after factory reset!''
 
# Following the address, the <font color="blue">command</font> is transmitted
 
# Following the address, the <font color="blue">command</font> is transmitted
 
#* In case of the Read Request, an <font color="blue">''R''</font> is transmitted
 
#* In case of the Read Request, an <font color="blue">''R''</font> is transmitted
Line 192: Line 268:
 
#* In the forth Byte, representing bit 7-0 of the register, the state of the outputs is shown. Here REL2, REL4 and REL6 are on.
 
#* In the forth Byte, representing bit 7-0 of the register, the state of the outputs is shown. Here REL2, REL4 and REL6 are on.
 
# The last two characters contain the <font color="cyan">checksum</font>. In this case, the dummy-checksum '00' is used. This means no validity checking is performed.
 
# The last two characters contain the <font color="cyan">checksum</font>. In this case, the dummy-checksum '00' is used. This means no validity checking is performed.
 +
 +
=== Example 2: Write to [[DIN Rail Relais 6I6S]] at module address 0x93, set Relays to 0x10 (only relais #4 on, all other are off) ===
 +
 +
  '''<font color="red">RP</font><font color="green">93</font><font color="blue">W</font><font color="magenta">'''00'''</font><font color="coral">00000010</font><font color="cyan">00</font>'''
 +
  '''<font color="red">RP</font><font color="green">93</font><font color="blue">I</font><font color="magenta">'''00'''</font><font color="coral">00000010</font><font color="cyan">00</font>'''
 +
 +
# The <font color="magenta">SADR</font> 0 is accessed.
 +
# 8 characters forming 4 Bytes of <font color="coral">data</font> are transmitted.
 +
# The module answers with a Write-Acknowledge '<font color="blue">I</font>'
 +
 +
=== Example 3: same as Example 2 but store the value to internal EEPROM too ===
 +
 +
  <font color="red">RP</font><font color="green">93</font><font color="blue">W</font><font color="magenta">'''01'''</font><font color="coral">00000010</font><font color="cyan">00</font>
 +
  <font color="red">RP</font><font color="green">93</font><font color="blue">I</font><font color="magenta">'''01'''</font><font color="coral">00000010</font><font color="cyan">00</font>
 +
 +
The <font color="magenta">SADR</font> 1 is accessed. The content is written into internal EEPROM too and then restored after reset or power-loss!
 +
See Ralais 6I6S documentation for details!
 +
 +
=== Example 4: Set the baudrate to 57600 ===
 +
 +
  <font color="red">RP</font><font color="green">93</font><font color="blue">W</font><font color="magenta">'''FD'''</font><font color="coral">0000E100</font><font color="cyan">00</font>
 +
 +
The <font color="magenta">SADR</font> 253 is accessed and the value for the baudrate set to 0xE100 which equals 57600 b/s.<br/>
 +
The ACK to this command is issued using the new setting and might not be visible in the terminal application.
 +
 +
If the baudrate is not supported on this device it answers with the special nACK 0x09 (Data invalid):
 +
 +
  <font color="red">RP</font><font color="green">93</font><font color="blue">n</font><font color="magenta">'''FD'''</font><font color="coral">00000009</font><font color="cyan">00</font>
  
 
=== Adding a valid checksum ===
 
=== Adding a valid checksum ===
Line 223: Line 327:
 
}
 
}
 
</pre>
 
</pre>
 +
 +
== Changelog ==
 +
 +
=== v2.2 ===
 +
*specified baudRate settings
 +
 +
=== v2.1 ===
 +
*Reserved Register 0xFE for Communication Settings
 +
 +
=== v2.0 ===
 +
*added Packet Type 'S' (Sync)
 +
*added Packet Type 'n' (N)ACK with reason
 +
*Section 'Usage'
 +
 +
=== v1.0 ===
 +
*initial release
  
  
 
[[Category:DIN Rail Modules]]
 
[[Category:DIN Rail Modules]]
 
[[Category:HowTo]]
 
[[Category:HowTo]]

Latest revision as of 12:02, 28 March 2017

Contents

[edit] Railbus Protocol (standard ASCII format)

The Railbus Protocol is designed to be as flexible as possible while being as easy as possible.

All data is transmitted on the RS485 with a baudrate of 9600:8N1 as printable ASCII characters. Any data is converted into the corresponding hexadecimal notation.
For convenient manual interaction Railbus devices append CRNL to responses.
This behavior can be controled via the system registers starting at 250 (0xFA).

[edit] Packet Layout

Every packet has a fixed length and is created as defined here:

MW ADDR CM SADR DATA CHKS

[edit] MW - Magic word

The magic word is prepended to every packet and always consists of the two characters 'R' and 'P'. These characters never occour on the bus under normal conditions.

[edit] ADDR - Modul address as HEX

Each modul on the bus has a address. In its delivery-state, a modules address is set to 0. On modules equipped with a BCD-Display, the modules address is shown there. The modul address is one byte long and is transmitted as two characters.

Example: "0A" for the module address 10(decimal), the Modules BCD-Display will show "0A"

[edit] CM - command

The command consists of one byte, either an 'R', 'W', 'S', 'K', 'I' or 'N'. The value is not converted to hexadecimal notation. These command characters are not valid hexadecimal digits and therefore can not show up in the rest of the packet.

The different characters define the type of the packet, as shown in the following table:

'R' Read Request. Asks the addressed device to send the register-content.
'W' Write Request. Asks the addressed device to write the data into the register
'S' Sync. Is ACKed by 'n' and used to reset write queue
'K' Read Acknowledge. Acknowledges a preceeding Read Request and transmits the corresponding data
'I' Write Acknowledge. Acknowledges a preceeding Write Request and contains the new register content.
'N' Not Acknowledge. Is sent, if a read or write-request to an unknown register was made.
'n' Special nACK. Positive or negative ackknowledge of received requests. The data field contains further information of the reason and type

[edit] SADR - Sub address or register address

The sub-address field selects the internal register choosed to be read or written. The sub-addresses 0 to 249 are interpreted device specific.Every module type has its own set of supported sub-addresses.

Registers 250 to 255 are "special" sub addresses for common issues. Not all registers are used on every device. Refer to the devices datasheet.
The sub-address 255(0xFF) is used for identifying a device (read command) and setting the module address (write command).
The sub-address 254(0xFE) is used for communication settings like CRNL append.
The sub-address 253(0xFD) is used to set the baudrate the device uses.
The sub-address 250(0xFA) is used to put the device in delivery state. All properties except the railbus settings are reset.

Write requests to read only registers are NACKed by a special nACK with status code "Forbidden", so are read requests to write only registers. Not implemented addresses are responded by an Not Acknowledge.

[edit] SADR 255 (0xFF) - Modul identification

Layout :

31 - 8 7 - 0
ID ADDR R
============== W

Reading the register will transmit the Devices ID and its current address. On writing the address the 24 higher bits are ignored and only the address will be set to a new value. The corresponding ACK will use the old address but new commands are only accepted on the new one.

The IDs can be like "R66" for the Din Rail Relais 6I6S. Refer to the devices datasheet for specific information.

[edit] SADR 254 (0xFE) - Communication Settings

Layout:

31 30 29-0
noCRNL noACKS notUsed

This register is set to zero during device reset or power on.

If bit noCRNL is set the device suppresses appending of CRNL to packets.
If bit noACKs is set the device suppresses responses to succesful write commands.

[edit] SADR 253 (0xFD) - Baud Rate

This register is set to the default baudrate of 9600 (0x2580) on power on or device reset.
Setting the baudrate to zero forces use of the default railbus baudrate of 9600 (0x2580).
The success response to a change in baudrate is transmitted using the new value.
Most of our devices support the higher speed baudrate of 57600 (0xE100), some even higher ones. Consult the devices datasheet for specific information.
Trying to set an unsupported baudrate is NACKed with the special nACK 0x09 (invalid Data).

[edit] SADR 250 (0xFA) - Factory Reset

Write the value 0x1F2E3D4C to this register to put the device back into delivery state.
All properties except the railbus settings (SADR 250-255) are reset.

[edit] DATA - the register data and (N)ACK types

In the 'K', 'I' and 'W' modes this field consists of 32bit hexadecimal notated data representing the register content and is transmitted in eight characters. In the 'n' Mode this field contains information about the type or reason for the (N)ACK.

[edit] CHK - Checksum

The checksum consists of one byte of data, transmitted as two hexadecimal notated characters. If the MSB is set, the checksumming is enabled, using CRC7 on all of the preceeding data. If the MSB isnt set, checksum is ignored.

[edit] Usage

A write should be repeated as long as no corresponding (N)ACK is received. Devices should execute each Write command only once but deliver an Special ACK for each received copy. The special sync command counts as a write command and as such breaks this loop. If currently a command is processed and therefore the queue couldn't be cleared, the Sync is NACKed.

Only one write can be executed at once. Reads can be executed any time.

[edit] Special ACKs 'n'

  • DATA: 0x01 - ACK Received. The command was received and will be executed.
  • DATA: 0x02 - ACK Retransmission. The command was received is currently executed.
  • DATA: 0x03 - ACK Done before. The command was already received and finished.
  • DATA: 0x06 - NACK Unknown. Unknown Register.
  • DATA: 0x07 - NACK Forbidden. Read on Writeonly Register or Write on Readonly one.
  • DATA: 0x08 - NACK Busy. Write received but already executing command.
  • DATA: 0x09 - NACK Invalid. Command could not be executed. Invalid Data.
  • DATA: 0x0A - NACK Error. Command aborted.
  • DATA: 0x0B - NACK Abort before. Command was already aborted in the past.
  • DATA: 0x10 - ACK Synced. The Sync was succesfully completed.

[edit] Railbus Protocol binary extension

the binary extension to the railbus protocol is for automated transmissions of data only.

[edit] Packet Layout

Packets using the binary extension do have a variable length and have the following layout:

MW ADDR CM LENGTH SRCA SE DATA CHK

[edit] MW, ADDR

the Magic Word and the destination address are encoded like in the standard ASCII railbus protocol.

[edit] CM - Command

The command for the binary extension always has the highest bit set to flag the variable packet length.

The defined commands are implementation specific. The command is transmitted as one character.

[edit] LENGTH - packet length

The Length field specifies the number of character transmitted for the complete packet. It is a 16bit integer transmitted in 4 hex-coded characters.

[edit] SRCA - source address

The source address is defined as the address of the sender. Like the ADDR-field is is transmitted in two characters.

[edit] SE - sequence number

An ongoing sequence number. Every packet in an ongoing stream has this field incremented to provide a unique packet identification. The number of the first packet in a stream should be used on a random base.

The sequence number is represented as a 8bit integer, transmitted unencoded in one character.

[edit] DATA - variable length data

the rest of the packet consists of unencoded databytes.


[edit] CHK - variable length data

the checksum is encoded and calculated as in the standard ASCII railbus protocol.

[edit] Examples

[edit] Example 1: Request for current Status on a DIN Rail Relais 6I6S

For reading the current status on a Relais 6I6S, the first line of the following listing should be send; the board will answer with the second line.

 RPFFR0000
 RPFFK000015002A00
  1. Every packet starts with the magic characters R and P.
  2. The next two characters contain the hexadecimal encoded address of the board. In this case, the board listens at the address 0xFF (or 255 in decimal notation).

Note: The module address 255 is the default address after factory reset!

  1. Following the address, the command is transmitted
    • In case of the Read Request, an R is transmitted
    • In case of the Read Acknowledge - the answer of the board - an K is transmitted
  2. Next the SADR is put on the line. In this example the register 0 is accessed.
  3. Only in the Read Acknowledge, 8 characters forming 4 Bytes of data are transmitted. In this case the state of the inputs and outputs is transmitted.
    • In the second Byte of the data, representing bit 23-16 of the register, the state of the inputs is shown. Here DIGIN1, DIGIN3 and DIGIN5 have a voltage detected.
    • In the forth Byte, representing bit 7-0 of the register, the state of the outputs is shown. Here REL2, REL4 and REL6 are on.
  4. The last two characters contain the checksum. In this case, the dummy-checksum '00' is used. This means no validity checking is performed.

[edit] Example 2: Write to DIN Rail Relais 6I6S at module address 0x93, set Relays to 0x10 (only relais #4 on, all other are off)

 RP93W000000001000
 RP93I000000001000
  1. The SADR 0 is accessed.
  2. 8 characters forming 4 Bytes of data are transmitted.
  3. The module answers with a Write-Acknowledge 'I'

[edit] Example 3: same as Example 2 but store the value to internal EEPROM too

 RP93W010000001000
 RP93I010000001000

The SADR 1 is accessed. The content is written into internal EEPROM too and then restored after reset or power-loss! See Ralais 6I6S documentation for details!

[edit] Example 4: Set the baudrate to 57600

 RP93WFD0000E10000

The SADR 253 is accessed and the value for the baudrate set to 0xE100 which equals 57600 b/s.
The ACK to this command is issued using the new setting and might not be visible in the terminal application.

If the baudrate is not supported on this device it answers with the special nACK 0x09 (Data invalid):

 RP93nFD0000000900

[edit] Adding a valid checksum

The checksum is calculated as CRC7, like used in communication in MMC or SD-Cards. The theory is described in Wikipedia:Cyclic redundancy check. This CRC7 is or'ed with a 0x80, to have the highest bit set and enable the checksum-checking.

To calculate the checksum, the function crc7_calc in the following code can be used:

const unsigned char crc7_table[16] = {
	0x00, 0x12, 0x24, 0x36, 0x48, 0x5a, 0x6c, 0x7e,
	0x90, 0x82, 0xb4, 0xa6, 0xd8, 0xca, 0xfc, 0xee
};

static unsigned char crc7_next(unsigned char crc, unsigned char dat)
{
	crc ^= dat;
	crc = ((crc << 4) & 0xff) ^ crc7_table[crc >> 4];
	crc = ((crc << 4) & 0xff) ^ crc7_table[crc >> 4];
	return crc;
}

unsigned char crc7_calc(const unsigned char *dat, unsigned short len)
{
	unsigned char crc = 0;

	if (len) do {
		crc = crc7_next(crc, *dat++);
	} while (--len);

	return (crc >> 1)|(1<<7);
}

[edit] Changelog

[edit] v2.2

  • specified baudRate settings

[edit] v2.1

  • Reserved Register 0xFE for Communication Settings

[edit] v2.0

  • added Packet Type 'S' (Sync)
  • added Packet Type 'n' (N)ACK with reason
  • Section 'Usage'

[edit] v1.0

  • initial release
Personal tools