Skip to content

Commit

Permalink
add serialPort param
Browse files Browse the repository at this point in the history
  • Loading branch information
GavinYellow committed Dec 26, 2017
1 parent dc91bcd commit 5e69945
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions SCADA/Program/ModbusDriver/ModbusRTUDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,45 @@ public bool IsClosed
}
}

private int _timeOut = 1000;
private int _timeOut = 3000;
public int TimeOut
{
get { return _timeOut; }
set { _timeOut = value; }
}


private int _baudRate = 9600;
[Description("波特率")]
public int BaudRate
{
get { return _baudRate; }
set { _baudRate = value; }
}
// private SerialPort _serialPort;

private int _dataBits = 8;
[Description("数据位")]
public int DataBits
{
get { return _dataBits; }
set { _dataBits = value; }
}
private StopBits _stopBits = StopBits.One;
[Description("停止位")]
public StopBits StopBits
{
get { return _stopBits; }
set { _stopBits = value; }
}

private Parity _parity = Parity.None;
[Description("奇偶校验")]
public Parity parity
{
get { return _parity; }
set { _parity = value; }
}

List<IGroup> _grps = new List<IGroup>();
public IEnumerable<IGroup> Groups
Expand All @@ -77,15 +103,15 @@ public bool Connect()
{
try
{
if (_timeOut <= 0) _timeOut = 1000;
if (_serialPort == null)
_serialPort = new SerialPort(_port);
if (_timeOut <= 0) _timeOut = 1000;
_serialPort.ReadTimeout = _timeOut;
_serialPort.WriteTimeout = _timeOut;
_serialPort.BaudRate = _baudRate;
_serialPort.DataBits = 8;
_serialPort.Parity = Parity.Even;
_serialPort.StopBits = StopBits.One;
_serialPort.DataBits = _dataBits;
_serialPort.Parity = _parity;
_serialPort.StopBits = _stopBits;
_serialPort.Open();
return true;
}
Expand Down
Binary file modified SCADA/dll/ModbusDriver.dll
Binary file not shown.

0 comments on commit 5e69945

Please sign in to comment.