Document toolboxDocument toolbox

Gateway module for serial network Example Setup

The GATEWAY Module for serial network uses a script for data exchange to a partner Gateway. This article shows how to put this device into operation with an example setup.

GATEWAY Module for serial network
Articlenumber: 100068

https://www.kunbus.com/serial-rx-gateway-module.html

GATEWAY Module for Modbus TCP
Articlenumber: 100088

https://www.kunbus.com/serial-rx-gateway-module.html

USB-PiBridge Plug

Articlenumber: 100101

https://revolution.kunbus.de/shop/en/usb-plug-pibridge

Instructions

  1. Download and install the following software

    1. KUNBUS Scripter: https://www.kunbus.de/downloads.html
      (or see attached ZIP)

  2. PuTTY: https://www.putty.org/

  3. QModMaster: https://sourceforge.net/projects/qmodmaster/

  4. Connect the USB-PiBridge Plug with the Serial Gateway

  5. Connect the 24V power supply. The power led should light green

  6. Connect the PiBridge Plug via USB to your PC

  7. Open the Scripter and load the script “ScriptExample_64Registers.pbs” see top of the page.

  8. Go to File → Settings and enter the serial connection details

 

 

Download the script

// // KUNBUS GmbH // 07.08.2019 // Example Script for a Gateway Serial Rx Module. // // This script demonstrates how to receive and transfer // a variable amount of up to 64 Registers (2Bytes) to a partner // Gateway Module. // // We define a serial protocol as follows // // Byte | 1 | 2 | 3 | ... | 129 | // -----+-----------+--------+--------+-----+----------+ // Desc | Registers | Byte 1 | Byte 2 | ... | Byte 128 | // // On the Partner Gateway Modbus-RTU the data is mapped as follows // // Reg. | 1025 | 1026 | 1027 | ... | 1091 | // -----+--------+-----------+---------+-----+---------+ // Desc | Status | Registers | Word 1 | ... | Word 64 | // // Attention: Command "setMBReg(address, parameter);" writes // the value in parameter in the register address. The parameter // can be a constant, variable or an array. If the parameter an array is, // must be the number of occupied bytes a multiple of 2. SECTION_CONFIG; configPort(115200, even, 1, 8); // Configrue the serial interface // Baudrate, parity, StopBits, DataBits setBigEndian(); // One register consists of two bytes big endian decl(cRegisterCount, 1); // 1-byte variable as register counter decl(cRxCnt, 1); // 1-byte variable as byte counter declArray(aRxBuf, 128); // An array may consist of up to 128 bytes decl(cStatus, 1); // 1-byte variable as cStatus // '10' : no error // '20' : the value of 'cRxCnt' is > 128 // '30' : an error occured and the execution jumps to SECTION_ERROR // '40' : a fatal error occured and the execution jumps to SECTION_FATAL SECTION_INIT; if cStatus==0 then // After the section FATAL script jumps in SECTION_INIT. Therefore set(cStatus, 10); // to avoid overwrite of those Status values this is just set on first run. endif SECTION_RUN; setMBReg(1025, cStatus); // the value of the variable 'cStatus' is saved to register '1025' readStore(cRegisterCount, 1); // read one byte from the serial interface if cRegisterCount <= 64 then // check amount of registers within range setMBReg(1026, cRegisterCount); // the amount of registers is saved to register 1026 set(cRxCnt, cRegisterCount); multiply(cRxCnt, 2); readStore(aRxBuf, cRxCnt); // At this point the execution waits until the gateway has received // 'cRxCnt' bytes. setMBReg(1027, aRxBuf); // The content of the complete receive buffer is copied to registers '1027' to '1027+cRxCnt' // The modular gateway serial transfers the registers '1027 to 1027+cRxCnt' to the partner gateway set(cStatus, 10); // The data were transferred without any problem. cStatus=10. else set(cStatus, 20); endif SECTION_ERROR; set(cStatus, 30); // In case an error occurs the execution jumps to SECTION_ERROR. setMBReg(1025, cStatus); SECTION_FATAL; set(cStatus, 40); // In case a fatal error occurs the execution jumps to SECTION_FATAL. setMBReg(1025, cStatus);
  1. Klick on the green button to download the script to the device

Hardware Setup

  1. Disconnect the USB-PiBridge Plug

  2. Connect the two Modular Gateway components with the (Not-USB) PiBridge Plug

  3.  

  4. Connect the 24V power supply, the both power leds should light green

  5. Connect the Fieldbus Connection

Test it!

  1. Open PuTTy

    1. Enter the serial connection details

    2. Go To “Session”

    3.  

    4. Open The Connection

       

  2. Open QModmaster

    1. Configure the TCP Connection

    2.  

    3. Configure cyclic data exchange

    4. You should see status “000A” on the first register which equals 10 decimal

 

Data Transfer

Open PuTTy

 

 

  1. Enter [Alt] + [Num Pad 2] into the PuTTy Terminal window (not the “2” key next to the “w” key!)

  2. You do not see an output but this means we want to transfer 2 registers, i.e. 4 bytes

  3. Now enter “1234”

  4. You should see the output “1234” after you have typed the last character

 

Open QModMaster

 

You should see the same output:

  1. “000A” → Status 10 decimal - no error

  2. “0002” → Two registers have been transferred which means 4 bytes

  3. “3132“ → ASCII “12”

  4. “3334” → ASCII “34”