Skip to content

Commit

Permalink
update IModbusMaster interface to include custom message method, upda…
Browse files Browse the repository at this point in the history
…ted comment, consolidated RtuModbusMessage interface.
  • Loading branch information
sjalex committed May 28, 2009
1 parent c99191a commit 5b697e8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
8 changes: 8 additions & 0 deletions NModbus/src/Modbus/Device/IModbusMaster.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Modbus.IO;
using Modbus.Message;

namespace Modbus.Device
{
Expand Down Expand Up @@ -91,5 +92,12 @@ public interface IModbusMaster : IDisposable
/// <param name="startWriteAddress">Address to begin writing (Holding registers are addressed starting at 0).</param>
/// <param name="writeData">Register values to write.</param>
ushort[] ReadWriteMultipleRegisters(byte slaveAddress, ushort startReadAddress, ushort numberOfPointsToRead, ushort startWriteAddress, ushort[] writeData);

/// <summary>
/// Executes the custom message.
/// </summary>
/// <typeparam name="TResponse">The type of the response.</typeparam>
/// <param name="request">The request.</param>
TResponse ExecuteCustomMessage<TResponse>(IModbusMessage request) where TResponse : IModbusMessage, new();
}
}
2 changes: 1 addition & 1 deletion NModbus/src/Modbus/Device/ModbusSlave.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void RegisterCustomFunction<TRequest>(byte functionCode, Func<TRequest, D
if (_customMessages.ContainsKey(functionCode))
throw new ArgumentException("A custom function already exists with the specified function code. You must unregister it first.", "functionCode");

// CONSIDER only allowing true user-defined function codes, Modbus defines 65-101 as user-defined function codes.
// CONSIDER only allowing true user-defined function codes, Modbus defines 65-72 and 100-110 as user-defined function codes.

// wrap in more generic delegate type
Func<IModbusMessage, DataStore, IModbusMessage> wrapper = (message, dataStore) => applyRequest((TRequest) message, dataStore);
Expand Down
4 changes: 2 additions & 2 deletions NModbus/src/Modbus/IO/ModbusRtuTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static int RequestBytesToRead(byte[] frameStart, ModbusSlave slave)
// allow a custom function registered with the slave to provide the number of bytes left to read
CustomMessageInfo messageInfo;
if (slave.TryGetCustomMessageInfo(functionCode, out messageInfo))
return messageInfo.Instance.RtuRequestBytesRemaining(frameStart);
return messageInfo.Instance.RtuBytesRemaining(frameStart);

int numBytes;

Expand Down Expand Up @@ -75,7 +75,7 @@ public static int ResponseBytesToRead<T>(byte[] frameStart, Func<Type, IModbusMe
{
// allow a custom message to provide the number of bytes left to read
if (typeof(IModbusMessageRtu).IsAssignableFrom(typeof(T)))
return instanceCache.Invoke(typeof(T)).RtuResponseBytesRemaining(frameStart);
return instanceCache.Invoke(typeof(T)).RtuBytesRemaining(frameStart);

byte functionCode = frameStart[1];

Expand Down
9 changes: 2 additions & 7 deletions NModbus/src/Modbus/Message/IModbusMessageRtu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@ namespace Modbus.Message
public interface IModbusMessageRtu : IModbusMessage
{
/// <summary>
/// Gets the remaining length of the response given the specified frame start.
/// Gets the remaining length of the message given the specified frame start.
/// </summary>
Func<byte[], int> RtuResponseBytesRemaining { get; }

/// <summary>
/// Gets the remaining length of the request given the specified frame start.
/// </summary>
Func<byte[], int> RtuRequestBytesRemaining { get; }
Func<byte[], int> RtuBytesRemaining { get; }
}
}

0 comments on commit 5b697e8

Please sign in to comment.