有个dll
internal interface IModbusOperator
using System;
namespace xxx
{
{
void open(object parameter);
void open(ExSerialPort serPort);
bool isOpen();
void close();
void closeNoResetFlag();
void setReadWriteTimeout(uint readTimeout, uint writeTimeout);
void setRetryCount(int count);
bool readCoil(byte slabId, ushort startAddress, ushort length, out bool[] dest);
bool readCoilInput(byte slabId, ushort startAddress, ushort length, out bool[] dest);
bool readHoldingRegister(byte slabId, ushort startAddress, ushort length, bool isReverse, out uint[] dest);
bool readHoldingRegister(byte slabId, ushort startAddress, ushort length, bool isReverse, out float[] dest);
bool readHoldingRegister(byte slabId, ushort startAddress, ushort length, out ushort[] dest);
bool readInputRegister(byte slabId, ushort startAddress, ushort length, bool isReverse, out float[] dest);
bool readInputRegister(byte slabId, ushort startAddress, ushort length, bool isReverse, out uint[] dest);
bool readInputRegister(byte slabId, ushort startAddress, ushort length, out ushort[] dest);
void writeCoil(byte slabId, ushort startAddress, bool[] value);
void writeHoldingRegister(byte slabId, ushort startAddress, bool isReverse, float[] value);
void writeHoldingRegister(byte slabId, ushort startAddress, bool isReverse, int[] value);
bool writeHoldingRegister(byte slabId, ushort startAddress, ushort[] dest);
}
}
在c#中调用的一个例子,其中下面这行出错 dest = this.master.ReadCoils(slabId, startAddress - 1, length);
bool IModbusOperator.readCoil(byte slabId, ushort startAddress, ushort length, out bool[] dest)
{
bool result;
try
{
if (!this.isOpen || this.serialPort == null)
{
throw new Exception("请先打开串口");
}
if (!this.serialPort.IsOpen)
{
this.open();
}
if (slabId > 255)
{
throw new Exception("设备ID不能>255");
}
Monitor.Enter(this);
try
{
this.currentRetryCount = 0;
while (true)
{
try
{
dest = this.master.ReadCoils(slabId, startAddress - 1, length);
}
错误 101 与“Modbus.Device.IModbusMaster.ReadCoils(byte, ushort, ushort)”最匹配的重载方法具有一些无效参数
错误 102 参数 2: 无法从“int”转换为“ushort”
该怎么修改呢?
------解决思路----------------------
dest = this.master.ReadCoils(slabId, (ushort)(startAddress - 1), (ushort)length);