Commit 9cf9d490 authored by 潘栩锋's avatar 潘栩锋 🚴

IBC&收卷 完成 WS.json 创建。 以后Autogen_WS会是万能的。能转换 汇川HMI 与 昆仑HMI

parent 2edd15a4
$root_path = $PSScriptRoot
$src_path = $root_path + "\WS.xml"
$dest_path = $root_path + "\..\..\..\..\Project.FLY.IBC\FLY.IBC.UI.Server\bin\Debug\Gage1\WS.xml"
echo WS.xml
cp $src_path $dest_path
echo Ƴɹ
pause
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EPPlus" version="4.5.2.1" targetFramework="net461" />
<package id="Fody" version="3.2.16" targetFramework="net461" developmentDependency="true" />
<package id="PropertyChanged.Fody" version="2.5.13" targetFramework="net461" />
</packages>
\ No newline at end of file
This diff is collapsed.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\PropertyChanged.Fody.2.5.13\build\PropertyChanged.Fody.props" Condition="Exists('..\packages\PropertyChanged.Fody.2.5.13\build\PropertyChanged.Fody.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
......@@ -45,17 +44,6 @@
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="EPPlus, Version=4.5.2.1, Culture=neutral, PublicKeyToken=ea159fdaa78159a1, processorArchitecture=MSIL">
<HintPath>..\packages\EPPlus.4.5.2.1\lib\net40\EPPlus.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MISC">
<HintPath>..\..\dll\MISC.dll</HintPath>
</Reference>
<Reference Include="PropertyChanged, Version=2.5.13.0, Culture=neutral, PublicKeyToken=ee3ee20bcf148ddd, processorArchitecture=MSIL">
<HintPath>..\packages\PropertyChanged.Fody.2.5.13\lib\net452\PropertyChanged.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Data" />
......@@ -78,6 +66,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="ClassList.cs" />
<Compile Include="DevMapperRule.cs" />
<Compile Include="WS_ItemInfo.cs" />
<Page Include="MainWindow.xaml">
......@@ -115,7 +104,6 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="app.config" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
......@@ -128,15 +116,21 @@
<ItemGroup>
<Resource Include="FodyWeavers.xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Costura.Fody">
<Version>4.1.0</Version>
</PackageReference>
<PackageReference Include="EPPlus">
<Version>4.5.3.2</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>12.0.3</Version>
</PackageReference>
<PackageReference Include="PropertyChanged.Fody">
<Version>3.2.4</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\PropertyChanged.Fody.2.5.13\build\PropertyChanged.Fody.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\PropertyChanged.Fody.2.5.13\build\PropertyChanged.Fody.props'))" />
<Error Condition="!Exists('..\packages\Fody.3.2.16\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.3.2.16\build\Fody.targets'))" />
</Target>
<Import Project="..\packages\Fody.3.2.16\build\Fody.targets" Condition="Exists('..\packages\Fody.3.2.16\build\Fody.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
......
using OfficeOpenXml;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Autogen_WS
{
/// <summary>
/// 类表
/// </summary>
public class ClassList
{
public List<ClassInfo> classInfos = new List<ClassInfo>();
/// <summary>
/// 读取设备转换表
/// </summary>
/// <returns></returns>
public bool Load(string xlsxfile)
{
classInfos.Clear();
/// <summary>
/// 类名
/// </summary>
int i_className = 1;
/// <summary>
/// 表名
/// </summary>
int i_tableName = 2;
/// <summary>
/// 单例模式
/// </summary>
int i_isSingleton = 3;
/// <summary>
/// 实例名
/// </summary>
int i_objectName = 4;
using (ExcelPackage packages = new ExcelPackage(new FileInfo(xlsxfile)))
{
using (ExcelWorksheet sheet = packages.Workbook.Worksheets["类表"])
{
int iRow = 2;
int i = iRow - 1;
while (true)
{
i++;
ClassInfo classInfo = new ClassInfo();
try
{
classInfo.className = sheet.Cells[i, i_className].Value.ToString();
classInfo.tableName = sheet.Cells[i, i_tableName].Value.ToString();
string isSingleton_str = sheet.Cells[iRow, i_isSingleton].Value.ToString();
if (!string.IsNullOrEmpty(isSingleton_str))
{
if (Regex.IsMatch(isSingleton_str, "Y"))
{
classInfo.isSingleton = true;
}
}
classInfo.objectName = sheet.Cells[i, i_objectName].Value.ToString();
}
catch
{
//完成,没有数据了
break;
}
if (string.IsNullOrEmpty(classInfo.className)) break;
if (string.IsNullOrEmpty(classInfo.tableName)) return false;
if (string.IsNullOrEmpty(classInfo.objectName)) return false;
classInfos.Add(classInfo);
}
}
}
if (classInfos.Count == 0)
return false;
return true;
}
}
public class ClassInfo
{
/// <summary>
/// 类名
/// </summary>
public string className;
/// <summary>
/// 表名
/// </summary>
public string tableName;
/// <summary>
/// 单例模式
/// </summary>
public bool isSingleton;
/// <summary>
/// 实例名
/// </summary>
public string objectName;
}
}
......@@ -9,9 +9,12 @@ using System.Text.RegularExpressions;
namespace Autogen_WS
{
public class DeviceAddr
/// <summary>
/// 设备地址
/// </summary>
public class DeviceAddrList
{
public List<string> EP = new List<string>();
public List<DeviceAddrInfo> deviceAddrInfos = new List<DeviceAddrInfo>();
/// <summary>
/// 读取设备转换表
......@@ -19,11 +22,10 @@ namespace Autogen_WS
/// <returns></returns>
public bool Load(string xlsxfile)
{
EP.Clear();
deviceAddrInfos.Clear();
int i_deviceno = 1;//设备序号
int i_ep = 2;//ep
int i_deviceName = 1;
int i_ep = 2;
using (ExcelPackage packages = new ExcelPackage(new FileInfo(xlsxfile)))
......@@ -35,12 +37,11 @@ namespace Autogen_WS
while (true)
{
i++;
string str_dev;
string str_ep;
DeviceAddrInfo deviceAddrInfo = new DeviceAddrInfo();
try
{
str_dev = sheet.Cells[i, i_deviceno].Value.ToString();
str_ep = sheet.Cells[i, i_ep].Value.ToString();
deviceAddrInfo.deviceName = sheet.Cells[i, i_deviceName].Value.ToString();
deviceAddrInfo.ep = sheet.Cells[i, i_ep].Value.ToString();
}
catch
{
......@@ -48,16 +49,29 @@ namespace Autogen_WS
break;
}
if (string.IsNullOrEmpty(str_dev)) break;
if (string.IsNullOrEmpty(deviceAddrInfo.deviceName)) break;
if (string.IsNullOrEmpty(deviceAddrInfo.ep)) return false;
EP.Add(str_ep);
deviceAddrInfos.Add(deviceAddrInfo);
}
}
}
if (EP.Count == 0)
if (deviceAddrInfos.Count == 0)
return false;
return true;
}
}
public class DeviceAddrInfo
{
/// <summary>
/// 设备名称
/// </summary>
public string deviceName;
/// <summary>
/// 地址&端口
/// </summary>
public string ep;
}
}
<?xml version="1.0" encoding="utf-8"?>
<Weavers>
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<PropertyChanged />
<Costura />
</Weavers>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="PropertyChanged" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:attribute name="InjectOnPropertyNameChanged" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if the On_PropertyName_Changed feature is enabled.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="EventInvokerNames" type="xs:string">
<xs:annotation>
<xs:documentation>Used to change the name of the method that fires the notify event. This is a string that accepts multiple values in a comma separated form.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="CheckForEquality" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should be inserted. If false, equality checking will be disabled for the project.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="CheckForEqualityUsingBaseEquals" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should use the Equals method resolved from the base class.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="UseStaticEqualsFromBase" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should use the static Equals method resolved from the base class.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="Costura" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:all>
<xs:element minOccurs="0" maxOccurs="1" name="ExcludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="IncludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="Unmanaged32Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="Unmanaged64Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 64 bit assembly names to include, delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="PreloadOrder" type="xs:string">
<xs:annotation>
<xs:documentation>The order of preloaded assemblies, delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:all>
<xs:attribute name="CreateTemporaryAssemblies" type="xs:boolean">
<xs:annotation>
<xs:documentation>This will copy embedded files to disk before loading them into memory. This is helpful for some scenarios that expected an assembly to be loaded from a physical file.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IncludeDebugSymbols" type="xs:boolean">
<xs:annotation>
<xs:documentation>Controls if .pdbs for reference assemblies are also embedded.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="DisableCompression" type="xs:boolean">
<xs:annotation>
<xs:documentation>Embedded assemblies are compressed by default, and uncompressed when they are loaded. You can turn compression off with this option.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="DisableCleanup" type="xs:boolean">
<xs:annotation>
<xs:documentation>As part of Costura, embedded assemblies are no longer included as part of the build. This cleanup can be turned off.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="LoadAtModuleInit" type="xs:boolean">
<xs:annotation>
<xs:documentation>Costura by default will load as part of the module initialization. This flag disables that behavior. Make sure you call CosturaUtility.Initialize() somewhere in your code.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IgnoreSatelliteAssemblies" type="xs:boolean">
<xs:annotation>
<xs:documentation>Costura will by default use assemblies with a name like 'resources.dll' as a satellite resource and prepend the output path. This flag disables that behavior.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="ExcludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with |</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IncludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to include from the default action of "embed all Copy Local references", delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="Unmanaged32Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="Unmanaged64Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 64 bit assembly names to include, delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="PreloadOrder" type="xs:string">
<xs:annotation>
<xs:documentation>The order of preloaded assemblies, delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
\ No newline at end of file
......@@ -18,18 +18,12 @@
</Grid>
<GroupBox Header="输出选项" >
<StackPanel Orientation="Vertical" MaxHeight="80">
<StackPanel MaxHeight="80">
<GroupBox>
<StackPanel Orientation="Vertical">
<StackPanel >
<CheckBox Content="生成cs" Margin="5" IsChecked="{Binding IsCreateCSharp}" />
<StackPanel Orientation="Horizontal">
<Button Grid.Column="2" Content="浏 览" Height="23" Margin="5" Width="65" Click="button4_Click" />
<TextBlock Grid.Column="1" Text="{Binding CSharpPath}" Margin="5" />
</StackPanel>
</StackPanel>
</GroupBox>
</StackPanel>
</GroupBox>
</StackPanel>
......
......@@ -15,6 +15,7 @@ using System.IO;
using Microsoft.Win32;
using System.Threading;
using System.ComponentModel;
using System.Threading.Tasks;
namespace Autogen_WS
{
......@@ -48,39 +49,21 @@ namespace Autogen_WS
InitializeComponent();
di = new DataInfos();
this.DataContext = di;
grid_mainwindow.DataContext = this;
}
void Gen(object param)
di.ErrorMsgbox = (string msg) =>
{
di.LoadXlsxFile();
if (IsCreateCSharp)
this.Dispatcher.BeginInvoke(new Action<string>((string _msg) =>
{
#region 生成WeighterC属性代码
di.Gen_CS();
#endregion
}
#region 生成WS.xml
di.Gen_WS_XML();
#endregion
MessageBox.Show(_msg);
}), msg);
this.Dispatcher.BeginInvoke(new Action(() =>
{
};
this.DataContext = di;
grid_mainwindow.DataContext = this;
MessageBox.Show("完成");
}), null);
}
private void button1_Click(object sender, RoutedEventArgs e)
private async void button1_Click(object sender, RoutedEventArgs e)
{
FileInfo fi;
......@@ -99,27 +82,29 @@ namespace Autogen_WS
return;
}
if (IsCreateCSharp)
bool ret = await Task.Factory.StartNew<bool>(() =>
{
try
{
fi = new FileInfo(CSharpPath);
}
catch
//加载xlsx
if (!di.LoadXlsxFile(XlsxPath))
return false;
//生成.cs文件
if (IsCreateCSharp)
{
MessageBox.Show("请选择.cs文件....", "Error");
return;
if (!di.Gen_CS())
return false;
}
if (!fi.Exists)
//生成WS.xml
return di.Gen_WS_XML();
});
if (ret)
{
MessageBox.Show(".cs不存在!", "Error");
return;
}
MessageBox.Show("完成");
}
di.XlsxFile = XlsxPath;
di.CSharpPath = CSharpPath;
Thread t = new Thread(Gen);
t.Start();
}
private void button2_Click(object sender, RoutedEventArgs e)
......
......@@ -13,7 +13,7 @@ namespace Autogen_WS
{
public class PLCDevice
{
public IPEndPoint EP { get; set; }
public string EP { get; set; }
}
public class PLCVariable
......@@ -52,14 +52,5 @@ namespace Autogen_WS
public List<PLCDevice> Devices = new List<PLCDevice>();
public List<PLCVariable> Variables = new List<PLCVariable>();
public void Load(string filepath)
{
Misc.SaveToXmlHepler.Load(filepath, this);
}
public void Save(string filepath)
{
Misc.SaveToXmlHepler.Save(filepath, this);
}
}
}
......@@ -8,36 +8,43 @@ namespace Autogen_WS
{
public class WS_ItemInfo
{
/// <summary>
/// 属性描述
/// </summary>
public string propDescription;
/// <summary>
/// 属性名
/// </summary>
public string propName;
/// <summary>
/// 属性描述
/// 数据类型, bool, float, uint16, int16, uint32, int32
/// </summary>
public string propDescription;
public string typeName;
/// <summary>
/// plc 序号
/// 放大
/// </summary>
public int plc_index = 0;
public double scale = 1;
/// <summary>
/// 寄存器类型 0,1,3,4
/// 报警
/// </summary>
public string reg_type;
public bool isError = false;
/// <summary>
/// 地址
///报警触发条件 true=ON时触发, false=OFF时触发
/// </summary>
public int mb_addr = -1;
public bool trigger = true;
/// <summary>
/// 数据类型, 与寄存器类型不同, bool, float, UInt16
/// plc 序号
/// </summary>
public string typeName;
public int plcIndex = 0;
/// <summary>
/// 放大
/// 寄存器类型 0,1,3,4
/// </summary>
public double scale = 1;
public string regType;
/// <summary>
/// 地址
/// </summary>
public int mbAddr = -1;
/// <summary>
/// 对象名
......@@ -50,18 +57,22 @@ namespace Autogen_WS
public WS_ItemInfo Clone()
{
WS_ItemInfo ii = new WS_ItemInfo();
ii.propName = propName;
ii.propDescription = propDescription;
ii.plc_index = plc_index;
ii.reg_type = reg_type;
ii.mb_addr = mb_addr;
ii.propName = propName;
ii.typeName = typeName;
ii.scale = scale;
ii.isError = isError;
ii.trigger = trigger;
ii.plcIndex = plcIndex;
ii.regType = regType;
ii.mbAddr = mbAddr;
ii.objectName = objectName;
return ii;
}
public string GetPropertyType()
public string GetPropertyType()//转为C#类型,只有bool 与 float
{
if (typeName == "bool")
return "bool";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment