public int SetDataMultiple(out byte[] requestBytes, out byte[] responseBytes, ushort start, ushort[] ushortRegs, bool[] boolRegs, out string errCode) { errCode = "OK"; try { if (_config.SelectedMemType == Memtype.Coils) { _modbus.WriteMultipleCoils(_config.Slaves, start, boolRegs); } if (_config.SelectedMemType == Memtype.HoldingRegisters) { _modbus.WriteMultipleRegisters(_config.Slaves, start, ushortRegs); } return(0); } catch (SlaveException ex) { errCode = ex.Message; return(1); } catch (Exception ex) { if (ex is InvalidOperationException) { throw; } errCode = ex.Message; return(2); } finally { requestBytes = _modbus.Transport.RequestFrame; responseBytes = _modbus.Transport.ResponseFrame; } }
public void WriteMultipleCoils(byte slaveAddress, ushort startAddress, ushort numberOfPoints, bool[] data) { if (!serialPort.IsOpen) { Open(); } try { master.WriteMultipleCoils(slaveAddress, startAddress, data); } catch (Exception ex) { AddMessage("Catch exception in the function WriteMultipleCoils(). " + ex.Message, DebugLevel.ExceptionLevel); Close(); } }