Skip to content

Commit ab53f66

Browse files
committed
Remove function restriction from slave, fixed slave logs
1 parent 7add7cf commit ab53f66

File tree

11 files changed

+20
-212
lines changed

11 files changed

+20
-212
lines changed

CommonControls/BaseForm.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -597,13 +597,15 @@ private void buttonPauseLog_Click(object sender, EventArgs e)
597597
buttonPauseLog.Text = _logPaused ? "Resume" : "Pause";
598598
}
599599

600-
protected void DriverIncommingData(byte[] data)
600+
protected void DriverIncommingData(byte[] data, int len)
601601
{
602602
if (_logPaused)
603603
return;
604-
var hex = new StringBuilder(data.Length * 2);
605-
foreach (byte b in data)
606-
hex.AppendFormat("{0:x2} ", b);
604+
var hex = new StringBuilder(len);
605+
for(int i = 0; i < len; i++)
606+
{
607+
hex.AppendFormat("{0:x2} ", data[i]);
608+
}
607609
AppendLog(String.Format("RX: {0}", hex));
608610
}
609611

ModbusLib/Net/TcpServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected override void Worker()
6464
length = CacheSize;
6565
//read the data from the physical port
6666
Port.Receive(buffer, length, SocketFlags.None);
67-
Protocol.OnIncommingData(buffer);
67+
Protocol.OnIncommingData(buffer, length);
6868
//append the data to the writer
6969
if (writer == null)
7070
writer = new ByteArrayWriter();

ModbusLib/Net/UdpServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected override void Worker()
5555
Port.ReceiveFrom(
5656
buffer,
5757
ref remote);
58-
Protocol.OnIncommingData(buffer);
58+
Protocol.OnIncommingData(buffer, length);
5959
//try to decode the incoming data
6060
var data = new ServerCommData(Protocol) {IncomingData = new ByteArrayReader(buffer)};
6161

ModbusLib/Ports/SerialPortServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private void Worker()
7676
buffer,
7777
0,
7878
length);
79-
Protocol.OnIncommingData(buffer);
79+
Protocol.OnIncommingData(buffer, length);
8080
//append the data to the writer
8181
if (writer == null)
8282
writer = new ByteArrayWriter();

ModbusLib/Protocols/Modbus/ModbusClient.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public void OnOutgoingData(byte[] data)
3939
if (OutgoingData != null) OutgoingData(data);
4040
}
4141

42-
public void OnIncommingData(byte[] data)
42+
public void OnIncommingData(byte[] data, int len)
4343
{
44-
if (IncommingData != null) IncommingData(data);
44+
if (IncommingData != null) IncommingData(data, len);
4545
}
4646

4747
/// <summary>
@@ -69,7 +69,7 @@ public CommResponse ExecuteGeneric(
6969
if (data.OutgoingData != null)
7070
OnOutgoingData(data.OutgoingData.ToArray());
7171
if (data.IncomingData != null)
72-
OnIncommingData(data.IncomingData.ToArray());
72+
OnIncommingData(data.IncomingData.ToArray(), data.IncomingData.Length);
7373
return rVal;
7474
}
7575

ModbusLib/Protocols/Modbus/ModbusCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public class ModbusCommand
7070
public const byte ErrorMemoryParity = 8;
7171

7272
public delegate void OutgoingData(byte[] data);
73-
public delegate void IncommingData(byte[] data);
73+
public delegate void IncommingData(byte[] data, int len);
7474

7575
public ModbusCommand(byte fc)
7676
{

ModbusLib/Protocols/Modbus/ModbusServer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ public void OnOutgoingData(byte[] data)
4141
if (OutgoingData != null) OutgoingData(data);
4242
}
4343

44-
public void OnIncommingData(byte[] data)
44+
public void OnIncommingData(byte[] data, int len)
4545
{
46-
if (IncommingData != null) IncommingData(data);
46+
if (IncommingData != null) IncommingData(data, len);
4747
}
4848

4949
/// <summary>

ModbusLib/Protocols/Shared/IProtocol.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public interface IProtocol
2929
event ModbusCommand.IncommingData IncommingData;
3030

3131
void OnOutgoingData(byte[] data);
32-
void OnIncommingData(byte[] data);
32+
void OnIncommingData(byte[] data, int len);
3333

3434

3535
}

ModbusMaster/MasterForm.Designer.cs

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ModbusSlave/SlaveForm.Designer.cs

Lines changed: 0 additions & 73 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)