Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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.

Image RemovedImage Added

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

Image RemovedImage Added

USB-PiBridge Plug

Articlenumber: 100101

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

view-file

nameScriptExample_64Registers.pbs

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

like on the picture on the right.
Image Removed
Image Removed
Download the script
    1. Image Added
  1. Connect the 24V power supply. The power led should light green

  2. Connect the PiBridge Plug via USB to your PC

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

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

  • Image Removed

    1. Image Added

    View file
    namescripter.zip

    Download the script

    View file
    nameScriptExample_64Registers.pbs

    Code Block
    breakoutModewide
    //  
    //  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

    Image Added

    Hardware Setup

    1. Disconnect the USB-PiBridge Plug

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

    3. Image Added

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

    5. Connect the Fieldbus Connection

    6. Image Added

    7. Image Added

    Test it!

    1. Open PuTTy

      1. Enter the serial connection details

      2. Go To “Session”

      3. Open The Connection

    2. Open QModmaster

      1. Configure the TCP Connection

      2. Configure cyclic data exchange

      3. 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”

    Page Properties
    hiddentrue

    Verwandte Vorgänge