Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Apollo3zehn committed Oct 19, 2021
2 parents 39d819d + e7bcd4e commit 74024b8
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 23 deletions.
2 changes: 1 addition & 1 deletion build/build.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<Major Condition="$(Major) == ''">4</Major>
<Minor Condition="$(Minor) == ''">0</Minor>
<Revision Condition="$(Revision) == ''">0</Revision>
<VersionSuffix Condition="$(VersionSuffix) == ''">preview.1</VersionSuffix>
<VersionSuffix Condition="$(VersionSuffix) == ''">preview.2</VersionSuffix>
</PropertyGroup>

<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/FluentModbus/Client/ModbusClientAsync.tt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<#@ import namespace="System.Text.RegularExpressions" #>

<#
var csstring = File.ReadAllText("FluentModbus/src/FluentModbus/Client/ModbusClient.cs");
var csstring = File.ReadAllText("src/FluentModbus/Client/ModbusClient.cs");
var methodsToConvert = Regex.Matches(csstring, @" \/{3}.*?\n }", RegexOptions.Singleline);

#>
Expand Down
13 changes: 9 additions & 4 deletions src/FluentModbus/Client/ModbusRtuClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public bool IsConnected
/// <summary>
/// Gets or sets the parity-checking protocol. Default is Parity.Even.
/// </summary>
// Must be even according to the spec (https://www.modbus.org/docs/Modbus_over_serial_line_V1_02.pdf,
// section 2.5.1 RTU Transmission Mode): "The default parity mode must be even parity."
public Parity Parity { get; set; } = Parity.Even;

/// <summary>
Expand Down Expand Up @@ -122,8 +124,13 @@ internal void Connect(IModbusRtuSerialPort serialPort)

internal void Connect(IModbusRtuSerialPort serialPort, ModbusEndianness endianness)
{
if (this.Parity == Parity.None && this.StopBits != StopBits.Two)
throw new InvalidOperationException(ErrorMessage.Modbus_NoParityRequiresTwoStopBits);
/* According to the spec (https://www.modbus.org/docs/Modbus_over_serial_line_V1_02.pdf),
* section 2.5.1 RTU Transmission Mode: "... the use of no parity requires 2 stop bits."
* Remove this check to improve compatibility (#56).
*/

//if (this.Parity == Parity.None && this.StopBits != StopBits.Two)
// throw new InvalidOperationException(ErrorMessage.Modbus_NoParityRequiresTwoStopBits);

base.SwapBytes = BitConverter.IsLittleEndian && endianness == ModbusEndianness.BigEndian
|| !BitConverter.IsLittleEndian && endianness == ModbusEndianness.LittleEndian;
Expand Down Expand Up @@ -177,9 +184,7 @@ private protected override Span<byte> TransceiveFrame(byte unitIdentifier, Modbu

// special case: broadcast (only for write commands)
if (unitIdentifier == 0)
{
return _frameBuffer.Buffer.AsSpan(0, 0);
}

// wait for and process response
frameLength = 0;
Expand Down
1 change: 0 additions & 1 deletion src/FluentModbus/Client/ModbusRtuClientAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ private protected override async Task<Memory<byte>> TransceiveFrameAsync(byte un
case ModbusFunctionCode.WriteFileRecord:
case ModbusFunctionCode.MaskWriteRegister:
break;

default:
throw new ModbusException(ErrorMessage.Modbus_InvalidUseOfBroadcast);
}
Expand Down
2 changes: 1 addition & 1 deletion src/FluentModbus/Client/ModbusRtuClientAsync.tt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<#@ import namespace="System.Text.RegularExpressions" #>

<#
var csstring = File.ReadAllText("FluentModbus/src/FluentModbus/Client/ModbusRtuClient.cs");
var csstring = File.ReadAllText("src/FluentModbus/Client/ModbusRtuClient.cs");
var match = Regex.Matches(csstring, @"(private protected override Span<byte> TransceiveFrame\()(.*?)\)(.*?\n })", RegexOptions.Singleline)[0];

#>
Expand Down
2 changes: 1 addition & 1 deletion src/FluentModbus/Client/ModbusTcpClientAsync.tt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<#@ import namespace="System.Text.RegularExpressions" #>

<#
var csstring = File.ReadAllText("FluentModbus/src/FluentModbus/Client/ModbusTcpClient.cs");
var csstring = File.ReadAllText("src/FluentModbus/Client/ModbusTcpClient.cs");
var match = Regex.Matches(csstring, @"(private protected override Span<byte> TransceiveFrame\()(.*?)\)(.*?\n })", RegexOptions.Singleline)[0];

#>
Expand Down
9 changes: 0 additions & 9 deletions src/FluentModbus/Resources/ErrorMessage.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions src/FluentModbus/Resources/ErrorMessage.resx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,4 @@
<data name="Modbus_InvalidValueUShort" xml:space="preserve">
<value>The value is invalid. Valid values are in the range of 0 - 65535.</value>
</data>
<data name="Modbus_NoParityRequiresTwoStopBits" xml:space="preserve">
<value>The use of no parity bit requires 2 stop bits.</value>
</data>
</root>
9 changes: 7 additions & 2 deletions src/FluentModbus/Server/ModbusRtuServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,13 @@ public void Start(string port)
/// <param name="serialPort">The serial port to be used.</param>
public void Start(IModbusRtuSerialPort serialPort)
{
if (this.Parity == Parity.None && this.StopBits != StopBits.Two)
throw new InvalidOperationException(ErrorMessage.Modbus_NoParityRequiresTwoStopBits);
/* According to the spec (https://www.modbus.org/docs/Modbus_over_serial_line_V1_02.pdf),
* section 2.5.1 RTU Transmission Mode: "... the use of no parity requires 2 stop bits."
* Remove this check to improve compatibility (#56).
*/

//if (this.Parity == Parity.None && this.StopBits != StopBits.Two)
// throw new InvalidOperationException(ErrorMessage.Modbus_NoParityRequiresTwoStopBits);

base.StopProcessing();
base.StartProcessing();
Expand Down

0 comments on commit 74024b8

Please sign in to comment.