Generation

generate functionTue, 17 Jan 2023

Esp32 modbus tcp slave

#include "mbed.h" #include "modbustcp.h" #include "EthernetInterface.h" #include "stdio.h" Serial pc(USBTX, USBRX); DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); int main() { EthernetInterface eth; eth.init(); eth.connect(); printf("IP Address is %s\n", eth.getIPAddress()); ModbusTCPSlave slave(TCPSOCKET_PORT); //set coils start address (1:output coil,0:input coil) slave.setCoilStartAddress(0x00,0x00); //set discrete input start address (1:output coil,0:input coil) slave.setDiscreteInputStartAddress(0x00,0x00); //set holding registers start address (1:input reg,0:output reg) slave.set

Questions about programming?Chat with your personal AI assistant