如何修复来自 WEB API 的 Modbus 连接错误?

问题描述

While I am trying to connect MODBUS slave device from WEB API I got this error,what should I do for fix it

在这种情况下,我尝试连接 https://localhost:44386/api/canli?dene=192.168.0.8 这个 API URL。通常我可以从表单应用程序连接 192.168.0.8 IP 地址

解决方法

我想 Int32? dene 是您的 IP 地址。因此最好将此参数定义为string,然后您可以调用:

modbusClient = new modbusClient(dene,502); 

如果出于某种原因需要将此参数作为数字进行操作,您应该将其定义为 UInt32long,然后将其转换为类似 belog 的字符串:

var ipAddress = new IPAddress((long)dene);
modbusClient = new ModbusClient(ipAddress.ToString(),502);