User Tools

Site Tools

한국어

moacon:startmodbusrtu:index

startModbusRtu

void startModbusRtu(u8 comCh, u8 slaveAdr, u16* regBuffer, u16* bitBuffer)

comCh: The RS-232 channel to listen on
slaveAdr: The Modbus slave address
regBuffer: Word data memory
bitBuffer: Bit data memory

Starts a Modbus slave on the MOACON listening on RS-232 channel comCh with Modbus slave address slaveAdr. regBuffer and bitBuffer are the areas of memory from which the master will read and write word data and bit data respectively. Those buffers must be declared static.

Because the MOACON uses the Modbus protocol over and RS-232 channel, it is necessary to open the RS- 232 with the openCom function before calling startModbusRtu.

static u8 MDcoil[10];
static u16 MDregister[10];
 
openCom(2,38400, C8N1);
startModbusRtu(2,1,MDregister, MDcoil);

NOTE: Although the MOACON can have more than one RS-232 channel using the CPU Module and the Communication Module, the MOACON does not support multiple Modbus slaves running simultaneously.

An example within a digital input module in slot 1, and a digital output module in slot 2:

#include "moacon500.h"
 
static u8 MDcoil[2];
 
void cmain(void)
{
    portInit(0, 1); // Input module in slot 0
    portInit(1, 0); // Output module in slot 1
 
    openCom(0, 115200, C8N1);
    startModbusRtu(0, 1, NULL, MDcoil);
 
    while(1)
    {
        int i;
 
        // read inputs into MDcoil
        MDcoil[0] = portBlockIn(0);
 
        // write MDcoil to outputs
        for(i = 0; i < 8; i++)
        {
            portOut(10 + i, (MDcoil[1] >> i) & 1);
        }
    }
}

See also: About MODBUS

MOACON home

moacon/startmodbusrtu/index.txt · Last modified: 2020/06/30 18:03 by COMFILE Technology