init: 导入项目到 meswork Gitea
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
using Global;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
//using static SqlManage.ExecSql;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
namespace DTTest
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public partial class E { }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public partial class ModelManagement
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="ar"></param>
|
||||
private void TheEnd(IAsyncResult ar)
|
||||
{
|
||||
var dn = (GeneralFunction)ar.AsyncState;
|
||||
dn.EndInvoke(ar);
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="ar"></param>
|
||||
public void SignalWriteTask_0(IAsyncResult ar)
|
||||
{
|
||||
var dn = (Func)ar.AsyncState;
|
||||
dn.EndInvoke(ar);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
103
DataMirrorTools_Simulator/ModelBasic/Base/CopyFilesHandler.cs
Normal file
103
DataMirrorTools_Simulator/ModelBasic/Base/CopyFilesHandler.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
namespace CopyFiles
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class CopyFilesHandler
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="strSouPath"></param>
|
||||
/// <param name="strDesPath"></param>
|
||||
public void CopyFiles(string strSouPath, string strDesPath)
|
||||
{
|
||||
Directory.CreateDirectory(strDesPath);
|
||||
|
||||
if (!Directory.Exists(strSouPath)) return;
|
||||
|
||||
string[] directories = Directory.GetDirectories(strSouPath);
|
||||
|
||||
if (directories.Length > 0)
|
||||
{
|
||||
foreach (string d in directories)
|
||||
{
|
||||
CopyFiles(d, strDesPath + d.Substring(d.LastIndexOf("\\")));
|
||||
}
|
||||
}
|
||||
|
||||
string[] files = Directory.GetFiles(strSouPath);
|
||||
|
||||
if (files.Length > 0)
|
||||
{
|
||||
foreach (string s in files)
|
||||
{
|
||||
string targetPath = strDesPath + s.Substring(s.LastIndexOf("\\"));
|
||||
|
||||
if (File.Exists(targetPath))
|
||||
{
|
||||
File.Delete(targetPath);
|
||||
}
|
||||
File.Copy(s, targetPath);
|
||||
currCount++;
|
||||
Console.WriteLine("" + currCount.ToString() + " / " + maxCount + " -> " + targetPath);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int currCount = 0;
|
||||
|
||||
int maxCount = 0;
|
||||
|
||||
List<String> fileNameLiat = new List<String>();
|
||||
|
||||
|
||||
public void GetFileCount(string strSouPath)
|
||||
{
|
||||
if (!Directory.Exists(strSouPath)) return ;
|
||||
|
||||
string[] directories = Directory.GetDirectories(strSouPath);
|
||||
|
||||
if (directories.Length > 0)
|
||||
{
|
||||
foreach (string d in directories)
|
||||
{
|
||||
GetFileCount(d);
|
||||
}
|
||||
}
|
||||
|
||||
string[] files = Directory.GetFiles(strSouPath);
|
||||
|
||||
if (files.Length > 0)
|
||||
{
|
||||
foreach (string s in files)
|
||||
{
|
||||
fileNameLiat.Add(s);
|
||||
}
|
||||
}
|
||||
maxCount = fileNameLiat.Count();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
191
DataMirrorTools_Simulator/ModelBasic/Base/ExtendMethod.cs
Normal file
191
DataMirrorTools_Simulator/ModelBasic/Base/ExtendMethod.cs
Normal file
@@ -0,0 +1,191 @@
|
||||
using Global;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
//using static DataLinkMesWork.SQLCommon;
|
||||
//using static SqlManage.ExecSql;
|
||||
using System.Reflection;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
namespace DTTest
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public partial class E { }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public partial class ModelManagement
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
namespace BT.Preservation.Models
|
||||
{
|
||||
public static class ExtendMethod
|
||||
{
|
||||
/// <summary>
|
||||
/// DataTable转成List
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="dt"></param>
|
||||
/// <returns></returns>
|
||||
public static List<T> ToDataList<T>(this DataTable dt)
|
||||
{
|
||||
var list = new List<T>();
|
||||
var plist = new List<PropertyInfo>(typeof(T).GetProperties());
|
||||
foreach (DataRow item in dt.Rows)
|
||||
{
|
||||
T s = Activator.CreateInstance<T>();
|
||||
for (int i = 0; i < dt.Columns.Count; i++)
|
||||
{
|
||||
PropertyInfo info = plist.Find(p => p.Name == dt.Columns[i].ColumnName);
|
||||
if (info != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!Convert.IsDBNull(item[i]))
|
||||
{
|
||||
object v = null;
|
||||
if (info.PropertyType.ToString().Contains("System.Nullable"))
|
||||
{
|
||||
v = Convert.ChangeType(item[i], Nullable.GetUnderlyingType(info.PropertyType));
|
||||
}
|
||||
else
|
||||
{
|
||||
v = Convert.ChangeType(item[i], info.PropertyType);
|
||||
}
|
||||
info.SetValue(s, v, null);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogNet.LogisTrac.WriteLog(typeof(ExtendMethod), ex);
|
||||
|
||||
throw new Exception("字段[" + info.Name + "]转换出错," + ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
list.Add(s);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DataTable转成Dto
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="dt"></param>
|
||||
/// <returns></returns>
|
||||
public static T ToDataDto<T>(this DataTable dt)
|
||||
{
|
||||
T s = Activator.CreateInstance<T>();
|
||||
if (dt == null || dt.Rows.Count == 0)
|
||||
{
|
||||
return s;
|
||||
}
|
||||
var plist = new List<PropertyInfo>(typeof(T).GetProperties());
|
||||
for (int i = 0; i < dt.Columns.Count; i++)
|
||||
{
|
||||
PropertyInfo info = plist.Find(p => p.Name == dt.Columns[i].ColumnName);
|
||||
if (info != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!Convert.IsDBNull(dt.Rows[0][i]))
|
||||
{
|
||||
object v = null;
|
||||
if (info.PropertyType.ToString().Contains("System.Nullable"))
|
||||
{
|
||||
v = Convert.ChangeType(dt.Rows[0][i], Nullable.GetUnderlyingType(info.PropertyType));
|
||||
}
|
||||
else
|
||||
{
|
||||
v = Convert.ChangeType(dt.Rows[0][i], info.PropertyType);
|
||||
}
|
||||
info.SetValue(s, v, null);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogNet.LogisTrac.WriteLog(typeof(ExtendMethod), ex);
|
||||
|
||||
|
||||
throw new Exception("字段[" + info.Name + "]转换出错," + ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将实体集合转换为DataTable
|
||||
/// </summary>
|
||||
/// <typeparam name="T">实体类型</typeparam>
|
||||
/// <param name="entities">实体集合</param>
|
||||
public static DataTable ToDataTable<T>(List<T> entities)
|
||||
{
|
||||
var result = CreateTable<T>();
|
||||
FillData(result, entities);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建表
|
||||
/// </summary>
|
||||
private static DataTable CreateTable<T>()
|
||||
{
|
||||
var result = new DataTable();
|
||||
var type = typeof(T);
|
||||
foreach (var property in type.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance))
|
||||
{
|
||||
var propertyType = property.PropertyType;
|
||||
if ((propertyType.IsGenericType) && (propertyType.GetGenericTypeDefinition() == typeof(Nullable<>)))
|
||||
propertyType = propertyType.GetGenericArguments()[0];
|
||||
result.Columns.Add(property.Name, propertyType);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 填充数据
|
||||
/// </summary>
|
||||
private static void FillData<T>(DataTable dt, IEnumerable<T> entities)
|
||||
{
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
dt.Rows.Add(CreateRow(dt, entity));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建行
|
||||
/// </summary>
|
||||
private static DataRow CreateRow<T>(DataTable dt, T entity)
|
||||
{
|
||||
DataRow row = dt.NewRow();
|
||||
var type = typeof(T);
|
||||
foreach (var property in type.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance))
|
||||
{
|
||||
row[property.Name] = property.GetValue(entity) ?? DBNull.Value;
|
||||
}
|
||||
return row;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
using FileExplorer;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
//using System.Threading.Tasks;
|
||||
//using static SqlManage.ExecSql;
|
||||
//using System.Windows.Forms;
|
||||
|
||||
namespace DTTest
|
||||
{
|
||||
public partial class E { }
|
||||
public partial class ModelManagement
|
||||
{
|
||||
public void B_C_ExportModel(string modelName, string modelData)
|
||||
{
|
||||
// // ModelBasic.ErrDef.iErrHandler.ErrInfoTransmit("【收到的文件名】 = " + modelName);
|
||||
|
||||
var filepathGltf = PP.PCP.ModelFilePath + modelName + ".gltf";
|
||||
var filepathGlb = PP.PCP.ModelFilePath + modelName + ".glb";
|
||||
var cmd = " gltf-pipeline -i " + filepathGltf + " -o " + filepathGlb + " -b -d"+ " && del "+ filepathGltf;
|
||||
|
||||
if (File.Exists(filepathGltf))
|
||||
{
|
||||
File.Delete(filepathGltf);
|
||||
}
|
||||
|
||||
System.IO.File.WriteAllText(filepathGltf, modelData);
|
||||
|
||||
Thread tExec = new Thread(new ParameterizedThreadStart(ExecCmd));
|
||||
tExec.IsBackground = true;
|
||||
tExec.Start(cmd);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void ExecCmd(object cmd)
|
||||
{
|
||||
Cmd.InvokeCmd((string)cmd);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
1015
DataMirrorTools_Simulator/ModelBasic/Base/MM.Brush.Class.cs
Normal file
1015
DataMirrorTools_Simulator/ModelBasic/Base/MM.Brush.Class.cs
Normal file
File diff suppressed because it is too large
Load Diff
104
DataMirrorTools_Simulator/ModelBasic/Base/MM.Define.cs
Normal file
104
DataMirrorTools_Simulator/ModelBasic/Base/MM.Define.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
using Global;
|
||||
using ModelBasic;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
using WeifenLuo.WinFormsUI.Docking;
|
||||
|
||||
namespace DTTest
|
||||
{
|
||||
public partial class E { }
|
||||
public partial class ModelManagement : DockContent//,IModelManagement,IModelManagement3
|
||||
{
|
||||
/// <summary>
|
||||
/// 客户端对象
|
||||
/// </summary>
|
||||
private static ConLink.Enthernet.NetComplexClient clientLocal
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = null;
|
||||
|
||||
/// <summary>
|
||||
/// 行为对应对象
|
||||
/// </summary>
|
||||
Dictionary<String, ActControl> dc_ActCode_Object = new Dictionary<String, ActControl>();
|
||||
|
||||
#region 协议说明20200915,
|
||||
/*20200605 C->B发送播放协议 协议 DT|Robot|Subjection|ModelCode|00&-48&64&00&73&00&3
|
||||
DT|Device|Subjection|ModelCode|00&-48&64&00&73&00&1
|
||||
DT|FirstPosition|Subjection|ModelCode|00&-48&64&00&73&00&1
|
||||
DT|Frames|[{"i":ModelCode,"tx":-3669.57,"ty":843.59,"tz":885.98,"rx":0,"ry":90,"rz":0}]
|
||||
协议说明 0 数据类型 DT:数字孪生数据
|
||||
1 设备类型(如何驱动) Robot:机器人类型的设备,Device:普通设备,FirstPosition:普通设备运动无过程
|
||||
2 设备名字(模型隶属于,即父级)
|
||||
3 设备运动部件名称
|
||||
4 设备运动部件数据 普通设备 机器人设备
|
||||
0 X 0 J1
|
||||
1 Y 1 J2
|
||||
2 Z 2 J3
|
||||
3 RX 3 J4
|
||||
4 RY 4 J5
|
||||
5 RZ 5 J6
|
||||
6 预留 6 夹手状态
|
||||
20200605 C->B->C请求模型位置 协议 DT|Position|ModelCode
|
||||
DT|Position|ModelCode|00&-48&64&00&73&00
|
||||
协议说明 0 数据类型 DT:数字孪生数据
|
||||
1 指令 Position:表示请求位置
|
||||
2 设备运动部件名称
|
||||
3 设备运动部件返回的数据 0 X 0 J1
|
||||
1 Y 1 J2
|
||||
2 Z 2 J3
|
||||
3 RX 3 J4
|
||||
4 RY 4 J5
|
||||
5 RZ 5 J6
|
||||
6 预留 6 夹手状态
|
||||
20200605 C->B请求选中模型 协议 DT|Select|ModelCode
|
||||
协议说明 1 指令 Select:表示显示选中的模型
|
||||
2 设备运动部件名称
|
||||
20200713 C->B请求拖拽模型 协议 DT|DragMove|ModelCode
|
||||
DT|DragRotate|ModelCode
|
||||
协议说明 1 指令 Drag:表示模型出现操作标,可以拖拽(平移DragMove、旋转DragRotate)
|
||||
2 设备运动部件名称
|
||||
20200706 C->B通知模型显示(隐藏) 协议 DT|Visible|ModelCode|1
|
||||
协议说明 1 指令 Visible:表示模型显示、隐藏
|
||||
2 设备运动部件名称
|
||||
3 显示、隐藏 0、隐藏;1、显示
|
||||
20200714设计20200810废弃 B->C->B请求模型名称 协议 DT|RequestModelName
|
||||
DT|RequestModelName|{二维JSON}
|
||||
DT|RequestModelVisible
|
||||
DT|RequestModelVisible|{二维JSON}
|
||||
协议说明 1 指令 Request:表示请求模型名称、模型可见
|
||||
2 设备运动部件名称
|
||||
20200810 C->B通知行为播放 协议 DT|PlayAct|ActCode|1
|
||||
DT|PlayAct|ActCode|0
|
||||
协议说明 1 指令 PlayAct:表示播放行为
|
||||
2 设备运动部件名称
|
||||
3 播放、暂停 0、暂停;1、播放
|
||||
20200810 C->B通知重新加载播放数据 协议 DT|ReLoadAct
|
||||
协议说明 1 指令 ReLoadAct:表示重新加载行为数据
|
||||
20200812设计20200911废弃 C->B通知行为播放 协议 DT|PlayTagID|TagID|1
|
||||
DT|PlayTagID|TagID|0
|
||||
协议说明 1 指令 PlayTagID:表示用TagID播放行为
|
||||
2 设备运动部件名称
|
||||
3 播放、暂停 0、暂停;1、播放
|
||||
20200824 C->B绘制工艺路径 协议 DT|DrawPath|{}
|
||||
协议说明 1 指令 DrawPath:表示绘制路径指令
|
||||
2 {} [{"CraftCode": 1,"Visible": 1,"Point": [1,2,3.4,5,6,7,8,9,1.2]}]
|
||||
20200827 B->C网页选中模型后返回模型信息 协议 DT|ClickModel|{}
|
||||
协议说明 1 指令 ClickModel:表示点击模型后触发
|
||||
2 {} [{"ModelCode": 1,"ModelName": 1,"Visible": 1,"x": 11,"y": 11,"z": 11,"rx": 11,"ry": 11,"rz": 11}]
|
||||
3 说明 网页收到选择模型的指令(第29行:DT|Select|ModelCode),也应当返回此内容
|
||||
20200829 C->B请求改变模型透明度 协议 DT|ModelTransparent|ModelCode|1
|
||||
协议说明 1 指令 ModelTransparent:表示模型透明, 0-1:表示透明度 0完全透明 1 不透明
|
||||
2 设备运动部件名称
|
||||
20200831 C->B请求模型进行自转 协议 DT|ModelRotation|ModelCode|1
|
||||
协议说明 1 指令 ModelRotation:表示模型旋转, 0暂停 1 旋转
|
||||
2 设备运动部件名称
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using ExecJavaScript;
|
||||
using ModelBasic;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
//using WeifenLuo.WinFormsUI.Docking;
|
||||
//using static SqlManage.ExecSql;
|
||||
|
||||
namespace DTTest
|
||||
{
|
||||
public partial class E { }
|
||||
public partial class ModelManagement
|
||||
{
|
||||
|
||||
//static Dictionary<String, String> dc_Craft_Script = null;
|
||||
//ExecScript execScript = null;
|
||||
|
||||
//public void ReLoad_CraftAndScript()
|
||||
//{
|
||||
// dc_Craft_Script = SqlOperation.SqlCraft.Load_CraftAndScript();
|
||||
// execScript = new ExecScript();
|
||||
//}
|
||||
|
||||
|
||||
//public void RunScript(Dictionary<String, String> dc_TagID_PlcValue,string changedTagID)
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// if (dc_TagID_PlcValue == null)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// foreach (KeyValuePair<String, String> item in dc_Craft_Script)
|
||||
// {
|
||||
// var craftCode = item.Key;
|
||||
// var scriptText = item.Value;
|
||||
// if (scriptText.Contains(changedTagID))
|
||||
// {
|
||||
// var result = execScript.RunScript(dc_TagID_PlcValue, scriptText);
|
||||
// if (result == "1")
|
||||
// {
|
||||
// S_PlayAct(craftCode, "1");
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
// }
|
||||
// }
|
||||
// catch (Exception err)
|
||||
// {
|
||||
// // ModelBasic.ErrDef.iErrHandler.ErrInfoTransmit($"执行脚本错误!:{err.Message}");
|
||||
// }
|
||||
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
298
DataMirrorTools_Simulator/ModelBasic/Base/MM.MesWorkOpc.cs
Normal file
298
DataMirrorTools_Simulator/ModelBasic/Base/MM.MesWorkOpc.cs
Normal file
@@ -0,0 +1,298 @@
|
||||
using ModelBasic;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
//using WeifenLuo.WinFormsUI.Docking;
|
||||
//using static SqlManage.ExecSql;
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
namespace DTTest
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public partial class E { }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public partial class ModelManagement
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="dt_Signal"></param>
|
||||
/// <param name="dt_Device"></param>
|
||||
/// <returns></returns>
|
||||
public bool GetSignalTable(out DataTable dt_Signal, out DataTable dt_Device)
|
||||
{
|
||||
var b = false;
|
||||
|
||||
dt_Signal = CreateOpcSignalTable();
|
||||
dt_Device = CreateOpcDeviceTable();
|
||||
var dc_TagType_TypeIDAndLong = new Dictionary<String, String>();
|
||||
dc_TagType_TypeIDAndLong.Add("INT16","2,2");
|
||||
dc_TagType_TypeIDAndLong.Add("INT32","3,4");
|
||||
dc_TagType_TypeIDAndLong.Add("FLOAT", "4,4");
|
||||
dc_TagType_TypeIDAndLong.Add("UINT64", "7,8");
|
||||
dc_TagType_TypeIDAndLong.Add("STRING", "8,?");
|
||||
dc_TagType_TypeIDAndLong.Add("BOOL", "11,1");
|
||||
dc_TagType_TypeIDAndLong.Add("BYTE", "17,1");
|
||||
dc_TagType_TypeIDAndLong.Add("UINT16", "18,2");
|
||||
dc_TagType_TypeIDAndLong.Add("DOUBLE", "19,8");
|
||||
dc_TagType_TypeIDAndLong.Add("INT", "2,2");
|
||||
dc_TagType_TypeIDAndLong.Add("DINT", "3,4");
|
||||
dc_TagType_TypeIDAndLong.Add("WORD", "18,2");
|
||||
dc_TagType_TypeIDAndLong.Add("DWORD", "3,4");
|
||||
dc_TagType_TypeIDAndLong.Add("REAL", "4,4");
|
||||
dc_TagType_TypeIDAndLong.Add("LREAL", "19,8");
|
||||
|
||||
//[DeviceCode],[Name],[IP],[DeviceType],[IsEnable],[Explain]
|
||||
var deviceTable = SqlOperation.SqlSignalTree.Select_Connect();
|
||||
var countDeviceTable = deviceTable.Rows.Count;
|
||||
for (int i = 0; i < countDeviceTable; i++)
|
||||
{
|
||||
//[ID],[IP],[DeviceType],[IsEnable]
|
||||
var ip = deviceTable.Rows[i]["IP"].ToString();
|
||||
var deviceType = deviceTable.Rows[i]["DeviceType"].ToString();
|
||||
var isEnable = Convert.ToInt32(deviceTable.Rows[i]["IsEnable"]).ToString();
|
||||
|
||||
dt_Device.Rows.Add(ip, deviceType, isEnable);
|
||||
}
|
||||
|
||||
var opcDataTable = SqlOperation.SqlSignalTree.SelectSignalForOpc(PP.ProjectCode);
|
||||
var count = opcDataTable.Rows.Count;
|
||||
for(int i = 0; i < count; i++)
|
||||
{
|
||||
var Region = opcDataTable.Rows[i]["Region"].ToString();
|
||||
var addr = opcDataTable.Rows[i]["Address"].ToString();
|
||||
var addr1 = "";
|
||||
var addr2 = "";
|
||||
if (addr.Contains("."))
|
||||
{
|
||||
addr1 = addr.Split('.')[0];
|
||||
addr2 = "."+addr.Split('.')[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
addr1 = addr;
|
||||
addr2 = "";
|
||||
}
|
||||
|
||||
var tagType = opcDataTable.Rows[i]["Type"].ToString().ToUpper();
|
||||
var tagTypeID = dc_TagType_TypeIDAndLong[tagType].Split(',')[0];
|
||||
|
||||
var tagLong = dc_TagType_TypeIDAndLong[tagType].Split(',')[1];
|
||||
|
||||
//if (tagType == "STRING")
|
||||
//{
|
||||
// tagLong = (Convert.ToInt32(addr2) + 2).ToString();
|
||||
//}
|
||||
if (tagType == "STRING")
|
||||
{
|
||||
var length_1 = "";
|
||||
if (addr2.Contains("."))
|
||||
{
|
||||
length_1 = addr2.Replace(".", "");
|
||||
}
|
||||
tagLong = (Convert.ToInt32(length_1) + 2).ToString();
|
||||
}
|
||||
|
||||
var tagID = opcDataTable.Rows[i]["DeviceCode"].ToString();
|
||||
var tagName = opcDataTable.Rows[i]["Name"].ToString();
|
||||
|
||||
var isEnable = Convert.ToInt32(opcDataTable.Rows[i]["IsEnable"]).ToString();
|
||||
var devicePid = opcDataTable.Rows[i]["DevicePid"].ToString();
|
||||
var ip = "127.0.0.1";
|
||||
var dr_Connect = deviceTable.Select($"DeviceCode = '{devicePid}'");
|
||||
if (dr_Connect.Length > 0)
|
||||
{
|
||||
ip = dr_Connect[0]["IP"].ToString();
|
||||
}
|
||||
|
||||
var opName = "OP_"+ ip;
|
||||
|
||||
var isMonitor = opcDataTable.Rows[i]["IsMonitor"].ToString ();
|
||||
switch (isMonitor)
|
||||
{
|
||||
case "1":
|
||||
case "True":
|
||||
case "TRUE":
|
||||
case "true":
|
||||
isMonitor = "1";
|
||||
break;
|
||||
default:
|
||||
isMonitor = "0";
|
||||
break;
|
||||
}
|
||||
var resourcesCode = opcDataTable.Rows[i]["Resources"].ToString();
|
||||
|
||||
|
||||
dt_Signal.Rows.Add(
|
||||
tagID,//TagID
|
||||
tagName,//TagName
|
||||
opName, //工位号
|
||||
opName, //数据来源
|
||||
ip, //IP
|
||||
tagTypeID, //TagTypeID
|
||||
tagLong, //TagLong
|
||||
Region, //DbName
|
||||
tagType, //变量类型
|
||||
addr1, //变量地址
|
||||
addr2, //变量其它
|
||||
"0",//演示偏移
|
||||
"2",//列位置
|
||||
resourcesCode,//测量位置
|
||||
tagName,//测量项目
|
||||
"",//测量单位
|
||||
"3",//变量类型代码
|
||||
"数字孪生变量",//变量类型名称
|
||||
"127",//机体类型
|
||||
"",//线体类型
|
||||
"无",//"S7:[127.0.0.1|VFD1|S7ONLINE|01.00,127.0.0.1,02.02,1]DB411,B1",//TagAdr
|
||||
"无",//"S7:[@LOCALSERVER]DB411,INT1",//TagAdrDemo
|
||||
isEnable,//是否启用
|
||||
"Group1",//监控组
|
||||
"100",//监控时间间隔
|
||||
"0",//OpcServer_OPNAME
|
||||
"0",//变量特点
|
||||
isMonitor,//是否监控
|
||||
"0",//变量排序
|
||||
"0",//工序能力
|
||||
"1",//监控属性代码
|
||||
"0",//测量位置短
|
||||
"100",//上限值
|
||||
"0",//下限值
|
||||
"50",//理论值
|
||||
"1",//IsGoodBad
|
||||
"0",//IsSaveToSql
|
||||
"0"//IsWebSocket
|
||||
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return b;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private DataTable CreateOpcSignalTable()
|
||||
{
|
||||
//TagID TagName 工位号 数据来源 IP TagTypeID TagLong DbName 变量类型 变量地址 变量其它 演示偏移 列位置 测量位置 测量项目 测量单位 变量类型代码 变量类型名称 机体类型 线体类型 TagAdr TagAdrDemo 是否启用 监控组 监控时间间隔 OpcServer_OPNAME 变量特点 是否监控 变量排序 工序能力 监控属性代码 测量位置短 上限值 下限值 理论值 IsGoodBad IsSaveToSql IsWebSocket
|
||||
var dt = new DataTable();
|
||||
dt.Columns.Add("TagID");
|
||||
dt.Columns.Add("TagName");
|
||||
dt.Columns.Add("工位号");
|
||||
dt.Columns.Add("数据来源");
|
||||
dt.Columns.Add("IP");
|
||||
dt.Columns.Add("TagTypeID");
|
||||
dt.Columns.Add("TagLong");
|
||||
dt.Columns.Add("DbName");
|
||||
dt.Columns.Add("变量类型");
|
||||
dt.Columns.Add("变量地址");
|
||||
dt.Columns.Add("变量其它");
|
||||
dt.Columns.Add("演示偏移");
|
||||
dt.Columns.Add("列位置");
|
||||
dt.Columns.Add("测量位置");
|
||||
dt.Columns.Add("测量项目");
|
||||
dt.Columns.Add("测量单位");
|
||||
dt.Columns.Add("变量类型代码");
|
||||
dt.Columns.Add("变量类型名称");
|
||||
dt.Columns.Add("机体类型");
|
||||
dt.Columns.Add("线体类型");
|
||||
dt.Columns.Add("TagAdr");
|
||||
dt.Columns.Add("TagAdrDemo");
|
||||
dt.Columns.Add("是否启用");
|
||||
dt.Columns.Add("监控组");
|
||||
dt.Columns.Add("监控时间间隔");
|
||||
dt.Columns.Add("OpcServer_OPNAME");
|
||||
dt.Columns.Add("变量特点");
|
||||
dt.Columns.Add("是否监控");
|
||||
dt.Columns.Add("变量排序");
|
||||
dt.Columns.Add("工序能力");
|
||||
dt.Columns.Add("监控属性代码");
|
||||
dt.Columns.Add("测量位置短");
|
||||
dt.Columns.Add("上限值");
|
||||
dt.Columns.Add("下限值");
|
||||
dt.Columns.Add("理论值");
|
||||
dt.Columns.Add("IsGoodBad");
|
||||
dt.Columns.Add("IsSaveToSql");
|
||||
dt.Columns.Add("IsWebSocket");
|
||||
|
||||
return dt;
|
||||
|
||||
}
|
||||
|
||||
private DataTable CreateOpcDeviceTable()
|
||||
{
|
||||
//设备IP 设备类型 是否启用
|
||||
|
||||
var dt = new DataTable();
|
||||
dt.Columns.Add("设备IP");
|
||||
dt.Columns.Add("设备类型");
|
||||
dt.Columns.Add("是否启用");
|
||||
|
||||
return dt;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void GetSignalTableForAdvanced( DataTable dt_Signal
|
||||
, out Dictionary<String, String> dc_IP_InstanceName
|
||||
, out Dictionary<String,String> dc_TagID_InstanceName
|
||||
, out Dictionary<String, String> dc_TagID_Addr
|
||||
, out Dictionary<String, Int32> dc_TagID_TagTypeCode)
|
||||
{
|
||||
|
||||
dc_IP_InstanceName = new Dictionary<String, String>();
|
||||
var dt_Device = SqlOperation.SqlSignalTree.Select_Connect();
|
||||
foreach (DataRow dr in dt_Device.Rows)
|
||||
{
|
||||
var ip = dr["IP"].ToString();
|
||||
var name = dr["Name"].ToString();
|
||||
dc_IP_InstanceName.Add(ip, name);
|
||||
}
|
||||
|
||||
dc_TagID_InstanceName = new Dictionary<String, String>();
|
||||
dc_TagID_Addr = new Dictionary<String, String>();
|
||||
dc_TagID_TagTypeCode = new Dictionary<String, Int32>();
|
||||
for (int i = 0; i < dt_Signal.Rows.Count; i++)
|
||||
{
|
||||
var tagID = dt_Signal.Rows[i]["TagID"].ToString();
|
||||
var ip = dt_Signal.Rows[i]["IP"].ToString();
|
||||
var dbName = dt_Signal.Rows[i]["DbName"].ToString();
|
||||
var 变量地址 = dt_Signal.Rows[i]["变量地址"].ToString();
|
||||
var 变量其它 = dt_Signal.Rows[i]["变量其它"].ToString();
|
||||
var addr = dbName + 变量地址 + 变量其它;
|
||||
var tagTypeCode = Convert.ToInt32(dt_Signal.Rows[i]["TagTypeID"]);
|
||||
if (addr.Contains("I") | addr.Contains("Q"))
|
||||
{
|
||||
dc_TagID_InstanceName.Add(tagID, dc_IP_InstanceName[ip]);
|
||||
dc_TagID_Addr.Add(tagID, addr);
|
||||
dc_TagID_TagTypeCode.Add(tagID, tagTypeCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
//using Global;
|
||||
//using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
//using static DataLinkMesWork.SQLCommon;
|
||||
//using static SqlManage.ExecSql;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
namespace DTTest
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public partial class E { }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public partial class ModelManagement
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="processList"></param>
|
||||
/// <param name="useTimeList"></param>
|
||||
/// <param name="jList"></param>
|
||||
private void RecordJointData(List<String> processList, List<Int32> useTimeList, List<List<double>> jList)
|
||||
{
|
||||
useTimeList[0] = 0;
|
||||
var dc_ProcessCode_Joint = new Dictionary<String, List<double>>();
|
||||
var jointIndex = 0;
|
||||
for (int i = 0; i < processList.Count ; i++)
|
||||
{
|
||||
var index = jointIndex += useTimeList[i] / PP.PCP.FrameValue;
|
||||
var ii = index >= jList.Count ? index - 1 : index;
|
||||
dc_ProcessCode_Joint.Add(processList[i], jList[ii]);
|
||||
}
|
||||
ExecToSQL(dc_ProcessCode_Joint);
|
||||
}
|
||||
|
||||
|
||||
private void ExecToSQL(Dictionary<String, List<double>> dc_ProcessCode_Joint)
|
||||
{
|
||||
var sqls = "";
|
||||
|
||||
foreach (var item in dc_ProcessCode_Joint)
|
||||
{
|
||||
var tagId = item.Key;
|
||||
var tagJointValue = item.Value;
|
||||
var sql = " UPDATE [ModelProcess] SET [J1] = " + tagJointValue[0] + ", [J2] = " + tagJointValue[1] + ", [J3] = " + tagJointValue[2] + ", [J4] = " + tagJointValue[3] + ", [J5] = " + tagJointValue[4] + ", [J6] = " + tagJointValue[5] + " WHERE [ProjectCode] = '" + PP.ProjectCode + "' AND [ProcessCode] = '" + tagId + "' ;\n";
|
||||
sqls += sql;
|
||||
}
|
||||
|
||||
SqlOperation.SqlCraft.ExecSqlStrNoQuery(sqls);
|
||||
|
||||
//foreach (var ProcessCode_JointDic in dc_ProcessCode_Joint)
|
||||
//{
|
||||
// var currProcessCode = ProcessCode_JointDic.Key;
|
||||
// var currJoint = JsonConvert.SerializeObject(ProcessCode_JointDic.Value);
|
||||
|
||||
// SqlOperation.SqlProcess.UpdateProcessRobotCurrJoint(currProcessCode, currJoint);
|
||||
//}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
237
DataMirrorTools_Simulator/ModelBasic/Base/MM.SimDeviceSignal.cs
Normal file
237
DataMirrorTools_Simulator/ModelBasic/Base/MM.SimDeviceSignal.cs
Normal file
@@ -0,0 +1,237 @@
|
||||
using Global;
|
||||
using MesServerFunctions;
|
||||
using ModelBasic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
||||
namespace DTTest
|
||||
{
|
||||
public partial class E { }
|
||||
public class DeviceSignalSimGanttBase : ModelManagement
|
||||
{
|
||||
static string MqttTargetTopicPLC = System.Configuration.ConfigurationManager.AppSettings["MqttTargetTopicPLC"];
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static int playIndex;
|
||||
/// <summary>
|
||||
/// 循环播放
|
||||
/// 2021.3.31
|
||||
/// </summary>
|
||||
public static bool LoopPlay = false;
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
private Thread t_PlayCurrDeviceSignalSimTask = null;
|
||||
/// <summary>
|
||||
/// 播放当前的信号仿真的任务
|
||||
/// 2020.12.10
|
||||
/// </summary>
|
||||
public void PlayCurrDeviceSignalSimTask(string deviceSignalSimCode)
|
||||
{
|
||||
if (t_PlayCurrDeviceSignalSimTask == null)
|
||||
{
|
||||
t_PlayCurrDeviceSignalSimTask = new Thread(new ParameterizedThreadStart(PlayDeviceSignalSim));
|
||||
t_PlayCurrDeviceSignalSimTask.IsBackground = true;
|
||||
t_PlayCurrDeviceSignalSimTask.Name = deviceSignalSimCode.ToString();
|
||||
t_PlayCurrDeviceSignalSimTask.Start(deviceSignalSimCode);
|
||||
}
|
||||
else
|
||||
{
|
||||
// // ModelBasic.ErrDef.iErrHandler.ErrInfoTransmit("当前存在播放的信号仿真!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static public bool IsCanPlay(string deviceSignalSimCode)
|
||||
{
|
||||
var dt_DeviceSignalSim = SqlOperation.SqlDeviceSignalSim.Select_DeviceSignalSim(deviceSignalSimCode);
|
||||
if (dt_DeviceSignalSim.Rows.Count < 1)
|
||||
{
|
||||
// // ModelBasic.ErrDef.iErrHandler.ErrInfoTransmit("当前不存在播放的信号仿真!");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
private void PlayDeviceSignalSim(object obj)
|
||||
{
|
||||
var deviceSignalSimCode = (string)obj;
|
||||
var dt_DeviceSignalSim = SqlOperation.SqlDeviceSignalSim.Select_DeviceSignalSim(deviceSignalSimCode);
|
||||
if (dt_DeviceSignalSim.Rows.Count < 1)
|
||||
{
|
||||
// // ModelBasic.ErrDef.iErrHandler.ErrInfoTransmit("当前不存在播放的信号仿真!");
|
||||
return;
|
||||
}
|
||||
var dt_DeviceSignalSim_Count = dt_DeviceSignalSim.Rows.Count;
|
||||
var list_TagStartTime_TagID_TagValue = new List<OperationResultMesDtSim<Int32, String, String,Int32,string,string>>();
|
||||
var timeList = new List<int>();
|
||||
|
||||
for (int i = 0; i < dt_DeviceSignalSim_Count; i++)
|
||||
{
|
||||
var startTime = Convert.ToInt32(dt_DeviceSignalSim.Rows[i]["StartTime"]);
|
||||
var tagStartTime = startTime / 100;
|
||||
var keepTime = Convert.ToInt32(dt_DeviceSignalSim.Rows[i]["KeepTime"]);
|
||||
var tagID = dt_DeviceSignalSim.Rows[i]["TagID"].ToString();
|
||||
var tagValue = dt_DeviceSignalSim.Rows[i]["TagValue"].ToString();
|
||||
var opName = dt_DeviceSignalSim.Rows[i]["OpName"].ToString();
|
||||
var tagIDCopyFrom = dt_DeviceSignalSim.Rows[i]["TagIDCopyFrom"].ToString();
|
||||
|
||||
int tagFrom = 1;
|
||||
if(dt_DeviceSignalSim.Rows[i]["TagFrom"]!=DBNull.Value)
|
||||
{
|
||||
tagFrom = Convert.ToInt32(dt_DeviceSignalSim.Rows[i]["TagFrom"]);
|
||||
|
||||
}
|
||||
list_TagStartTime_TagID_TagValue.Add(new OperationResultMesDtSim<Int32, String, String, Int32, String, String>()
|
||||
{ PlayIDList = tagStartTime, PlayName = tagID, ModelName = tagValue, TagFrom = tagFrom, OpName = opName, TagIDCopyFrom = tagIDCopyFrom });
|
||||
|
||||
timeList.Add(startTime + keepTime);
|
||||
}
|
||||
var maxTime = timeList.Max();
|
||||
var maxFrame = maxTime / 100;
|
||||
|
||||
var dc_TagStartTime_TagIDAndTagValue = list_TagStartTime_TagID_TagValue.GroupBy(m => m.PlayIDList)
|
||||
.ToDictionary(k => k.First().PlayIDList, v => v.ToList());
|
||||
|
||||
do{
|
||||
do{
|
||||
if (dc_TagStartTime_TagIDAndTagValue.ContainsKey(playIndex))
|
||||
foreach (var item in dc_TagStartTime_TagIDAndTagValue[playIndex])
|
||||
{
|
||||
var tagID = item.PlayName;
|
||||
var tagValue = item.ModelName;
|
||||
var opName = item.OpName;
|
||||
var tagIDCopyFrom = item.TagIDCopyFrom;
|
||||
switch (item.TagFrom)
|
||||
{
|
||||
case 1:
|
||||
DtWebApiDT.PLC.WritePLC(tagID, tagValue);
|
||||
break;
|
||||
case 2:
|
||||
DtWebApi.ReadWritePLC.WritePLC(tagID, tagValue);
|
||||
break;
|
||||
case 3://扫描条码
|
||||
string Message;
|
||||
|
||||
|
||||
Message = "BarCode|Bar|" + opName + "|" + tagValue;
|
||||
|
||||
SendMessage.SendMessageBARToMES(opName,Message);
|
||||
//asyncSendMessage(Message);
|
||||
//DtWebApi.ReadWritePLC.WritePLC(tagID, tagValue);
|
||||
break;
|
||||
case 4://拷贝变量值
|
||||
tagValue = DtWebApi.ReadWritePLC.ReadPLC(tagIDCopyFrom).ToString();
|
||||
DtWebApi.ReadWritePLC.WritePLC(tagID, tagValue);
|
||||
break;
|
||||
case 5://MQTT
|
||||
|
||||
Message = "MesToWeb|Web|" + opName + "|" + tagValue;
|
||||
SendMessage.SendMessageMESToWEB(opName, Message);
|
||||
//asyncSendMessage(Message);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
//if (GlobalVar.signalWriteTask != null)
|
||||
//{
|
||||
// GlobalVar.signalWriteTask.BeginInvoke(Cmd_Frame.SignalWrite, tagID, tagValue, "-1", new AsyncCallback(SignalWriteTask_0), GlobalVar.signalWriteTask);
|
||||
//}
|
||||
}
|
||||
|
||||
ModelControl_CurrRunInfoEventPs(playIndex);
|
||||
playIndex++;
|
||||
Thread.Sleep(100);
|
||||
} while (playIndex <= maxFrame) ;
|
||||
|
||||
playIndex = 0;
|
||||
|
||||
} while(LoopPlay);
|
||||
|
||||
t_PlayCurrDeviceSignalSimTask = null;
|
||||
PlayDeviceSignalSimTaskEnd(deviceSignalSimCode);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void End_DeviceSignalSim_ExecTask(string deviceSignalSimCode)
|
||||
{
|
||||
if (t_PlayCurrDeviceSignalSimTask != null)
|
||||
{
|
||||
var ts = Get_DeviceSignalSim_ExecTask_State();
|
||||
if (ts == (ThreadState.Background | ThreadState.Suspended))
|
||||
{
|
||||
t_PlayCurrDeviceSignalSimTask.Resume();
|
||||
}
|
||||
t_PlayCurrDeviceSignalSimTask.Abort();
|
||||
}
|
||||
|
||||
playIndex = 0;
|
||||
t_PlayCurrDeviceSignalSimTask = null ;
|
||||
PlayDeviceSignalSimTaskEnd(deviceSignalSimCode);
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="craftCode"></param>
|
||||
public void Suspend_DeviceSignalSim_ExecTask()
|
||||
{
|
||||
t_PlayCurrDeviceSignalSimTask.Suspend();
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="craftCode"></param>
|
||||
public void Resume_DeviceSignalSim_ExecTask()
|
||||
{
|
||||
t_PlayCurrDeviceSignalSimTask.Resume();
|
||||
}
|
||||
|
||||
public ThreadState Get_DeviceSignalSim_ExecTask_State()
|
||||
{
|
||||
ThreadState threadState = ThreadState.Stopped;
|
||||
if (t_PlayCurrDeviceSignalSimTask != null)
|
||||
{
|
||||
threadState = t_PlayCurrDeviceSignalSimTask.ThreadState;
|
||||
}
|
||||
return threadState;
|
||||
}
|
||||
|
||||
public MesWorkMqtt.Mqtt2 mqtt2;
|
||||
public void InitMqtt2(string url, string topic)
|
||||
{
|
||||
mqtt2 = new MesWorkMqtt.Mqtt2();
|
||||
mqtt2.MqttUrl = url;
|
||||
mqtt2.topic = topic;
|
||||
StartAsync();
|
||||
|
||||
}
|
||||
private async void StartAsync()
|
||||
{
|
||||
await mqtt2.StartAsync();
|
||||
}
|
||||
|
||||
|
||||
public async void asyncSendMessage(string Message)
|
||||
{
|
||||
|
||||
|
||||
await mqtt2.Publish(MqttTargetTopicPLC, Message);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
448
DataMirrorTools_Simulator/ModelBasic/Base/MM.TransferProject.cs
Normal file
448
DataMirrorTools_Simulator/ModelBasic/Base/MM.TransferProject.cs
Normal file
@@ -0,0 +1,448 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web.Script.Serialization;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DTTest
|
||||
{
|
||||
public partial class E { }
|
||||
public partial class ModelManagement
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 导出项目数据
|
||||
/// 2020.10.29
|
||||
/// </summary>
|
||||
public void ExportProjectData_FixedTable_Dialog(bool isLightweight)
|
||||
{
|
||||
var exportOpenFileDialog = new SaveFileDialog();
|
||||
//设置文件类型
|
||||
exportOpenFileDialog.Filter = "JavaScript Object Notation(*.json)|*.json";
|
||||
//exportOpenFileDialog.Filter = "JavaScript Object Notation(*.json)|*.json|Microsoft Excel(*.xls)|*.xls|Data File(*.dat)|*.dat";
|
||||
//设置默认文件类型显示顺序
|
||||
exportOpenFileDialog.FilterIndex = 1;
|
||||
//保存对话框是否记忆上次打开的目录
|
||||
exportOpenFileDialog.RestoreDirectory = true;
|
||||
|
||||
var exportDialogResult = exportOpenFileDialog.ShowDialog();
|
||||
|
||||
//点了保存按钮进入
|
||||
if (exportDialogResult == DialogResult.OK)
|
||||
{
|
||||
var localFilePath = exportOpenFileDialog.FileName;//获得文件路径
|
||||
var fileNameExt = localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1); //获取文件名,不带路径
|
||||
var fileExtension = localFilePath.Substring(localFilePath.LastIndexOf(".") + 1); //获取文件扩展名
|
||||
|
||||
//获取文件路径,不带文件名
|
||||
//FilePath = localFilePath.Substring(0, localFilePath.LastIndexOf("\\"));
|
||||
|
||||
//给文件名前加上时间
|
||||
//newFileName = DateTime.Now.ToString("yyyyMMdd") + fileNameExt;
|
||||
|
||||
//在文件名里加字符
|
||||
//saveFileDialog1.FileName.Insert(1,"dameng");
|
||||
|
||||
//System.IO.FileStream fs = (System.IO.FileStream)sfd.OpenFile();//输出文件
|
||||
var fileExtensionToLower = fileExtension.ToLower();
|
||||
|
||||
ExportProjectData_FixedTable(localFilePath, fileExtensionToLower, isLightweight);
|
||||
|
||||
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// MessageBox.Show("您已取消了导出数据操作!");
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
public void ExportProjectData_FixedTable_Dialog(string projectName)
|
||||
{
|
||||
var exportOpenFileDialog = new SaveFileDialog();
|
||||
//设置文件类型
|
||||
exportOpenFileDialog.Filter = "导出文件(*.bak)|*.bak";
|
||||
//exportOpenFileDialog.Filter = "JavaScript Object Notation(*.json)|*.json|Microsoft Excel(*.xls)|*.xls|Data File(*.dat)|*.dat";
|
||||
//设置默认文件类型显示顺序
|
||||
exportOpenFileDialog.FilterIndex = 1;
|
||||
//保存对话框是否记忆上次打开的目录
|
||||
exportOpenFileDialog.RestoreDirectory = true;
|
||||
|
||||
var exportDialogResult = exportOpenFileDialog.ShowDialog();
|
||||
|
||||
//点了保存按钮进入
|
||||
if (exportDialogResult == DialogResult.OK)
|
||||
{
|
||||
var localFilePath = exportOpenFileDialog.FileName;//获得文件路径
|
||||
//var fileNameExt = localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1); //获取文件名,不带路径
|
||||
//var fileExtension = localFilePath.Substring(localFilePath.LastIndexOf(".") + 1); //获取文件扩展名
|
||||
|
||||
//获取文件路径,不带文件名
|
||||
//FilePath = localFilePath.Substring(0, localFilePath.LastIndexOf("\\"));
|
||||
|
||||
//给文件名前加上时间
|
||||
//newFileName = DateTime.Now.ToString("yyyyMMdd") + fileNameExt;
|
||||
|
||||
//在文件名里加字符
|
||||
//saveFileDialog1.FileName.Insert(1,"dameng");
|
||||
|
||||
//System.IO.FileStream fs = (System.IO.FileStream)sfd.OpenFile();//输出文件
|
||||
//var fileExtensionToLower = fileExtension.ToLower();
|
||||
System.Threading.ThreadPool.QueueUserWorkItem((object obj) => {
|
||||
ExportProjectData(localFilePath, projectName);
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// MessageBox.Show("您已取消了导出数据操作!");
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
public void ExportProjectData(string localFilePath,string projectName)
|
||||
{
|
||||
string projectDbDir = PP.currExecPath + "\\models\\GLTFmodel\\" + projectName;
|
||||
string projectDbPath = projectDbDir + "\\db.json";
|
||||
//1导出项目数据
|
||||
ExportProjectData_FixedTable(projectDbPath, "json", false);
|
||||
|
||||
// Zip.ZipFile(projectDbDir, localFilePath, out string err);
|
||||
|
||||
}
|
||||
|
||||
public void ImportProjectData(string localFilePath, string projectName)
|
||||
{
|
||||
|
||||
string projectDbDir = PP.currExecPath + "\\models\\GLTFmodel\\" + projectName;
|
||||
string projectDbPath = projectDbDir + "\\db.json";
|
||||
// Zip.UnZipFile(localFilePath, projectDbDir, out string err);
|
||||
ImportProjectData_FixedTable(projectDbPath, projectName);
|
||||
//1导出项目数据
|
||||
//ExportProjectData_FixedTable(projectDbPath, "json", false);
|
||||
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 导出项目数据
|
||||
/// 2020.10.29
|
||||
/// 2021.3.12
|
||||
/// </summary>
|
||||
public void ExportProjectData_FixedTable(string localFilePath, string fileExtensionToLower, bool isLightweight)
|
||||
{
|
||||
var outDataSet = new DataSet();
|
||||
var tableDataList = new List<String>();
|
||||
|
||||
var dt_TableList = SqlOperation.TransferProject.Select_DB_Tables();
|
||||
|
||||
// PP.iGlobalVar2.ShowMainProgressSet("导出项目数据进度", dt_TableList.Rows.Count - 1);
|
||||
|
||||
for (int i = 0; i < dt_TableList.Rows.Count; i++)
|
||||
{
|
||||
var tableName = dt_TableList.Rows[i]["name"].ToString();
|
||||
DataTable dt = null;
|
||||
try
|
||||
{
|
||||
dt = SqlOperation.TransferProject.Select_Table(tableName);
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
LogNet.LogisTrac.WriteLog(typeof(ModelManagement), err);
|
||||
if(ModelBasic.ErrDef.iErrHandler!=null)
|
||||
// ModelBasic.ErrDef.iErrHandler.ErrInfoTransmit("导出项目数据查询表【错误】在表名【" + tableName + "】:\n" + err.ToString());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dt.Columns.Contains("ID"))
|
||||
{
|
||||
dt.Columns.Remove("ID");
|
||||
}
|
||||
if (dt.Columns.Contains("OperationTime"))
|
||||
{
|
||||
dt.Columns.Remove("OperationTime");
|
||||
}
|
||||
if (dt.Columns.Contains("ProjectCode"))
|
||||
{
|
||||
dt.Columns.Remove("ProjectCode");
|
||||
}
|
||||
if (dt.Columns.Contains("ActData"))
|
||||
{
|
||||
dt.Columns.Remove("ActData");
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (isLightweight)//轻量级选项
|
||||
{
|
||||
if (dt.Columns.Contains("CraftPlayData"))
|
||||
{
|
||||
dt.Columns.Remove("CraftPlayData");
|
||||
}
|
||||
}
|
||||
|
||||
//if (dt.Columns.Contains("CraftPlayData_Joint"))
|
||||
//{
|
||||
// dt.Columns.Remove("CraftPlayData_Joint");
|
||||
//}
|
||||
//if (dt.Columns.Contains("CraftPlayData_Raw"))
|
||||
//{
|
||||
// dt.Columns.Remove("CraftPlayData_Raw");
|
||||
//}
|
||||
|
||||
outDataSet.Tables.Add(dt.Copy());
|
||||
if (dt.Rows.Count > 0)
|
||||
tableDataList.Add("{\"" + dt.TableName + "\":" + JsonConvert.SerializeObject(dt) + "}");
|
||||
// PP.iGlobalVar2.ShowMainProgress(i);
|
||||
}
|
||||
|
||||
if (fileExtensionToLower == "json" | fileExtensionToLower == "dat")
|
||||
{
|
||||
var db_Project_Json = "[" + string.Join(",", tableDataList.ToArray()) + "]";
|
||||
File.WriteAllText(localFilePath, db_Project_Json);
|
||||
|
||||
//string strobj = db_Project_Json;
|
||||
//FileStream stream = new FileStream(localFilePath, FileMode.Create, FileAccess.Write, FileShare.None);
|
||||
//BinaryFormatter formatter = new BinaryFormatter();
|
||||
//formatter.Serialize(stream, strobj);
|
||||
//stream.Close();
|
||||
|
||||
}
|
||||
if (fileExtensionToLower == "xls" | fileExtensionToLower == "xlsx")
|
||||
{
|
||||
var success = OExcel.ExeclHelper_Model.DataSetToExcel(outDataSet, localFilePath);
|
||||
if (success == false)
|
||||
{
|
||||
// ModelBasic.ErrDef.iErrHandler.ErrInfoTransmit("项目数据导出Excel【错误】,原因是数据中存在大字段!请导出.json或.dat文件");
|
||||
return;
|
||||
}
|
||||
}
|
||||
// if(ModelBasic.ErrDef.iErrHandler!=null)
|
||||
// ModelBasic.ErrDef.iErrHandler.ErrInfoTransmit("导出项目数据完成!输出路径:" + localFilePath);
|
||||
}
|
||||
|
||||
public void ImportProjectData(string projectName)
|
||||
{
|
||||
//1:判断项目名称是否存在?
|
||||
|
||||
|
||||
//2:项目名称如果存在,如果导入,删除原来项目
|
||||
|
||||
if (MessageBox.Show("确认导入项目?【" + projectName + "】", "导入确认", MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||||
{
|
||||
var importOpenFileDialog = new OpenFileDialog();
|
||||
var importDialogResult = importOpenFileDialog.ShowDialog();
|
||||
if (importDialogResult == DialogResult.OK)
|
||||
{
|
||||
var localFilePath = importOpenFileDialog.FileName;
|
||||
ImportProjectData( localFilePath, projectName);
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// MessageBox.Show("您已取消了导入项目操作!");
|
||||
//}
|
||||
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// MessageBox.Show("您已取消了导入项目操作!");
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 导入项目数据
|
||||
/// </summary>
|
||||
public void ImportProjectData()
|
||||
{
|
||||
//1:判断项目名称是否存在?
|
||||
|
||||
|
||||
//2:项目名称如果存在,如果导入,删除原来项目
|
||||
|
||||
if (MessageBox.Show("确认导入项目?【" + "projectName" + "】", "导入确认", MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||||
{
|
||||
var importOpenFileDialog = new OpenFileDialog();
|
||||
var importDialogResult = importOpenFileDialog.ShowDialog();
|
||||
if (importDialogResult == DialogResult.OK)
|
||||
{
|
||||
var localFilePath = importOpenFileDialog.FileName;
|
||||
ImportProjectData_FixedTable(localFilePath);
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// MessageBox.Show("您已取消了导入项目操作!");
|
||||
//}
|
||||
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// MessageBox.Show("您已取消了导入项目操作!");
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
public void ImportProjectData_FixedTable(string localFilePath, string restoredProjectName)
|
||||
{
|
||||
string PP_ProjectCode = Guid.NewGuid().ToString("D").ToUpper();
|
||||
var t1 = DateTime.Now.ToFileTimeUtc();
|
||||
var projectDataFile = File.ReadAllText(localFilePath);
|
||||
|
||||
var t2 = DateTime.Now.ToFileTimeUtc();
|
||||
var D1 = ((t2 - t1) / 10000).ToString();
|
||||
|
||||
var jProjectData = (JArray)JsonConvert.DeserializeObject(projectDataFile);
|
||||
|
||||
var curr_Index_All = 1;
|
||||
var t_ProgressBar_2 = new T_ProgressBar_2("导入项目数据进度", jProjectData.Count);
|
||||
//t_ProgressBar_2.Show();
|
||||
|
||||
foreach (JToken jProjectData_P in jProjectData)
|
||||
{
|
||||
var jObj = JObject.Parse(jProjectData_P.ToString());
|
||||
var tableName = jObj.First.Path;
|
||||
var j_TableData = jObj[tableName].ToString();
|
||||
|
||||
var dt_TableData = JsonConvert.DeserializeObject<DataTable>(j_TableData);
|
||||
|
||||
var columnName = GetColumnsByDataTable(dt_TableData);
|
||||
var columnNameRows = string.Join(",", columnName.ToList<String>().ToArray());
|
||||
|
||||
t_ProgressBar_2.ShowProgressSet(dt_TableData.Rows.Count);
|
||||
|
||||
//foreach(DataRow dr in dt_TableData.Rows)
|
||||
for (int k = 0; k < dt_TableData.Rows.Count; k++)
|
||||
{
|
||||
var rowDataList = new List<string>();
|
||||
for (int i = 0; i < columnName.Length; i++)
|
||||
{
|
||||
var currValue = dt_TableData.Rows[k][(columnName[i])].ToString();
|
||||
if (!ModelBasic.Judge.IsIntOrDouble(currValue))
|
||||
currValue = "'" + currValue + "'";
|
||||
|
||||
rowDataList.Add(currValue);
|
||||
|
||||
}
|
||||
|
||||
var rowData = string.Join(",", rowDataList.ToArray());
|
||||
SqlOperation.TransferProject.Insert_Table(tableName, columnNameRows, rowData, PP_ProjectCode, restoredProjectName);
|
||||
|
||||
//t_ProgressBar_2.ShowProgress(k);
|
||||
}
|
||||
|
||||
//t_ProgressBar_2.ShowProgress_All(curr_Index_All);
|
||||
curr_Index_All = curr_Index_All + 1;
|
||||
}
|
||||
|
||||
var t3 = DateTime.Now.ToFileTimeUtc();
|
||||
var D2 = ((t3 - t2) / 10000).ToString();
|
||||
MessageBox.Show("项目文件导入成功!\n"
|
||||
+ "读取耗时:" + D1 + " ms\n"
|
||||
+ "转换存储耗时:" + D2 + " ms\n");
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导入项目数据
|
||||
/// 2020.10.30
|
||||
/// 固定格式文件方式
|
||||
/// </summary>
|
||||
public void ImportProjectData_FixedTable(string localFilePath)
|
||||
{
|
||||
var t1 = DateTime.Now.ToFileTimeUtc();
|
||||
var projectDataFile = File.ReadAllText(localFilePath);
|
||||
|
||||
var t2 = DateTime.Now.ToFileTimeUtc();
|
||||
var D1 = ((t2 - t1) / 10000).ToString();
|
||||
|
||||
var jProjectData = (JArray)JsonConvert.DeserializeObject(projectDataFile);
|
||||
|
||||
var curr_Index_All = 1;
|
||||
var t_ProgressBar_2 = new T_ProgressBar_2("导入项目数据进度", jProjectData.Count);
|
||||
t_ProgressBar_2.Show();
|
||||
|
||||
foreach (JToken jProjectData_P in jProjectData)
|
||||
{
|
||||
var jObj = JObject.Parse(jProjectData_P.ToString());
|
||||
var tableName = jObj.First.Path;
|
||||
var j_TableData = jObj[tableName].ToString();
|
||||
|
||||
var dt_TableData = JsonConvert.DeserializeObject<DataTable>(j_TableData);
|
||||
|
||||
var columnName = GetColumnsByDataTable(dt_TableData);
|
||||
var columnNameRows = string.Join(",", columnName.ToList<String>().ToArray());
|
||||
|
||||
t_ProgressBar_2.ShowProgressSet(dt_TableData.Rows.Count);
|
||||
|
||||
//foreach(DataRow dr in dt_TableData.Rows)
|
||||
for (int k = 0; k < dt_TableData.Rows.Count; k++)
|
||||
{
|
||||
var rowDataList = new List<string>();
|
||||
for (int i = 0; i < columnName.Length; i++)
|
||||
{
|
||||
var currValue = dt_TableData.Rows[k][(columnName[i])].ToString();
|
||||
if (!ModelBasic.Judge.IsIntOrDouble(currValue))
|
||||
currValue = "'" + currValue + "'";
|
||||
|
||||
rowDataList.Add(currValue);
|
||||
|
||||
}
|
||||
|
||||
var rowData = string.Join(",", rowDataList.ToArray());
|
||||
SqlOperation.TransferProject.Insert_Table(tableName, columnNameRows, rowData);
|
||||
|
||||
t_ProgressBar_2.ShowProgress(k);
|
||||
}
|
||||
|
||||
t_ProgressBar_2.ShowProgress_All(curr_Index_All);
|
||||
curr_Index_All = curr_Index_All + 1;
|
||||
}
|
||||
|
||||
var t3 = DateTime.Now.ToFileTimeUtc();
|
||||
var D2 = ((t3 - t2) / 10000).ToString();
|
||||
MessageBox.Show("项目文件导入成功!\n"
|
||||
+ "读取耗时:" + D1 + " ms\n"
|
||||
+ "转换存储耗时:" + D2 + " ms\n");
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据datatable获得列名
|
||||
/// </summary>
|
||||
/// <param name="dt">表对象</param>
|
||||
/// <returns>返回结果的数据列数组</returns>
|
||||
public static string[] GetColumnsByDataTable(DataTable dt)
|
||||
{
|
||||
string[] strColumns = null;
|
||||
|
||||
if (dt.Columns.Count > 0)
|
||||
{
|
||||
var columnNum = 0;
|
||||
columnNum = dt.Columns.Count;
|
||||
strColumns = new string[columnNum];
|
||||
for (int i = 0; i < dt.Columns.Count; i++)
|
||||
{
|
||||
strColumns[i] = dt.Columns[i].ColumnName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return strColumns;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
161
DataMirrorTools_Simulator/ModelBasic/Base/MM.Virtual.cs
Normal file
161
DataMirrorTools_Simulator/ModelBasic/Base/MM.Virtual.cs
Normal file
@@ -0,0 +1,161 @@
|
||||
using Global;
|
||||
using ModelBasic;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
using WeifenLuo.WinFormsUI.Docking;
|
||||
|
||||
namespace DTTest
|
||||
{
|
||||
public partial class E { }
|
||||
public partial class ModelManagement
|
||||
{
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="m"></param>
|
||||
public virtual void ModelMotionControl_CurrModelInfo(object sender, Data_ClickModel m)
|
||||
{
|
||||
if (GlobalEventInterface.E_ModelMotionControl_CurrClickModel != null)
|
||||
{
|
||||
GlobalEventInterface.E_ModelMotionControl_CurrClickModel.Invoke(sender, m);
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="threejsBaseQ"></param>
|
||||
/// <param name="threejsToolQ"></param>
|
||||
/// <param name="threejsTcpQ"></param>
|
||||
/// <param name="threejsBaseP"></param>
|
||||
/// <param name="threejsToolP"></param>
|
||||
/// <param name="threejsTcpP"></param>
|
||||
public virtual void RobotData(double[] threejsBaseQ, double[] threejsToolQ, double[] threejsTcpQ, double[] threejsBaseP, double[] threejsToolP, double[] threejsTcpP)
|
||||
{
|
||||
if (GlobalEventInterface.E_RobotData != null)
|
||||
{
|
||||
GlobalEventInterface.E_RobotData.Invoke(threejsBaseQ, threejsToolQ, threejsTcpQ, threejsBaseP, threejsToolP, threejsTcpP);
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="arg1"></param>
|
||||
/// <param name="arg2"></param>
|
||||
public virtual void ModelControl_CurrRunInfoEvent(int index, int indexAll, C_Frames arg2)
|
||||
{
|
||||
if (GlobalEventInterface.E_ShowIndex != null)
|
||||
{
|
||||
GlobalEventInterface.E_ShowIndex.Invoke(index, indexAll);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public virtual void ModelControl_PlayTaskEnd()
|
||||
{
|
||||
if (GlobalEventInterface.E_ModelControl_PlayTaskEnd != null)
|
||||
{
|
||||
GlobalEventInterface.E_ModelControl_PlayTaskEnd.Invoke();
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="currTime_Play"></param>
|
||||
public virtual void CurrTime_Play(long currTime_Play)
|
||||
{
|
||||
if (GlobalEventInterface.E_CurrTime_Play != null)
|
||||
{
|
||||
GlobalEventInterface.E_CurrTime_Play.Invoke(currTime_Play);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="craftCode"></param>
|
||||
public virtual void PlayCurrCraftTaskEnd(string craftCode)
|
||||
{
|
||||
if (GlobalEventInterface.E_PlayCurrCraftTaskEnd != null)
|
||||
{
|
||||
GlobalEventInterface.E_PlayCurrCraftTaskEnd.Invoke(craftCode);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="index_ActFindCraftPlay"></param>
|
||||
/// <param name="maxRunFrame"></param>
|
||||
public virtual void ShowIndex(int index_ActFindCraftPlay, int maxRunFrame)
|
||||
{
|
||||
if (GlobalEventInterface.E_ShowIndex != null)
|
||||
{
|
||||
GlobalEventInterface.E_ShowIndex.Invoke(index_ActFindCraftPlay, maxRunFrame);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="actCode"></param>
|
||||
public virtual void PlayCurrActTaskEnd(string actCode)
|
||||
{
|
||||
if (GlobalEventInterface.E_PlayCurrActTaskEnd != null)
|
||||
{
|
||||
GlobalEventInterface.E_PlayCurrActTaskEnd.Invoke(actCode);
|
||||
}
|
||||
}//~~~
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="index_ActFindCraftPlay"></param>
|
||||
public virtual void PlayCurrActCraftTaskEnd(int index_ActFindCraftPlay)
|
||||
{
|
||||
if (GlobalEventInterface.E_PlayCurrActCraftTaskEnd != null)
|
||||
{
|
||||
GlobalEventInterface.E_PlayCurrActCraftTaskEnd.Invoke(index_ActFindCraftPlay);
|
||||
}
|
||||
}//~~~
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
public virtual void ModelControl_CurrRunInfoEventPs(int index)
|
||||
{
|
||||
if (GlobalEventInterface.E_ModelControl_CurrRunInfoEventPs != null)
|
||||
{
|
||||
GlobalEventInterface.E_ModelControl_CurrRunInfoEventPs.Invoke(index);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="deviceSignalSimCode"></param>
|
||||
public virtual void PlayDeviceSignalSimTaskEnd(string deviceSignalSimCode)
|
||||
{
|
||||
if (GlobalEventInterface.E_PlayDeviceSignalSimTaskEnd != null)
|
||||
{
|
||||
GlobalEventInterface.E_PlayDeviceSignalSimTaskEnd.Invoke(deviceSignalSimCode);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public virtual void OpenFileModel()
|
||||
{
|
||||
if (GlobalEventInterface.E_OpenFileModel != null)
|
||||
{
|
||||
GlobalEventInterface.E_OpenFileModel.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
176
DataMirrorTools_Simulator/ModelBasic/Base/MM.cs
Normal file
176
DataMirrorTools_Simulator/ModelBasic/Base/MM.cs
Normal file
@@ -0,0 +1,176 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Windows.Forms;
|
||||
//using static SqlManage.ExecSql;
|
||||
using System.IO;
|
||||
|
||||
|
||||
/*
|
||||
|
||||
truncate table [DeviceSignalSimTree]
|
||||
truncate table [DeviceTree]
|
||||
truncate table [ModelProcess]
|
||||
truncate table [OperationTree]
|
||||
truncate table [ProcesslLabelList]
|
||||
truncate table [ProjectList]
|
||||
truncate table [SignalViewer]
|
||||
truncate table [TagTriggerHandler]
|
||||
truncate table [Z_Save_Position]
|
||||
truncate table [Z_Save_Tag]
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
namespace DTTest
|
||||
{
|
||||
public partial class E { }
|
||||
public partial class ModelManagement
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public ModelManagement()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使用数据库链接创建项目
|
||||
/// 所有
|
||||
/// </summary>
|
||||
/// <param name="connectionString"></param>
|
||||
public ModelManagement(string connectionString,string projectCode)
|
||||
{
|
||||
LoadModel(connectionString);
|
||||
ReLoadPara(projectCode);
|
||||
while (!PP.ReLoadPara_IsCompleted)
|
||||
{
|
||||
System.Threading.Thread.Sleep(300);
|
||||
}
|
||||
}
|
||||
|
||||
#region 加载模型
|
||||
|
||||
/// <summary>
|
||||
/// 装载模型
|
||||
/// </summary>
|
||||
/// <param name="ipPortOpName_1"></param>
|
||||
/// <param name="prefix"></param>
|
||||
/// <param name="objectHeader"></param>
|
||||
/// <param name="sendInterval"></param>
|
||||
public void LoadModel(string connectionStringCurr)
|
||||
{
|
||||
//if (!DataLinkMesWork.KeyWordTest.KeyWordNew(out string sn1))
|
||||
//{
|
||||
// new DataLinkMesWork.Reg().ShowDialog();
|
||||
// if (!DataLinkMesWork.KeyWordTest.KeyWordNew(out string sn2))
|
||||
// return;
|
||||
//}
|
||||
|
||||
if (connectionStringCurr.ToLower() == "file")
|
||||
connectionStringCurr = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=" + PP.currExecPath + "\\ModelData.mdf;Integrated Security=True;Connect Timeout=30";
|
||||
|
||||
PP.ConnectionStr = connectionStringCurr;
|
||||
|
||||
if (!SqlOperation.Project.SelectConnect(PP.ConnectionStr))
|
||||
{
|
||||
string[] txt = PP.ConnectionStr.Split(';');
|
||||
string server = txt[0].Split('=')[1];
|
||||
string database = txt[1].Split('=')[1];
|
||||
string uid = txt[2].Split('=')[1];
|
||||
string pwd = txt[3].Split('=')[1];
|
||||
|
||||
MessageBox.Show("【未找到数据源,请检查链接】\r\n\r\n" +"当前链接是:"+ server + "\\"+ database + "\r\n\r\n" +"用户名:" + uid + "\r\n\r\n" +"密码:" + pwd + "\r\n\r\n位置:DataMirrorTools.exe.config");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void ReLoadPara(string projectCode)
|
||||
{
|
||||
SqlOperation.SqlProject.Refresh_Project_Para(projectCode);
|
||||
|
||||
try
|
||||
{
|
||||
var tipsBuilder = new System.Text.StringBuilder();
|
||||
if (!PP.PCP.ConnMode)
|
||||
tipsBuilder.AppendLine("【提示】没有使用通讯服务!").AppendLine();
|
||||
if (PP.PCP.IsRecordData)
|
||||
tipsBuilder.AppendLine("【警告】程序将记录数据到数据库!").AppendLine();
|
||||
if (!PP.PCP.IsAllowVisible)
|
||||
tipsBuilder.AppendLine("【警告】发布后的程序将不会控制模型显示和隐藏!").AppendLine();
|
||||
if (!PP.PCP.IsStartChrome)
|
||||
tipsBuilder.AppendLine("【警告】程序启动将不启动浏览界面!").AppendLine();
|
||||
if (tipsBuilder.Length > 0)
|
||||
MessageBox.Show(tipsBuilder.ToString());
|
||||
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
LogNet.LogisTrac.WriteLog(typeof(ModelManagement), err);
|
||||
|
||||
Console.WriteLine(err);
|
||||
MessageBox.Show("程序启动配置判断有误!");
|
||||
}
|
||||
|
||||
// UsedCefOrSocket(PP.PCP.ConnMode);
|
||||
// SelectTagID_Handler();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 检测行为是否存在
|
||||
/// </summary>
|
||||
/// <param name="actCode"></param>
|
||||
/// <returns></returns>
|
||||
public ActControl ActObjectExist(string actCode)
|
||||
{
|
||||
ActControl actControl = null;
|
||||
try
|
||||
{
|
||||
if (dc_ActCode_Object.ContainsKey(actCode))
|
||||
{
|
||||
actControl = dc_ActCode_Object[actCode];
|
||||
}
|
||||
else
|
||||
{
|
||||
actControl = new ActControl();
|
||||
actControl.CurrRunInfoEvent += new Action<int, int, C_Frames>(ModelControl_CurrRunInfoEvent);
|
||||
actControl.CurrRunInfoEvent += new Action<int, int, C_Frames>(CurrRunInfoSend);
|
||||
actControl.PlayTaskEnd += new Action(ModelControl_PlayTaskEnd);
|
||||
dc_ActCode_Object.Add(actCode, actControl);
|
||||
}
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
LogNet.LogisTrac.WriteLog(typeof(ModelManagement), err);
|
||||
|
||||
Console.WriteLine(err);
|
||||
}
|
||||
|
||||
return actControl;
|
||||
}
|
||||
|
||||
|
||||
protected internal void CurrRunInfoSend(int arg1, int arg2, C_Frames arg3)
|
||||
{
|
||||
// SendPlayFrameData(arg3);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user