|
@@ -6,7 +6,9 @@ using System.Linq;
|
|
|
using NewLife;
|
|
|
using NewLife.Data;
|
|
|
using NewLife.Log;
|
|
|
+using NewLife.Model;
|
|
|
using NewLife.Net;
|
|
|
+using NewLife.Net.Handlers;
|
|
|
using NewLife.Reflection;
|
|
|
using NewLife.Serialization;
|
|
|
using OPC_Client;
|
|
@@ -28,6 +30,7 @@ namespace ScadaTcpService
|
|
|
Log = XTrace.Log,
|
|
|
SessionLog = XTrace.Log
|
|
|
};
|
|
|
+ _tcpServer.Add<StandardCodec>();
|
|
|
_tcpServer.Start();
|
|
|
CreateScada();
|
|
|
|
|
@@ -64,7 +67,8 @@ namespace ScadaTcpService
|
|
|
c.Value.batchNum,
|
|
|
c.Value.id,
|
|
|
c.Value.quality,
|
|
|
- c.Value.DateTime1
|
|
|
+ c.Value.DateTime1,
|
|
|
+ c.Value.value
|
|
|
})
|
|
|
.ToList();
|
|
|
var sendData = new
|
|
@@ -76,7 +80,7 @@ namespace ScadaTcpService
|
|
|
{
|
|
|
foreach (var item in InitDic.Where(c => c.Value))
|
|
|
{
|
|
|
- _tcpServer.GetSession(item.Key)?.Send(new Packet(sendData.ToJson().GetBytes()));
|
|
|
+ _tcpServer.GetSession(item.Key)?.SendMessage(new Packet(sendData.ToJson().GetBytes()));
|
|
|
}
|
|
|
|
|
|
|
|
@@ -117,10 +121,11 @@ namespace ScadaTcpService
|
|
|
c.batchNum,
|
|
|
c.id,
|
|
|
c.quality,
|
|
|
- c.DateTime1
|
|
|
+ c.DateTime1,
|
|
|
+ c.value
|
|
|
}).ToList()
|
|
|
};
|
|
|
- Send(new Packet(data.ToJson().GetBytes()));
|
|
|
+ SendMessage(new Packet(data.ToJson().GetBytes()));
|
|
|
base.OnConnected();
|
|
|
}
|
|
|
|
|
@@ -133,9 +138,13 @@ namespace ScadaTcpService
|
|
|
|
|
|
protected override void OnReceive(ReceivedEventArgs e)
|
|
|
{
|
|
|
- if (e.Packet?.ToStr().ToLower().Contains("start") != true) return;
|
|
|
- if (ScadaService.InitDic.ContainsKey(ID))
|
|
|
- ScadaService.InitDic[ID] = true;
|
|
|
+ if (e.Message is Packet pk)
|
|
|
+ {
|
|
|
+ if (pk.ToStr().ToLower().Contains("start") != true) return;
|
|
|
+ if (ScadaService.InitDic.ContainsKey(ID))
|
|
|
+ ScadaService.InitDic[ID] = true;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|