Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RX Buffer was being cleared with correct data in it. #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 9 additions & 28 deletions EasyModbus/ModbusClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ public bool[] ReadDiscreteInputs(int startingAddress, int quantity)
bytesToRead = 5 + quantity / 8;
else
bytesToRead = 6 + quantity / 8;
// serialport.ReceivedBytesThreshold = bytesToRead;
readBuffer = new byte[256];
serialport.Write(data, 6, 8);
if (debug)
{
Expand All @@ -937,8 +937,6 @@ public bool[] ReadDiscreteInputs(int startingAddress, int quantity)
SendDataChanged(this);

}
data = new byte[2100];
readBuffer = new byte[256];
DateTime dateTimeSend = DateTime.Now;
byte receivedUnitIdentifier = 0xFF;

Expand Down Expand Up @@ -1118,7 +1116,7 @@ public bool[] ReadCoils(int startingAddress, int quantity)
bytesToRead = 5 + quantity/8;
else
bytesToRead = 6 + quantity/8;
// serialport.ReceivedBytesThreshold = bytesToRead;
readBuffer = new byte[256];
serialport.Write(data, 6, 8);
if (debug)
{
Expand All @@ -1133,8 +1131,6 @@ public bool[] ReadCoils(int startingAddress, int quantity)
SendDataChanged(this);

}
data = new byte[2100];
readBuffer = new byte[256];
DateTime dateTimeSend = DateTime.Now;
byte receivedUnitIdentifier = 0xFF;

Expand Down Expand Up @@ -1311,7 +1307,7 @@ public int[] ReadHoldingRegisters(int startingAddress, int quantity)
{
dataReceived = false;
bytesToRead = 5 + 2 * quantity;
// serialport.ReceivedBytesThreshold = bytesToRead;
readBuffer = new byte[256];
serialport.Write(data, 6, 8);
if (debug)
{
Expand All @@ -1326,9 +1322,6 @@ public int[] ReadHoldingRegisters(int startingAddress, int quantity)
SendDataChanged(this);

}
data = new byte[2100];
readBuffer = new byte[256];

DateTime dateTimeSend = DateTime.Now;
byte receivedUnitIdentifier = 0xFF;

Expand Down Expand Up @@ -1515,9 +1508,7 @@ public int[] ReadInputRegisters(int startingAddress, int quantity)
{
dataReceived = false;
bytesToRead = 5 + 2 * quantity;


// serialport.ReceivedBytesThreshold = bytesToRead;
readBuffer = new byte[256];
serialport.Write(data, 6, 8);
if (debug)
{
Expand All @@ -1532,8 +1523,6 @@ public int[] ReadInputRegisters(int startingAddress, int quantity)
SendDataChanged(this);

}
data = new byte[2100];
readBuffer = new byte[256];
DateTime dateTimeSend = DateTime.Now;
byte receivedUnitIdentifier = 0xFF;

Expand Down Expand Up @@ -1720,7 +1709,7 @@ public void WriteSingleCoil(int startingAddress, bool value)
{
dataReceived = false;
bytesToRead = 8;
// serialport.ReceivedBytesThreshold = bytesToRead;
readBuffer = new byte[256];
serialport.Write(data, 6, 8);
if (debug)
{
Expand All @@ -1735,8 +1724,6 @@ public void WriteSingleCoil(int startingAddress, bool value)
SendDataChanged(this);

}
data = new byte[2100];
readBuffer = new byte[256];
DateTime dateTimeSend = DateTime.Now;
byte receivedUnitIdentifier = 0xFF;

Expand Down Expand Up @@ -1902,7 +1889,7 @@ public void WriteSingleRegister(int startingAddress, int value)
{
dataReceived = false;
bytesToRead = 8;
// serialport.ReceivedBytesThreshold = bytesToRead;
readBuffer = new byte[256];
serialport.Write(data, 6, 8);
if (debug)
{
Expand All @@ -1917,8 +1904,6 @@ public void WriteSingleRegister(int startingAddress, int value)
SendDataChanged(this);

}
data = new byte[2100];
readBuffer = new byte[256];
DateTime dateTimeSend = DateTime.Now;
byte receivedUnitIdentifier = 0xFF;

Expand Down Expand Up @@ -2101,7 +2086,7 @@ public void WriteMultipleCoils(int startingAddress, bool[] values)
{
dataReceived = false;
bytesToRead = 8;
// serialport.ReceivedBytesThreshold = bytesToRead;
readBuffer = new byte[256];
serialport.Write(data, 6, data.Length - 6);
if (debug)
{
Expand All @@ -2116,8 +2101,6 @@ public void WriteMultipleCoils(int startingAddress, bool[] values)
SendDataChanged(this);

}
data = new byte[2100];
readBuffer = new byte[256];
DateTime dateTimeSend = DateTime.Now;
byte receivedUnitIdentifier = 0xFF;

Expand Down Expand Up @@ -2288,7 +2271,7 @@ public void WriteMultipleRegisters(int startingAddress, int[] values)
{
dataReceived = false;
bytesToRead = 8;
// serialport.ReceivedBytesThreshold = bytesToRead;
readBuffer = new byte[256];
serialport.Write(data, 6, data.Length - 6);

if (debug)
Expand All @@ -2304,8 +2287,6 @@ public void WriteMultipleRegisters(int startingAddress, int[] values)
SendDataChanged(this);

}
data = new byte[2100];
readBuffer = new byte[256];
DateTime dateTimeSend = DateTime.Now;
byte receivedUnitIdentifier = 0xFF;

Expand Down Expand Up @@ -2495,8 +2476,8 @@ public int[] ReadWriteMultipleRegisters(int startingAddressRead, int quantityRea
if (serialport != null)
{
dataReceived = false;
readBuffer = new byte[256];
bytesToRead = 5 + 2*quantityRead;
// serialport.ReceivedBytesThreshold = bytesToRead;
serialport.Write(data, 6, data.Length - 6);
if (debug)
{
Expand Down