-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved to sharp serial and single net4x target.
- Loading branch information
1 parent
8987f81
commit 854bdb2
Showing
12 changed files
with
251 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using SharpSerial; | ||
|
||
namespace SharpModbus | ||
{ | ||
public class ModbusIsolatedStream : IModbusStream | ||
{ | ||
private readonly Action<char, byte[], int> monitor; | ||
private readonly SerialProcess serialProcess; | ||
private readonly int timeout; | ||
|
||
public ModbusIsolatedStream(object settings, int timeout, Action<char, byte[], int> monitor = null) | ||
{ | ||
this.serialProcess = new SerialProcess(settings); | ||
this.timeout = timeout; | ||
this.monitor = monitor; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Disposer.Dispose(serialProcess); | ||
} | ||
|
||
public void Write(byte[] data) | ||
{ | ||
if (monitor != null) monitor('>', data, data.Length); | ||
serialProcess.Write(data); | ||
} | ||
|
||
public int Read(byte[] data) | ||
{ | ||
var response = serialProcess.Read(data.Length, -1, timeout); | ||
var count = response.Length; | ||
for (var i = 0; i < count; i++) data[i] = response[i]; | ||
if (monitor != null) monitor('<', data, count); | ||
return count; | ||
} | ||
} | ||
} |
Oops, something went wrong.