/* #include * mb_sample_tcp_master.c * * Change Logs: * Date Author Notes * 2024-04-02 qiyongzhong first version */ #include "rtthread.h" #ifdef MB_USING_SAMPLE_TCP_MASTER #define DBG_TAG "mb.tcp.master" #define DBG_LVL DBG_LOG #include static const mb_backend_param_t mb_bkd_prm = { .tcp.host = "192.168.43.62", //主机地址 .tcp.port = 60000 //端口号 }; static void mb_sample_read_regs(mb_inst_t *hinst) { if (mb_connect(hinst) < 0)//连接失败, 延时返回 { LOG_E("modbus connect fail."); return; } u16 regs[64]; int addr = 4000; int nb = 29; int total = mb_read_regs(hinst, addr, nb, regs); if (total <= 0) { LOG_E("modbus read register fail."); return; } LOG_D("modbus read register success."); for (int i=0; i