Skip to content

RS485CommandResponse

Michael Jonker edited this page Nov 12, 2015 · 5 revisions

The RS485CommandResponse demo sketch is a simple message oriented application, i.e. incoming messages are decoded and executed. Depending on the request, the sketch may reply with zero, one or more messages. The sketch may also send unsolicited messages (in this particular case it may send out so called breathing messages).

The sketch is programmed to responds to the broadcast address "S*", as well as a configurable private address "S+" where the '+' sign can be reconfigured as described below.

Usage of RS485CommandResponse example sketch

The RS485CommandResponse demo sketch maintains all application specific parameters in the class ApplicationControl (embedded in the sketch file). Four of these parameters (ApplicationType, SlaveId, Priority, RS232ExpirationTime) are read upon start up from the EEPROM. Three of these parameters can be updated, and saved on the EEPROM with the following (case sensitive!) user commands to be given over the active communication channel (i.e. which is either the RS485 or the RS232 based Console):

{S*SLID=<your slave identifier character>}
{S*PRIO=<your slave priority (0...31)>}
{S*EXPL=<your slave RS232 expiration time in seconds, use zero to disable>}
{S*?}
{S*EEPROM.SAVE}

If, on start-up of the sketch, the EEPROM was not found to be programmed for this demo sketch application type (here 66) then the parameters will be set to the following default values: ApplicationType=66, SlaveId= '+'; Priority=0x1F; RS232 expiration time =0 (i.e. disabled). The EEPROM values can be updated with a {S...EEPROM.SAVE} command.

After programming the SlaveId with e.g. message {S*SLID=A} the module will respond to both the explicit slave address starting with {SA and to the general broadcast address starting with {S*.

Programming the RS232 expiration time with message {S*EXPL=...}, will set the time in seconds that the RS232 input should be idle for the slave to automatically switch to RS485 communication. Note that after start-up, the first value used for RS232ExpirationTime is the bitwise and of the specified value and 0x07. Setting the RS232 expiration time to zero will inhibit the automatic switch over, however, you can still switch to RS485 explicitly with the message {S*RS485} or {SARS485} from the RS232 Console. Note that whilst command input is given over either RS232 or RS485, depending on the active communication mode, any output sent to RS485, is always also transmitted to the RS232 console.

When the RS485CommandResponse sketch starts up, it will first produce a sequence of flashes on the DE and RE* LEDs (see fig 1. on Hardware Connection ). Subsequently, the demo will send an ALIVE message and a memory statistics report to the RS232 console. Depending on the value of RS232ExpirationTime, and whether data over RS232 was available or not, the demo will then switch to RS485 mode.