[go: nahoru, domu]

Skip to content

Commit

Permalink
Add IODriver All Run
Browse files Browse the repository at this point in the history
  • Loading branch information
User authored and User committed May 31, 2019
1 parent c0d7902 commit 01e6f6c
Show file tree
Hide file tree
Showing 149 changed files with 2,176 additions and 7,707 deletions.
4 changes: 4 additions & 0 deletions AdvancedScada.BaseService/BaseService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
<Project>{dcf54cf4-e611-46b1-8056-7f71aae0d9f5}</Project>
<Name>HMIException</Name>
</ProjectReference>
<ProjectReference Include="..\Drivers\AdvancedScada.IODriver\AdvancedScada.IODriver.csproj">
<Project>{09b71d40-9c34-44f8-bc1b-1b3380ead582}</Project>
<Name>AdvancedScada.IODriver</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\licenses.licx" />
Expand Down
53 changes: 6 additions & 47 deletions AdvancedScada.BaseService/ReadService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using AdvancedScada.DriverBase;
using AdvancedScada.IBaseService;
using AdvancedScada.IBaseService.Common;
using AdvancedScada.IODriver;
using AdvancedScada.Management.BLManager;
using Microsoft.Win32;
using System;
Expand All @@ -19,52 +20,25 @@ public class ReadService : IReadService
private bool RUN_APPLICATION;

public IServiceCallback EventDataChanged;
public IServiceDriver iServiceDriver = null;
DriverHelper driverHelper = new DriverHelper();
readonly Functions frame = Functions.GetFunctions();
private static object mutex = new object();
private static ReadService _instance;

object mutexStop = new object();
object mutexUpdate = new object();
object mutexStart = new object();
object mutexDispose = new object();
object mutexWrite = new object();
private ChannelManager objChannelManager;

public static ReadService GetReadService()
{
lock (mutex)
{
if (_instance == null)
{
_instance = new ReadService();
}
}

return _instance;
}


public ReadService()
{

objChannelManager = ChannelManager.GetChannelManager();

}
public IServiceDriver GetAssemblyDrivers(string ChannelTypes)
{
try
{


iServiceDriver = frame.GetAssembly($@"\AdvancedScada.{ChannelTypes}.Core.dll",
$"AdvancedScada.{ChannelTypes}.Core.DataService");
}
catch (System.Exception ex)
{

var err = new HMIException.ScadaException(this.GetType().Name, ex.Message);
}
return iServiceDriver;
}

public void Connection()
{
Expand Down Expand Up @@ -139,27 +113,12 @@ public void WriteTag(string tagName, dynamic value)
{
try
{
if (objChannelManager == null) return;

lock (mutexWrite)
{


var strArrays = tagName.Split('.');
var str = $"{strArrays[0]}.{strArrays[1]}";
foreach (var Channels in objChannelManager.Channels)
{
foreach (var dv in Channels.Devices)
{
var bEquals = $"{Channels.ChannelName}.{dv.DeviceName}".Equals(str);
if (bEquals)
{
iServiceDriver = GetAssemblyDrivers(Channels.ChannelTypes.Insert(0, "X"));

iServiceDriver?.WriteTag(tagName, value);

}
}
}
driverHelper?.WriteTag(tagName, value);
}
}
catch (System.Exception ex)
Expand Down
102 changes: 25 additions & 77 deletions AdvancedScada.BaseService/ServiceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,122 +6,70 @@
using AdvancedScada.DriverBase;
using AdvancedScada.IBaseService;
using AdvancedScada.IBaseService.Common;
using AdvancedScada.IODriver;
using AdvancedScada.Management.BLManager;
using Microsoft.Win32;

namespace AdvancedScada.BaseService
{
public class ServiceBase : IGetServiceBase
public class ServiceBase
{

IServiceDriver iServiceDriverAll = null;

private static readonly object mutex = new object();
private ushort _SerialNo;
DriverHelper driverHelper = new DriverHelper();
object mutexStop = new object();
public ServiceBase()
{
objChannelManager = ChannelManager.GetChannelManager();
RequestsDriver = new Dictionary<string, IServiceDriver>(1024);

}

public Dictionary<string, IServiceDriver> RequestsDriver { get; set; }


public IServiceDriver GetStartService()
public bool GetStartService()
{

try
{
HOST = $"{Registry.GetValue("HKEY_CURRENT_USER\\Software\\FormConfiguration", "IPAddress", null)}";
PORT = ushort.Parse(
$"{Registry.GetValue("HKEY_CURRENT_USER\\Software\\FormConfiguration", "Port", null)}");


var xmlFile = objChannelManager.ReadKey(objChannelManager.XML_NAME_DEFAULT);
if (string.IsNullOrEmpty(xmlFile) || string.IsNullOrWhiteSpace(xmlFile))
return null;
if (string.IsNullOrEmpty(xmlFile) || string.IsNullOrWhiteSpace(xmlFile)) return false;

lock (mutex)
{
RequestsDriver.Clear();

objChannelManager.Channels.Clear();
TagCollection.Tags.Clear();
var channels = objChannelManager.GetChannels(xmlFile);
var frame = Functions.GetFunctions();
foreach (var item in channels)
{
iServiceDriverAll =
frame.GetAssembly($@"\AdvancedScada.{item.ChannelTypes.Insert(0, "X")}.Core.dll",
$"AdvancedScada.{item.ChannelTypes.Insert(0, "X")}.Core.DataService");


driverHelper.InitializeService(channels);
driverHelper.Connect();

if (iServiceDriverAll != null)
iServiceDriverAll.InitializeService(item);
}

foreach (var item in channels)
{
_SerialNo = (ushort) (_SerialNo++ % 255 + 1);
iServiceDriverAll =
frame.GetAssembly($@"\AdvancedScada.{item.ChannelTypes.Insert(0, "X")}.Core.dll",
$"AdvancedScada.{item.ChannelTypes.Insert(0, "X")}.Core.DataService");

if (RequestsDriver.ContainsKey(item.ChannelTypes))
{
}
else
{
RequestsDriver.Add(item.ChannelTypes, iServiceDriverAll);
if (iServiceDriverAll != null)
iServiceDriverAll.Connect();
}

return true;

}
}
}
catch (Exception ex)
{
var err = new HMIException.ScadaException(GetType().Name, ex.Message);
}

return iServiceDriverAll;
}
public IServiceDriver GetAssemblyDrivers(string ChannelTypes)
{
try
{

var frame = Functions.GetFunctions();
iServiceDriverAll = frame.GetAssembly($@"\AdvancedScada.{ChannelTypes}.Core.dll",
$"AdvancedScada.{ChannelTypes}.Core.DataService");
}
catch (System.Exception ex)
{

var err = new HMIException.ScadaException(this.GetType().Name, ex.Message);
}
return iServiceDriverAll;
return true;
}
public IServiceDriver GetStopService()

public bool GetStopService()
{
try
{
if (objChannelManager == null) return null;

lock (mutexStop)
{
RequestsDriver.Clear();
var channels = objChannelManager.Channels;
foreach (var Ch in channels)
{
iServiceDriverAll = GetAssemblyDrivers(Ch.ChannelTypes.Insert(0, "X"));
if (RequestsDriver.ContainsKey(Ch.ChannelTypes))
{

}
else
{
RequestsDriver.Add(Ch.ChannelTypes, iServiceDriverAll);

iServiceDriverAll?.Disconnect();
}

}

driverHelper.Disconnect();

}
}
Expand All @@ -130,7 +78,7 @@ public IServiceDriver GetStopService()

var err = new HMIException.ScadaException(this.GetType().Name, ex.Message);
}
return iServiceDriverAll;
return true;
}

public NetTcpBinding GetNetTcpBinding()
Expand All @@ -150,7 +98,7 @@ public NetTcpBinding GetNetTcpBinding()
},
MaxBufferSize = 1000000,
MaxBufferPoolSize = 1000000,
MaxReceivedMessageSize = 2147483647L,
MaxReceivedMessageSize = 1000000,
ReceiveTimeout = TimeSpan.FromMinutes(2.0),
SendTimeout = TimeSpan.FromMinutes(2.0),
OpenTimeout = TimeSpan.FromDays(15.0),
Expand Down
10 changes: 5 additions & 5 deletions AdvancedScada.Controls/Controls.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@
<PropertyGroup>
</PropertyGroup>
<ItemGroup>
<Reference Include="DevExpress.Data.v18.2, Version=18.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL">
<Reference Include="DevExpress.Data.v19.1, Version=19.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="DevExpress.Printing.v18.2.Core, Version=18.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL">
<Reference Include="DevExpress.Printing.v19.1.Core, Version=19.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="DevExpress.Utils.v18.2, Version=18.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL">
<Reference Include="DevExpress.Utils.v19.1, Version=19.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="DevExpress.XtraBars.v18.2, Version=18.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL">
<Reference Include="DevExpress.XtraBars.v19.1, Version=19.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="DevExpress.XtraEditors.v18.2, Version=18.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL">
<Reference Include="DevExpress.XtraEditors.v19.1, Version=19.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.CSharp" />
Expand Down
11 changes: 2 additions & 9 deletions AdvancedScada.Controls/WCFChannelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ namespace AdvancedScada.Controls
public class WCFChannelFactory
{
private static IReadService client;
public const string Driver = "Driver";
public static ushort PORT = 8090;
public static string HOST = "localhost";
private static string ChannelTypes = string.Empty;

static object myLockRead = new object();

public static void Write(string PLCAddressClick, dynamic Value)
Expand All @@ -29,11 +26,7 @@ public static void Write(string PLCAddressClick, dynamic Value)
{
lock (myLockRead)
{
ChannelTypes =
$"{Registry.GetValue("HKEY_CURRENT_USER\\Software\\FormConfiguration", "ChannelTypes", null)}";
var frame = Functions.GetFunctions();
IGetServiceBase iServiceDriver = frame.GetAssemblyService(@"\AdvancedScada.BaseService.dll", "AdvancedScada.BaseService.ServiceBase");
if (iServiceDriver != null)

client = ServiceBaseClient.CreateChannelTools();
client.WriteTag(PLCAddressClick, Value);
}
Expand Down
10 changes: 5 additions & 5 deletions AdvancedScada.HMI/HMI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
<ApplicationIcon>this.Ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="DevExpress.BonusSkins.v18.2, Version=18.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
<Reference Include="DevExpress.Data.v18.2, Version=18.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
<Reference Include="DevExpress.Printing.v18.2.Core, Version=18.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
<Reference Include="DevExpress.Utils.v18.2, Version=18.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
<Reference Include="DevExpress.XtraEditors.v18.2, Version=18.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
<Reference Include="DevExpress.BonusSkins.v19.1, Version=19.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
<Reference Include="DevExpress.Data.v19.1, Version=19.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
<Reference Include="DevExpress.Printing.v19.1.Core, Version=19.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
<Reference Include="DevExpress.Utils.v19.1, Version=19.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
<Reference Include="DevExpress.XtraEditors.v19.1, Version=19.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
<Reference Include="Microsoft.ReportViewer.Common, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.ReportingServices.ReportViewerControl.Winforms.150.900.148\lib\net40\Microsoft.ReportViewer.Common.dll</HintPath>
</Reference>
Expand Down
14 changes: 7 additions & 7 deletions AdvancedScada.HMI/HMI.csproj.bak
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
<ApplicationIcon>this.Ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="DevExpress.BonusSkins.v18.2, Version=18.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
<Reference Include="DevExpress.Data.v18.2, Version=18.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
<Reference Include="DevExpress.Printing.v18.2.Core, Version=18.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
<Reference Include="DevExpress.Utils.v18.2, Version=18.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
<Reference Include="DevExpress.XtraEditors.v18.2, Version=18.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
<Reference Include="DevExpress.BonusSkins.v18.2, Version=18.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
<Reference Include="DevExpress.Data.v18.2, Version=18.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
<Reference Include="DevExpress.Printing.v18.2.Core, Version=18.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
<Reference Include="DevExpress.Utils.v18.2, Version=18.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
<Reference Include="DevExpress.XtraEditors.v18.2, Version=18.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
<Reference Include="Microsoft.ReportViewer.Common, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.ReportingServices.ReportViewerControl.Winforms.150.900.148\lib\net40\Microsoft.ReportViewer.Common.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -167,9 +167,9 @@
<Project>{A6981D28-2360-4212-8EEF-F78C117EB615}</Project>
<Name>Management</Name>
</ProjectReference>
<ProjectReference Include="..\Drivers\AdvancedScada.ErorrPLC\ErorrPLC.csproj">
<ProjectReference Include="..\Drivers\AdvancedScada.ErorrPLC\HMIException.csproj">
<Project>{dcf54cf4-e611-46b1-8056-7f71aae0d9f5}</Project>
<Name>ErorrPLC</Name>
<Name>HMIException</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
Expand Down
14 changes: 3 additions & 11 deletions AdvancedScada.HMI/MainForm/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public partial class MainForm : DevExpress.XtraEditors.XtraForm
public double[] TankMixWeight;
private double[] TankMixWeightFinel;
#endregion
public IGetServiceBase iServiceDriver = null;

public IReadService client = null;
public string GetDriverTypes()
{
Expand All @@ -35,20 +35,12 @@ public MainForm()
{
var functions = Functions.GetFunctions();

iServiceDriver = functions.GetAssemblyService();
if (iServiceDriver != null)
{
//iServiceDriver.GetStartService(false);


ServiceBaseClient.GetStartClient();
client = ServiceBaseClient.CreateChannelTools();
client?.Connection();

}
else
{

}




Expand Down
Loading

0 comments on commit 01e6f6c

Please sign in to comment.