Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
Modbus
libmodbus驱动可以同时应用在多个串口上面吗
发布于 2020-09-08 11:32:32 浏览:2104
订阅该版
modbus_new_rtu这个函数返回的是modbus结构体指针*ctx,通过创建多个不同的结构体指针,我觉得应该可以创建串口多个modbus接口,不知道是不是这样,有人试过吗
查看更多
文武斌
2020-09-08
这家伙很懒,什么也没写!
可以的,只要你的控制块不一样就行
4
个回答
默认排序
按发布时间排序
晨起小酌
2020-09-08
这家伙很懒,什么也没写!
```c modbus_t* modbus_new_rtu(const char *device, int baud, char parity, int data_bit, int stop_bit) { modbus_t *ctx; modbus_rtu_t *ctx_rtu; /* Check device argument */ if (device == NULL || *device == 0) { fprintf(stderr, "The device string is empty\n"); errno = EINVAL; return NULL; } /* Check baud argument */ if (baud == 0) { fprintf(stderr, "The baud rate value must not be zero\n"); errno = EINVAL; return NULL; } ctx = (modbus_t *)malloc(sizeof(modbus_t)); _modbus_init_common(ctx); ctx->backend = &_modbus_rtu_backend; ctx->backend_data = (modbus_rtu_t *)malloc(sizeof(modbus_rtu_t)); ctx_rtu = (modbus_rtu_t *)ctx->backend_data; ctx_rtu->device = NULL; /* Device name and \0 */ ctx_rtu->device = (char *)malloc((strlen(device) + 1) * sizeof(char)); strcpy(ctx_rtu->device, device); ctx_rtu->baud = baud; if (parity == 'N' || parity == 'E' || parity == 'O') { ctx_rtu->parity = parity; } else { modbus_free(ctx); errno = EINVAL; return NULL; } ctx_rtu->data_bit = data_bit; ctx_rtu->stop_bit = stop_bit; #if HAVE_DECL_TIOCSRS485 /* The RS232 mode has been set by default */ ctx_rtu->serial_mode = MODBUS_RTU_RS232; #endif #if HAVE_DECL_TIOCM_RTS /* The RTS use has been set by default */ ctx_rtu->rts = MODBUS_RTU_RTS_NONE; /* Calculate estimated time in micro second to send one byte */ ctx_rtu->onebyte_time = 1000000 * (1 + data_bit + (parity == 'N' ? 0 : 1) + stop_bit) / baud; ctx_rtu->rts_pin = 0; /* The internal function is used by default to set RTS */ ctx_rtu->set_rts = _modbus_rtu_ioctl_rts; /* The delay before and after transmission when toggling the RTS pin */ ctx_rtu->rts_delay = ctx_rtu->onebyte_time; #endif ctx_rtu->confirmation_to_ignore = FALSE; return ctx; } ```
ching
2020-09-08
这家伙很懒,什么也没写!
看代码像是可以的
lizhen9880
认证专家
2020-09-08
这家伙很懒,什么也没写!
可以
撰写答案
登录
注册新账号
关注者
0
被浏览
2.1k
关于作者
晨起小酌
这家伙很懒,什么也没写!
提问
3
回答
8
被采纳
0
关注TA
发私信
相关问题
1
ModbusRTU协议栈漏发送最后一个字节
2
3.0 增加freemodbus,编译不过
3
RT_THREAD上面的串口MODBUSRTU为啥没功能码?
4
关于 freemodbus 里存在的一点问题分享
5
请教如何使用组件里的FreeMODBUS
6
求一个FreeModbus的从机测试程序
7
FreeModbus的从机调试说明(含测试程序)
8
rtt_freemodbus
9
freemodbus怎么配置到uart
10
FreeModeBus从机调试问题
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
机器人操作系统 (ROS2) 和 RT-Thread 通信
4
国产MCU移植系列教程汇总,欢迎查看!
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
不用开发板都能跑的RT-Thread(保姆级教程)
2
RTTHREAD Doxygen 阅读
3
RT-Thread RISCV64 qemu 极简上手(不用思考就能跑起来)
4
NXP MCXN236测评-软件模拟I2C
5
ENV-Windows v2.0.0版本发布
热门标签
RT-Thread Studio
串口
LWIP
Env
SPI
Bootloader
AT
Hardfault
ART-Pi
CAN总线
FinSH
USB
文件系统
DMA
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
ESP8266
ota在线升级
WIZnet_W5500
I2C_IIC
UART
flash
packages_软件包
cubemx
freemodbus
PWM
潘多拉开发板_Pandora
定时器
BSP
ADC
flashDB
中断
编译报错
Debug
socket
msh
keil_MDK
SFUD
GD32
ulog
C++_cpp
MicroPython
at_device
本月问答贡献
小小李sunny
3
个答案
4
次被采纳
Rb君
16
个答案
2
次被采纳
xiaorui
8
个答案
2
次被采纳
踩姑娘的小蘑菇
8
个答案
2
次被采纳
出出啊
2
个答案
2
次被采纳
本月文章贡献
Z_Y
2
篇文章
6
次点赞
andeyqi
2
篇文章
2
次点赞
Lu_盼盼
2
篇文章
1
次点赞
liYony
1
篇文章
12
次点赞
Rb君
1
篇文章
5
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部