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
GATEWAY Module for Modbus TCP
Articlenumber: 100088
Instructions
Download and install the following software
KUNBUS Scripter: https://www.kunbus.de/downloads.html
(or see attached ZIP)
PuTTY: https://www.putty.org/
QModMaster: https://sourceforge.net/projects/qmodmaster/
Connect the USB-PiBridge Plug with the Serial Gateway
Connect the 24V power supply. The power led should light green
Connect the PiBridge Plug via USB to your PC
Open the Scripter and load the script “ScriptExample_64Registers.pbs” see top of the page.
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);
Klick on the green button to download the script to the device
Hardware Setup
Disconnect the USB-PiBridge Plug
Connect the two Modular Gateway components with the (Not-USB) PiBridge Plug
Connect the 24V power supply, the both power leds should light green
Connect the Fieldbus Connection
Test it!
Open PuTTy
Enter the serial connection details
Go To “Session”
Open The Connection
Open QModmaster
Configure the TCP Connection
Configure cyclic data exchange
You should see status “000A” on the first register which equals 10 decimal
Data Transfer
Open PuTTy
Enter [Alt] + [Num Pad 2] into the PuTTy Terminal window (not the “2” key next to the “w” key!)
You do not see an output but this means we want to transfer 2 registers, i.e. 4 bytes
Now enter “1234”
You should see the output “1234” after you have typed the last character
Open QModMaster
You should see the same output:
“000A” → Status 10 decimal - no error
“0002” → Two registers have been transferred which means 4 bytes
“3132“ → ASCII “12”
“3334” → ASCII “34”