Skip to content

Commit

Permalink
Merge pull request GavinYellow#16 from kevin100702/master
Browse files Browse the repository at this point in the history
ModbusTCP添加port参数和SQL 参数Datetime格式化
  • Loading branch information
GavinYellow authored May 9, 2018
2 parents c2e1f58 + e194f4a commit cac0189
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
8 changes: 4 additions & 4 deletions SCADA/Program/BatchCoreService/DAService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ public void Flush()
{
if (_hda.Count == 0) return;
if (DataHelper.Instance.BulkCopy(new HDASqlReader(_hda, this), "Log_HData",
string.Format("DELETE FROM Log_HData WHERE [TIMESTAMP]>'{0}'", _hda[0].TimeStamp.ToString())))
string.Format("DELETE FROM Log_HData WHERE [TIMESTAMP]>'{0}'", _hda[0].TimeStamp.ToString("yyyy/MM/dd HH:mm:ss"))))
{
_hda.Clear();
_hdastart = DateTime.Now;
Expand All @@ -1177,7 +1177,7 @@ public bool SaveRange(DateTime startTime, DateTime endTime)
var tempdata = _hda.ToArray();
if (tempdata.Length == 0) return true;
return DataHelper.Instance.BulkCopy(new HDASqlReader(GetData(tempdata, startTime, endTime), this), "Log_HData",
string.Format("DELETE FROM Log_HData WHERE [TIMESTAMP] BETWEEN '{0}' AND '{1}'", startTime, endTime));
string.Format("DELETE FROM Log_HData WHERE [TIMESTAMP] BETWEEN '{0}' AND '{1}'", startTime.ToString("yyyy/MM/dd HH:mm:ss"), endTime.ToString("yyyy/MM/dd HH:mm:ss")));
}

public void OnUpdate(object stateInfo)
Expand All @@ -1192,7 +1192,7 @@ public void OnUpdate(object stateInfo)
DateTime start = _hda[0].TimeStamp;
//_array.CopyTo(data, 0);
if (DataHelper.Instance.BulkCopy(new HDASqlReader(_hda, this), "Log_HData",
string.Format("DELETE FROM Log_HData WHERE [TIMESTAMP]>'{0}'", start.ToString())))
string.Format("DELETE FROM Log_HData WHERE [TIMESTAMP]>'{0}'", start.ToString("yyyy/MM/dd HH:mm:ss"))))
_hdastart = DateTime.Now;
else ThreadPool.UnsafeQueueUserWorkItem(new WaitCallback(this.SaveCachedData), _hda.ToArray());
_hda.Clear();
Expand All @@ -1213,7 +1213,7 @@ public void SaveCachedData(object stateInfo)
if (count >= 5) return;
if (DataHelper.Instance.BulkCopy(new HDASqlReader(tempData, this), "Log_HData",
string.Format("DELETE FROM Log_HData WHERE [TIMESTAMP] BETWEEN '{0}' AND '{1}'",
startTime, endTime)))
startTime.ToString("yyyy/MM/dd HH:mm:ss"), endTime.ToString("yyyy/MM/dd HH:mm:ss"))))
{
stateInfo = null;
_hdastart = DateTime.Now;
Expand Down
11 changes: 9 additions & 2 deletions SCADA/Program/ModbusDriver/ModbusTCPDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ public string ServerName
set { _ip = value; }
}

int _port = 502;
public int Port
{
get { return _port; }
set { _port = value; }
}

public bool IsClosed
{
get
Expand Down Expand Up @@ -172,7 +179,7 @@ public ModbusTCPReader(IDataServer server, short id, string name)

public bool Connect()
{
int port = 502;
//int port = 502;
try
{
if (tcpSynCl != null)
Expand All @@ -185,7 +192,7 @@ public bool Connect()
tcpSynCl.SendTimeout = _timeout;
tcpSynCl.ReceiveTimeout = _timeout;
tcpSynCl.NoDelay = true;
tcpSynCl.Connect(_ip, port);
tcpSynCl.Connect(_ip, _port);
return true;
}
catch (SocketException error)
Expand Down
Binary file modified SCADA/dll/ModbusDriver.dll
Binary file not shown.

0 comments on commit cac0189

Please sign in to comment.