添加middleware
6
middleware/zdhsys/App.config
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
|
||||
</startup>
|
||||
</configuration>
|
||||
28
middleware/zdhsys/App.xaml
Normal file
@@ -0,0 +1,28 @@
|
||||
<Application x:Class="zdhsys.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:zdhsys"
|
||||
StartupUri="MainWindow.xaml">
|
||||
<Application.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="Themes/GlobalResources.xaml"/>
|
||||
<ResourceDictionary Source="Themes/ScrollViewerDictionary.xaml"/>
|
||||
<ResourceDictionary Source="JsonTool/Themes/Paths.xaml" />
|
||||
<ResourceDictionary Source="JsonTool/Themes/Buttons.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<SolidColorBrush x:Key="TextBlueBrush" Color="#1887bf" x:Uid="蓝色文字" />
|
||||
<SolidColorBrush x:Key="TextLightBlueBrush" Color="#4e91b8" x:Uid="浅蓝或灰蓝色文字" />
|
||||
<SolidColorBrush x:Key="Transparent01" Color="#01ffffff" x:Uid="透明01,不可穿透" />
|
||||
<SolidColorBrush x:Key="TextBtnDisabledBrush" Color="#333333" x:Uid="按钮禁用文字" Opacity="0.6" />
|
||||
<SolidColorBrush x:Key="BorderBtnDisabledBrush" Color="#a0a2a3" x:Uid="按钮禁用边框" Opacity="0.6" />
|
||||
|
||||
|
||||
<!--按钮背景色-->
|
||||
<LinearGradientBrush x:Key="BtnBlueBackground" EndPoint="0.5,0" StartPoint="0.5,1" x:Uid="蓝色渐变背景">
|
||||
<GradientStop Color="#FF4B9DD3" Offset="0.087"/>
|
||||
<GradientStop Color="#FF69ACD7" Offset="1"/>
|
||||
</LinearGradientBrush>
|
||||
</ResourceDictionary>
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
225
middleware/zdhsys/App.xaml.cs
Normal file
@@ -0,0 +1,225 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Linq;
|
||||
using zdhsys;
|
||||
using Newtonsoft.Json;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Windows.Shapes;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace zdhsys
|
||||
{
|
||||
public partial class App : Application
|
||||
{
|
||||
private HttpListener _listener;
|
||||
private Task _serverTask;
|
||||
internal ExperimentData experimentData { get; private set; }
|
||||
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
base.OnStartup(e);
|
||||
|
||||
// 启动HTTP服务器
|
||||
StartHttpServer();
|
||||
}
|
||||
|
||||
private void StartHttpServer()
|
||||
{
|
||||
_listener = new HttpListener();
|
||||
_listener.Prefixes.Add("http://*:50000/");
|
||||
_listener.Start();
|
||||
|
||||
_serverTask = Task.Run(() => HandleRequests());
|
||||
}
|
||||
|
||||
private async Task HandleRequests()
|
||||
{
|
||||
while (_listener.IsListening)
|
||||
{
|
||||
var context = await _listener.GetContextAsync();
|
||||
ProcessRequest(context);
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessRequest(HttpListenerContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
var request = context.Request;
|
||||
var response = context.Response;
|
||||
|
||||
// 处理路由
|
||||
if (request.Url.AbsolutePath == "/" && request.HttpMethod == "GET")
|
||||
{
|
||||
var responseString = "{\"message\": \"Welcome to AI robot platform API!\"}";
|
||||
var buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
|
||||
|
||||
response.ContentType = "application/json";
|
||||
response.ContentLength64 = buffer.Length;
|
||||
response.OutputStream.Write(buffer, 0, buffer.Length);
|
||||
}
|
||||
else if (request.Url.AbsolutePath == "/sendScheme2RobotPlatform" && request.HttpMethod == "POST")
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var reader = new System.IO.StreamReader(request.InputStream, request.ContentEncoding))
|
||||
{
|
||||
var json = reader.ReadToEnd();
|
||||
Console.WriteLine("Received JSON data:");
|
||||
Console.WriteLine(json);
|
||||
|
||||
// 更新实验数据
|
||||
experimentData = JsonConvert.DeserializeObject<ExperimentData>(json);
|
||||
Console.WriteLine("Experiment data updated:");
|
||||
Console.WriteLine($"Task ID: {experimentData.TaskId}");
|
||||
Console.WriteLine($"Experiment Name: {experimentData.ExperimentName}");
|
||||
|
||||
// 创建任务ID文件夹
|
||||
string currentDirectory = Directory.GetCurrentDirectory();
|
||||
string directoryPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.IO.Path.GetDirectoryName(currentDirectory)), "PLdata", experimentData.TaskId);
|
||||
Directory.CreateDirectory(directoryPath);
|
||||
string jsonFilePath = System.IO.Path.Combine(directoryPath, "scheme.json");
|
||||
|
||||
try
|
||||
{
|
||||
// 将 JSON 字符串解析为 JObject
|
||||
var jsonObject = JObject.Parse(json);
|
||||
|
||||
// 将对象序列化为格式化的 JSON 字符串(缩进为 2)
|
||||
string formattedJson = jsonObject.ToString(Formatting.Indented);
|
||||
|
||||
// 将格式化的 JSON 写入文件
|
||||
File.WriteAllText(jsonFilePath, formattedJson);
|
||||
|
||||
Console.WriteLine($"JSON 已成功写入文件:{jsonFilePath}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"发生错误:{ex.Message}");
|
||||
}
|
||||
|
||||
var responseString = "{\"status\": \"success\", \"message\": \"Experiment data updated\"}";
|
||||
var buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
|
||||
|
||||
response.ContentType = "application/json";
|
||||
response.ContentLength64 = buffer.Length;
|
||||
response.OutputStream.Write(buffer, 0, buffer.Length);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
response.StatusCode = (int)HttpStatusCode.BadRequest;
|
||||
var errorResponse = new { error = ex.Message };
|
||||
var buffer = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(errorResponse));
|
||||
response.OutputStream.Write(buffer, 0, buffer.Length);
|
||||
}
|
||||
}
|
||||
else if (request.Url.AbsolutePath == "/getPLdata" && request.HttpMethod == "GET")
|
||||
{
|
||||
try
|
||||
{
|
||||
// 获取taskid参数
|
||||
string taskId = experimentData.TaskId;
|
||||
string currentDirectory = Directory.GetCurrentDirectory();
|
||||
|
||||
// 如果 taskId 为空,则尝试从 PLdata 文件夹中获取最新的日期文件夹
|
||||
if (string.IsNullOrEmpty(taskId))
|
||||
{
|
||||
string plDataPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.IO.Path.GetDirectoryName(currentDirectory)), "PLdata");
|
||||
|
||||
// 检查 PLdata 文件夹是否存在
|
||||
if (!Directory.Exists(plDataPath))
|
||||
{
|
||||
Console.WriteLine("PLdata directory does not exist.");
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取 PLdata 文件夹中的所有子文件夹
|
||||
var directories = Directory.GetDirectories(plDataPath)
|
||||
.Where(dir => DateTime.TryParse(System.IO.Path.GetFileName(dir), out _)) // 确保文件夹名是有效的日期格式
|
||||
.Select(dir => new { Path = dir, Date = DateTime.Parse(System.IO.Path.GetFileName(dir)) })
|
||||
.OrderByDescending(x => x.Date) // 按日期降序排序
|
||||
.ToList();
|
||||
|
||||
if (directories.Any())
|
||||
{
|
||||
// 取最新日期的文件夹名称作为 taskId
|
||||
taskId = System.IO.Path.GetFileName(directories.First().Path);
|
||||
Console.WriteLine($"Latest taskid from folder: {taskId}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("No valid date folders found in PLdata.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 构建路径
|
||||
string directoryPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.IO.Path.GetDirectoryName(currentDirectory)), "PLdata", taskId);
|
||||
Console.WriteLine($"Constructed directory path: {directoryPath}");
|
||||
|
||||
// 检查目录是否存在
|
||||
if (!Directory.Exists(directoryPath))
|
||||
{
|
||||
response.StatusCode = (int)HttpStatusCode.NotFound;
|
||||
var errorResponse = new { error = "Task directory not found" };
|
||||
var buffer = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(errorResponse));
|
||||
response.OutputStream.Write(buffer, 0, buffer.Length);
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取最新的txt文件
|
||||
var files = Directory.GetFiles(directoryPath, "*.TXT")
|
||||
.Select(f => new FileInfo(f))
|
||||
.OrderByDescending(f => f.LastWriteTime)
|
||||
.ToList();
|
||||
|
||||
if (files.Count == 0)
|
||||
{
|
||||
response.StatusCode = (int)HttpStatusCode.NotFound;
|
||||
var errorResponse = new { error = "No TXT files found" };
|
||||
var buffer = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(errorResponse));
|
||||
response.OutputStream.Write(buffer, 0, buffer.Length);
|
||||
return;
|
||||
}
|
||||
|
||||
// 读取最新文件内容
|
||||
string latestFileContent = File.ReadAllText(files[0].FullName);
|
||||
|
||||
// 发送响应
|
||||
var responseBuffer = Encoding.UTF8.GetBytes(latestFileContent);
|
||||
response.ContentType = "text/plain";
|
||||
response.ContentLength64 = responseBuffer.Length;
|
||||
response.OutputStream.Write(responseBuffer, 0, responseBuffer.Length);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
response.StatusCode = (int)HttpStatusCode.InternalServerError;
|
||||
var errorResponse = new { error = ex.Message };
|
||||
var buffer = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(errorResponse));
|
||||
response.OutputStream.Write(buffer, 0, buffer.Length);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
response.StatusCode = (int)HttpStatusCode.NotFound;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
context.Response.OutputStream.Close();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnExit(ExitEventArgs e)
|
||||
{
|
||||
// 关闭HTTP服务器
|
||||
_listener?.Stop();
|
||||
_listener?.Close();
|
||||
base.OnExit(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
9
middleware/zdhsys/Bean/DeviceFields.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace zdhsys.Bean
|
||||
{
|
||||
public class DeviceFields
|
||||
{
|
||||
public int index;
|
||||
public DeviceInfoModel dim;
|
||||
public DeviceFieldsModel dfm;
|
||||
}
|
||||
}
|
||||
33
middleware/zdhsys/Bean/DeviceFieldsModel.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using SQLite;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace zdhsys.Bean
|
||||
{
|
||||
public class DeviceFieldsModel
|
||||
{
|
||||
//[PrimaryKey, AutoIncrement]
|
||||
public int Id { get; set; }
|
||||
/// <summary>
|
||||
/// 字段名称
|
||||
/// </summary>
|
||||
public string FieldsName { get; set; }
|
||||
/// <summary>
|
||||
/// 字段内容
|
||||
/// </summary>
|
||||
public string FieldsContent { get; set; }
|
||||
|
||||
///// <summary>
|
||||
///// 所属设备
|
||||
///// </summary>
|
||||
//public int DeviceId { get; set; }
|
||||
|
||||
///// <summary>
|
||||
///// 所属组设备
|
||||
///// </summary>
|
||||
//public int DeviceGroupId { get; set; }
|
||||
}
|
||||
}
|
||||
94
middleware/zdhsys/Bean/DeviceGroupInfoModel.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using SQLite;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace zdhsys.Bean
|
||||
{
|
||||
public class DeviceGroupInfoModel
|
||||
{
|
||||
/// <summary>
|
||||
/// 表ID
|
||||
/// </summary>
|
||||
[PrimaryKey, AutoIncrement]
|
||||
public int Id { get; set; }
|
||||
/// <summary>
|
||||
/// 设备类别
|
||||
/// </summary>
|
||||
public int DeviceType { get; set; }
|
||||
/// <summary>
|
||||
/// 设备组ID --通讯用的
|
||||
/// </summary>
|
||||
public string DeviceId { get; set; }
|
||||
/// <summary>
|
||||
/// 设备组名称
|
||||
/// </summary>
|
||||
public string DeviceName { get; set; }
|
||||
/// <summary>
|
||||
/// 标签名称
|
||||
/// </summary>
|
||||
public string TagName { get; set; }
|
||||
/// <summary>
|
||||
/// 标签单位
|
||||
/// </summary>
|
||||
public string TagUnit { get; set; }
|
||||
/// <summary>
|
||||
/// 坐标位置:X
|
||||
/// </summary>
|
||||
public float X { get; set; }
|
||||
/// <summary>
|
||||
/// 坐标位置:Y
|
||||
/// </summary>
|
||||
public float Y { get; set; }
|
||||
/// <summary>
|
||||
/// 坐标位置:Z
|
||||
/// </summary>
|
||||
public float Z { get; set; }
|
||||
/// <summary>
|
||||
/// 设备大小:长
|
||||
/// </summary>
|
||||
public float L { get; set; }
|
||||
/// <summary>
|
||||
/// 设备大小:宽
|
||||
/// </summary>
|
||||
public float W { get; set; }
|
||||
/// <summary>
|
||||
/// 设备大小:高
|
||||
/// </summary>
|
||||
public float H { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 操作物体种类:大瓶子0 小瓶子1
|
||||
/// </summary>
|
||||
public int Bottole { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public long CreateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设备可操作
|
||||
/// </summary>
|
||||
public List<DeviceFieldsModel> Dfms;
|
||||
|
||||
/// <summary>
|
||||
/// 设备可操作JSON字符串
|
||||
/// </summary>
|
||||
public string FieldJson { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前余量
|
||||
/// </summary>
|
||||
public string Remain { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设备状态 1 正常 其它故障
|
||||
/// </summary>
|
||||
public int DeviceStatus { get; set; }
|
||||
/// <summary>
|
||||
/// 通信协议 =GlobalEnum.UnitDeviceType
|
||||
/// </summary>
|
||||
public string Protocol { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
124
middleware/zdhsys/Bean/DeviceInfoModel.cs
Normal file
@@ -0,0 +1,124 @@
|
||||
using SQLite;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace zdhsys.Bean
|
||||
{
|
||||
public class DeviceInfoModel
|
||||
{
|
||||
/// <summary>
|
||||
/// 表ID
|
||||
/// </summary>
|
||||
[PrimaryKey, AutoIncrement]
|
||||
public int Id { get; set; }
|
||||
/// <summary>
|
||||
/// 设备类别 0反应类设备 1转移类设备
|
||||
/// </summary>
|
||||
public int DeviceType { get; set; }
|
||||
/// <summary>
|
||||
/// 设备ID --通讯用的
|
||||
/// </summary>
|
||||
public string DeviceId { get; set; }
|
||||
/// <summary>
|
||||
/// 所属设备组ID
|
||||
/// </summary>
|
||||
public string DeviceGroupId { get; set; }
|
||||
/// <summary>
|
||||
/// 设备名称
|
||||
/// </summary>
|
||||
public string DeviceName { get; set; }
|
||||
/// <summary>
|
||||
/// 标签名称
|
||||
/// </summary>
|
||||
public string TagName { get; set; }
|
||||
/// <summary>
|
||||
/// 标签单位
|
||||
/// </summary>
|
||||
public string TagUnit { get; set; }
|
||||
/// <summary>
|
||||
/// 坐标位置:X
|
||||
/// </summary>
|
||||
public float X { get; set; }
|
||||
/// <summary>
|
||||
/// 坐标位置:Y
|
||||
/// </summary>
|
||||
public float Y { get; set; }
|
||||
/// <summary>
|
||||
/// 坐标位置:Z
|
||||
/// </summary>
|
||||
public float Z { get; set; }
|
||||
/// <summary>
|
||||
/// 设备大小:长
|
||||
/// </summary>
|
||||
public float L { get; set; }
|
||||
/// <summary>
|
||||
/// 设备大小:宽
|
||||
/// </summary>
|
||||
public float W { get; set; }
|
||||
/// <summary>
|
||||
/// 设备大小:高
|
||||
/// </summary>
|
||||
public float H { get; set; }
|
||||
/// <summary>
|
||||
/// 操作物体种类:大瓶子0 小瓶子1
|
||||
/// </summary>
|
||||
public int Bottole { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public long CreateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设备可操作 --不生成数据库字段
|
||||
/// </summary>
|
||||
public List<DeviceFieldsModel> Dfms;
|
||||
|
||||
/// <summary>
|
||||
/// 设备可操作JSON字符串
|
||||
/// </summary>
|
||||
public string FieldJson { get; set; }
|
||||
/// <summary>
|
||||
/// 点位信息
|
||||
/// </summary>
|
||||
public string PointJson { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 排序
|
||||
/// </summary>
|
||||
public int Sort { get; set; }
|
||||
|
||||
#region 下面是其它字段。是从设备上读取上来的。
|
||||
|
||||
/// <summary>
|
||||
/// 当前余量
|
||||
/// </summary>
|
||||
public string Remain { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设备状态 1 正常 其它故障
|
||||
/// </summary>
|
||||
public int DeviceStatus { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// PCR值
|
||||
/// </summary>
|
||||
public string PCR { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 浓度
|
||||
/// </summary>
|
||||
public string Concentration { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 密度
|
||||
/// </summary>
|
||||
public string Density { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 重量
|
||||
/// </summary>
|
||||
public string Weight { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
35
middleware/zdhsys/Bean/FlowModel.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using SQLite;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace zdhsys.Bean
|
||||
{
|
||||
public class FlowModel
|
||||
{
|
||||
[PrimaryKey, AutoIncrement]
|
||||
public int Id { get; set; }
|
||||
/// <summary>
|
||||
/// 流程名称
|
||||
/// </summary>
|
||||
public string FlowName { get; set; }
|
||||
/// <summary>
|
||||
/// 流程编号
|
||||
/// </summary>
|
||||
public string FlowNO { get; set; }
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public long CreateTime { get; set; }
|
||||
/// <summary>
|
||||
/// 流程状态 0正常 1禁用
|
||||
/// </summary>
|
||||
public int Status { get; set; }
|
||||
/// <summary>
|
||||
/// 流程详情
|
||||
/// </summary>
|
||||
public string FlowJson { get; set; }
|
||||
}
|
||||
}
|
||||
31
middleware/zdhsys/Bean/OptionFieldsModel.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace zdhsys.Bean
|
||||
{
|
||||
/// <summary>
|
||||
/// 子配方字段
|
||||
/// </summary>
|
||||
public class OptionFieldsModel
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备ID
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
/// <summary>
|
||||
/// 设备编号
|
||||
/// </summary>
|
||||
public string DeviceId { get; set; }
|
||||
/// <summary>
|
||||
/// 设备标签名
|
||||
/// </summary>
|
||||
public string TagName { get; set; }
|
||||
/// <summary>
|
||||
/// 数值
|
||||
/// </summary>
|
||||
public string TagValue { get; set; }
|
||||
}
|
||||
}
|
||||
41
middleware/zdhsys/Bean/OptionFieldsModel2.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace zdhsys.Bean
|
||||
{
|
||||
/// <summary>
|
||||
/// 子配方字段
|
||||
/// </summary>
|
||||
public class OptionFieldsModel2
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备ID
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
/// <summary>
|
||||
/// 设备编号
|
||||
/// </summary>
|
||||
public string DeviceId { get; set; }
|
||||
/// <summary>
|
||||
/// 设备标签名
|
||||
/// </summary>
|
||||
public string TagName { get; set; }
|
||||
/// <summary>
|
||||
/// 数值
|
||||
/// </summary>
|
||||
public string TagValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否是子配方
|
||||
/// </summary>
|
||||
public bool IsSub { get; set; }
|
||||
/// <summary>
|
||||
/// 子配方ID
|
||||
/// </summary>
|
||||
public int SubId { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
16
middleware/zdhsys/Bean/OptionModel.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace zdhsys.Bean
|
||||
{
|
||||
public class OptionModel
|
||||
{
|
||||
public string Column1 { get; set; }
|
||||
public string Column2 { get; set; }
|
||||
public string Column3 { get; set; }
|
||||
public string Column4 { get; set; }
|
||||
}
|
||||
}
|
||||
36
middleware/zdhsys/Bean/Options.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using SQLite;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace zdhsys.Bean
|
||||
{
|
||||
public class Options
|
||||
{
|
||||
[PrimaryKey, AutoIncrement]
|
||||
public int Id { get; set; }
|
||||
/// <summary>
|
||||
/// 配方名称
|
||||
/// </summary>
|
||||
public string OptionName { get; set; }
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public long CreateTime { get; set; }
|
||||
/// <summary>
|
||||
/// 配方状态 0正常 1已作废
|
||||
/// </summary>
|
||||
public int Status { get; set; }
|
||||
/// <summary>
|
||||
/// 配方详情
|
||||
/// </summary>
|
||||
public string OptionJson { get; set; }
|
||||
/// <summary>
|
||||
/// 使用流程
|
||||
/// </summary>
|
||||
public int FlowId { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
23
middleware/zdhsys/Bean/RobotInfoModel.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using SQLite;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace zdhsys.Bean
|
||||
{
|
||||
public class RobotInfoModel
|
||||
{
|
||||
[PrimaryKey, AutoIncrement]
|
||||
public int Id { get; set; }
|
||||
/// <summary>
|
||||
/// 机械臂IP
|
||||
/// </summary>
|
||||
public string RobotIP { get; set; }
|
||||
/// <summary>
|
||||
/// 机械臂PORT
|
||||
/// </summary>
|
||||
public string RobotPort { get; set; }
|
||||
}
|
||||
}
|
||||
36
middleware/zdhsys/Bean/SubOptionModel.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using SQLite;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace zdhsys.Bean
|
||||
{
|
||||
public class SubOptionModel
|
||||
{
|
||||
[PrimaryKey, AutoIncrement]
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 子配方名称
|
||||
/// </summary>
|
||||
public string SubOptionName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public long CreateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 配方状态 0正常 1已作废
|
||||
/// </summary>
|
||||
public int Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 标签集合JSON
|
||||
/// </summary>
|
||||
public string OptionJson { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
23
middleware/zdhsys/Control/ClearDevice.xaml
Normal file
@@ -0,0 +1,23 @@
|
||||
<UserControl x:Class="zdhsys.Control.ClearDevice"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:zdhsys.Control"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="150" d:DesignWidth="100">
|
||||
<Grid>
|
||||
<Border x:Name="bd" CornerRadius="10" Margin="3" Background="White" BorderBrush="#4E89FF" BorderThickness="1">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<Label x:Name="lbName" Content="清洗设备" Style="{StaticResource CommonStyleBold}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
<Image x:Name="img" Grid.Row="1" Height="40" Width="40"/>
|
||||
<Label x:Name="lbStatus" Grid.Row="2" Content="自检中..." FontSize="12" Foreground="#4E89FF" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
36
middleware/zdhsys/Control/ClearDevice.xaml.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace zdhsys.Control
|
||||
{
|
||||
/// <summary>
|
||||
/// ClearDevice.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class ClearDevice : UserControl
|
||||
{
|
||||
public ClearDevice()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
public void SetUI(string name,string status,string path)
|
||||
{
|
||||
Uri imageUri = new Uri(AppDomain.CurrentDomain.BaseDirectory + path);
|
||||
BitmapImage bitmapImage = new BitmapImage(imageUri);
|
||||
img.Source = bitmapImage;
|
||||
lbName.Content = name;
|
||||
lbStatus.Content = status;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
middleware/zdhsys/Control/ColorButton.xaml
Normal file
@@ -0,0 +1,13 @@
|
||||
<UserControl x:Class="zdhsys.Control.ColorButton"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:zdhsys.Control"
|
||||
mc:Ignorable="d"
|
||||
MouseLeftButtonDown="UserControl_MouseLeftButtonDown"
|
||||
d:DesignHeight="20" d:DesignWidth="20">
|
||||
<Grid x:Name="gd" Background="Green">
|
||||
<Label x:Name="lb_gou" Content="√" Visibility="Hidden" FontSize="15" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0" Padding="0"></Label>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
52
middleware/zdhsys/Control/ColorButton.xaml.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace zdhsys.Control
|
||||
{
|
||||
/// <summary>
|
||||
/// ColorButton.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class ColorButton : UserControl
|
||||
{
|
||||
public ColorButton()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
public event RoutedEventHandler Click;
|
||||
|
||||
public bool isCheck = false;
|
||||
public void SetUI(string hexColor)
|
||||
{
|
||||
Color color = (Color)ColorConverter.ConvertFromString(hexColor);
|
||||
SolidColorBrush brush = new SolidColorBrush(color);
|
||||
gd.Background = brush;
|
||||
}
|
||||
public void SetIsCheck(bool flag)
|
||||
{
|
||||
isCheck = flag;
|
||||
lb_gou.Visibility = isCheck ? Visibility.Visible : Visibility.Hidden;
|
||||
}
|
||||
|
||||
private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
//isCheck = !isCheck;
|
||||
//lb_gou.Visibility = isCheck ? Visibility.Visible : Visibility.Hidden;
|
||||
if (Click != null)
|
||||
{
|
||||
Click.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
27
middleware/zdhsys/Control/DevButton.xaml
Normal file
@@ -0,0 +1,27 @@
|
||||
<UserControl x:Class="zdhsys.Control.DevButton"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:zdhsys.Control"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="40" d:DesignWidth="100">
|
||||
<Grid>
|
||||
<Border x:Name="bd" CornerRadius="5" Margin="3" Background="White" BorderBrush="#0080FF" BorderThickness="2">
|
||||
<Button x:Name="btn" Background="Transparent">
|
||||
<Button.Template>
|
||||
<ControlTemplate TargetType="Button">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="1*"/>
|
||||
<ColumnDefinition Width="2*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Image x:Name="img" HorizontalAlignment="Right" Width="15" Height="15" Margin="3"/>
|
||||
<Label x:Name="tbk" Grid.Column="2" Content="Button" VerticalAlignment="Center" HorizontalContentAlignment="Left" Margin="0"/>
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
</Button.Template>
|
||||
</Button>
|
||||
</Border>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
82
middleware/zdhsys/Control/DevButton.xaml.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace zdhsys.Control
|
||||
{
|
||||
/// <summary>
|
||||
/// DevButton.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class DevButton : UserControl
|
||||
{
|
||||
public DevButton()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
Image img;
|
||||
Label tbk;
|
||||
public event RoutedEventHandler Click;
|
||||
|
||||
/// <summary>
|
||||
/// 设置按钮样式
|
||||
/// </summary>
|
||||
/// <param name="hexBG">按钮背景色</param>
|
||||
/// <param name="hexBd">按钮边框色</param>
|
||||
/// <param name="path">图标相对路径</param>
|
||||
/// <param name="hexTxt">按钮文本颜色</param>
|
||||
/// <param name="txt">按钮文本</param>
|
||||
public void SetUI(string hexBG,string hexBd,string path,string hexTxt,string txt)
|
||||
{
|
||||
Color color = (Color)ColorConverter.ConvertFromString(hexBG);
|
||||
SolidColorBrush brush = new SolidColorBrush(color);
|
||||
bd.Background = brush;
|
||||
|
||||
Color color1 = (Color)ColorConverter.ConvertFromString(hexBd);
|
||||
SolidColorBrush brush1 = new SolidColorBrush(color1);
|
||||
bd.BorderBrush = brush1;
|
||||
|
||||
img = btn.Template.FindName("img", btn) as Image;
|
||||
tbk = btn.Template.FindName("tbk", btn) as Label;
|
||||
|
||||
Uri imageUri = new Uri(AppDomain.CurrentDomain.BaseDirectory + path);
|
||||
BitmapImage bitmapImage = new BitmapImage(imageUri);
|
||||
img.Source = bitmapImage;
|
||||
|
||||
Color color2 = (Color)ColorConverter.ConvertFromString(hexTxt);
|
||||
SolidColorBrush brush2 = new SolidColorBrush(color2);
|
||||
tbk.Foreground = brush2;
|
||||
tbk.Content = txt;
|
||||
|
||||
btn.Click += Btn_Click;
|
||||
}
|
||||
/// <summary>
|
||||
/// 按钮单击事件传递
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void Btn_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (Click != null)
|
||||
{
|
||||
Click.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
|
||||
private void UserControl_MouseDoubleClick(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
20
middleware/zdhsys/Control/DevButton0.xaml
Normal file
@@ -0,0 +1,20 @@
|
||||
<UserControl x:Class="zdhsys.Control.DevButton0"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:zdhsys.Control"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="40" d:DesignWidth="100">
|
||||
<Grid>
|
||||
<Border x:Name="bd" CornerRadius="5" Margin="3" Background="White" BorderBrush="#0080FF" BorderThickness="2">
|
||||
<Button x:Name="btn" Background="Transparent">
|
||||
<Button.Template>
|
||||
<ControlTemplate TargetType="Button">
|
||||
<Label x:Name="tbk" Content="Button" HorizontalContentAlignment="Center" Margin="3"/>
|
||||
</ControlTemplate>
|
||||
</Button.Template>
|
||||
</Button>
|
||||
</Border>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
71
middleware/zdhsys/Control/DevButton0.xaml.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace zdhsys.Control
|
||||
{
|
||||
/// <summary>
|
||||
/// DevButton.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class DevButton0 : UserControl
|
||||
{
|
||||
public DevButton0()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
Label tbk;
|
||||
public event RoutedEventHandler Click;
|
||||
|
||||
/// <summary>
|
||||
/// 设置按钮样式
|
||||
/// </summary>
|
||||
/// <param name="hexBG">按钮背景色</param>
|
||||
/// <param name="hexBd">按钮边框色</param>
|
||||
/// <param name="path">图标相对路径</param>
|
||||
/// <param name="hexTxt">按钮文本颜色</param>
|
||||
/// <param name="txt">按钮文本</param>
|
||||
public void SetUI(string hexBG,string hexBd,string hexTxt,string txt)
|
||||
{
|
||||
Color color = (Color)ColorConverter.ConvertFromString(hexBG);
|
||||
SolidColorBrush brush = new SolidColorBrush(color);
|
||||
bd.Background = brush;
|
||||
|
||||
Color color1 = (Color)ColorConverter.ConvertFromString(hexBd);
|
||||
SolidColorBrush brush1 = new SolidColorBrush(color1);
|
||||
bd.BorderBrush = brush1;
|
||||
|
||||
tbk = btn.Template.FindName("tbk", btn) as Label;
|
||||
|
||||
Color color2 = (Color)ColorConverter.ConvertFromString(hexTxt);
|
||||
SolidColorBrush brush2 = new SolidColorBrush(color2);
|
||||
tbk.Foreground = brush2;
|
||||
tbk.Content = txt;
|
||||
|
||||
btn.Click += Btn_Click;
|
||||
}
|
||||
/// <summary>
|
||||
/// 按钮单击事件传递
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void Btn_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (Click != null)
|
||||
{
|
||||
Click.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
22
middleware/zdhsys/Control/DevButton1.xaml
Normal file
@@ -0,0 +1,22 @@
|
||||
<UserControl x:Class="zdhsys.Control.DevButton1"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:zdhsys.Control"
|
||||
mc:Ignorable="d"
|
||||
MouseLeftButtonDown="UserControl_MouseLeftButtonDown"
|
||||
d:DesignHeight="30" d:DesignWidth="100">
|
||||
<Grid>
|
||||
<Border x:Name="bd" CornerRadius="5" Margin="3" Background="White" BorderBrush="#0080FF" BorderThickness="2">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="1.5*"/>
|
||||
<ColumnDefinition Width="2*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Image x:Name="img" HorizontalAlignment="Right" Height="15" Width="15" Margin="3,0,3,0"/>
|
||||
<Label x:Name="tbk" Grid.Column="2" Padding="0" Content="Btn" VerticalAlignment="Center" HorizontalContentAlignment="Left" Margin="3,0,3,0"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
72
middleware/zdhsys/Control/DevButton1.xaml.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace zdhsys.Control
|
||||
{
|
||||
/// <summary>
|
||||
/// DevButton.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class DevButton1 : UserControl
|
||||
{
|
||||
public DevButton1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public event RoutedEventHandler Click;
|
||||
|
||||
/// <summary>
|
||||
/// 设置按钮样式
|
||||
/// </summary>
|
||||
/// <param name="hexBG">按钮背景色</param>
|
||||
/// <param name="hexBd">按钮边框色</param>
|
||||
/// <param name="path">图标相对路径</param>
|
||||
/// <param name="hexTxt">按钮文本颜色</param>
|
||||
/// <param name="txt">按钮文本</param>
|
||||
public void SetUI(string hexBG,string hexBd,string path,string hexTxt,string txt)
|
||||
{
|
||||
Color color = (Color)ColorConverter.ConvertFromString(hexBG);
|
||||
SolidColorBrush brush = new SolidColorBrush(color);
|
||||
bd.Background = brush;
|
||||
|
||||
Color color1 = (Color)ColorConverter.ConvertFromString(hexBd);
|
||||
SolidColorBrush brush1 = new SolidColorBrush(color1);
|
||||
bd.BorderBrush = brush1;
|
||||
|
||||
Uri imageUri = new Uri(AppDomain.CurrentDomain.BaseDirectory + path);
|
||||
BitmapImage bitmapImage = new BitmapImage(imageUri);
|
||||
if (img != null)
|
||||
{
|
||||
img.Source = bitmapImage;
|
||||
}
|
||||
|
||||
Color color2 = (Color)ColorConverter.ConvertFromString(hexTxt);
|
||||
SolidColorBrush brush2 = new SolidColorBrush(color2);
|
||||
if (tbk != null)
|
||||
{
|
||||
tbk.Foreground = brush2;
|
||||
tbk.Content = txt;
|
||||
}
|
||||
}
|
||||
|
||||
private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (Click != null)
|
||||
{
|
||||
Click.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
18
middleware/zdhsys/Control/DevButton2.xaml
Normal file
@@ -0,0 +1,18 @@
|
||||
<UserControl x:Class="zdhsys.Control.DevButton2"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:zdhsys.Control"
|
||||
mc:Ignorable="d"
|
||||
MouseLeftButtonDown="UserControl_MouseLeftButtonDown"
|
||||
d:DesignHeight="40" d:DesignWidth="100">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="1.5*"/>
|
||||
<ColumnDefinition Width="2*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Image x:Name="img" HorizontalAlignment="Right" Width="15" Height="15" Margin="0,0,3,0"/>
|
||||
<Label x:Name="tbk" Grid.Column="2" Content="Button" VerticalAlignment="Center" HorizontalContentAlignment="Left" Margin="0,0,0,0"/>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
62
middleware/zdhsys/Control/DevButton2.xaml.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace zdhsys.Control
|
||||
{
|
||||
/// <summary>
|
||||
/// DevButton.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class DevButton2 : UserControl
|
||||
{
|
||||
public DevButton2()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public event RoutedEventHandler Click;
|
||||
|
||||
public string Text;
|
||||
|
||||
/// <summary>
|
||||
/// 设置按钮样式
|
||||
/// </summary>
|
||||
/// <param name="hexBG">按钮背景色</param>
|
||||
/// <param name="hexBd">按钮边框色</param>
|
||||
/// <param name="path">图标相对路径</param>
|
||||
/// <param name="hexTxt">按钮文本颜色</param>
|
||||
/// <param name="txt">按钮文本</param>
|
||||
public void SetUI(string path,string hexTxt,string txt)
|
||||
{
|
||||
Text = txt;
|
||||
Uri imageUri = new Uri(AppDomain.CurrentDomain.BaseDirectory + path);
|
||||
BitmapImage bitmapImage = new BitmapImage(imageUri);
|
||||
img.Source = bitmapImage;
|
||||
|
||||
Color color2 = (Color)ColorConverter.ConvertFromString(hexTxt);
|
||||
SolidColorBrush brush2 = new SolidColorBrush(color2);
|
||||
tbk.Foreground = brush2;
|
||||
tbk.Content = txt;
|
||||
|
||||
}
|
||||
|
||||
private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (Click != null)
|
||||
{
|
||||
Click.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
20
middleware/zdhsys/Control/DevDevice.xaml
Normal file
@@ -0,0 +1,20 @@
|
||||
<UserControl x:Class="zdhsys.Control.DevDevice"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:zdhsys.Control"
|
||||
mc:Ignorable="d"
|
||||
MouseLeftButtonDown="UserControl_MouseLeftButtonDown"
|
||||
MouseEnter="UserControl_MouseEnter"
|
||||
MouseLeave="UserControl_MouseLeave"
|
||||
d:DesignHeight="70" d:DesignWidth="40">
|
||||
<Grid Background="White">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="2*"/>
|
||||
<RowDefinition Height="1*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Image x:Name="img"/>
|
||||
<Label x:Name="dev_name" Content="设备1" Margin="0,0,0,0" FontSize="12" Foreground="#333333" Grid.Row="1" Height="25" HorizontalAlignment="Center"/>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
82
middleware/zdhsys/Control/DevDevice.xaml.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using zdhsys.Popup;
|
||||
using zdhsys.Unitils;
|
||||
|
||||
namespace zdhsys.Control
|
||||
{
|
||||
/// <summary>
|
||||
/// DevDevice.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class DevDevice : UserControl
|
||||
{
|
||||
public DevDevice()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public string DevName = "";
|
||||
|
||||
public void SetUI(string devName,string path)
|
||||
{
|
||||
Uri imageUri = new Uri(AppDomain.CurrentDomain.BaseDirectory + path);
|
||||
BitmapImage bitmapImage = new BitmapImage(imageUri);
|
||||
img.Source = bitmapImage;
|
||||
dev_name.Content = devName;
|
||||
DevName = devName;
|
||||
}
|
||||
|
||||
HomeDeviceInfo info;
|
||||
|
||||
private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (info != null)
|
||||
{
|
||||
info.Close();
|
||||
info = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
Point p = GlobalUnitils.GetScreenPosition(this);
|
||||
Console.WriteLine(p.X + " - " + p.Y);
|
||||
info = new HomeDeviceInfo(p);
|
||||
info.Show();
|
||||
}
|
||||
}
|
||||
|
||||
private void UserControl_MouseEnter(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (info != null)
|
||||
{
|
||||
info.Close();
|
||||
info = null;
|
||||
}
|
||||
Point p = GlobalUnitils.GetScreenPosition(this);
|
||||
//Console.WriteLine(p.X + " - " + p.Y);
|
||||
info = new HomeDeviceInfo(p);
|
||||
info.SetUI(DevName, "断开", "POS", "无");
|
||||
info.Show();
|
||||
}
|
||||
|
||||
private void UserControl_MouseLeave(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (info != null)
|
||||
{
|
||||
info.Close();
|
||||
info = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
51
middleware/zdhsys/Control/DevLiquid.xaml
Normal file
@@ -0,0 +1,51 @@
|
||||
<UserControl x:Class="zdhsys.Control.DevLiquid"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:zdhsys.Control"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="150" d:DesignWidth="300">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="25"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Border x:Name="bd" CornerRadius="10" Margin="3" Background="White" BorderBrush="#4E89FF" BorderThickness="1">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="1*"/>
|
||||
<RowDefinition Height="2.5*"/>
|
||||
<RowDefinition Height="1*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label x:Name="lbName" Content="清洗设备" Margin="20,0,0,0" Style="{StaticResource CommonStyleBold}" HorizontalAlignment="Left" VerticalAlignment="Center"/>
|
||||
<Label x:Name="lbStatus" Grid.Column="1" Content="自检中..." Margin="0,0,20,0" FontSize="12" Foreground="#4E89FF" HorizontalAlignment="Right" VerticalAlignment="Center"/>
|
||||
</Grid>
|
||||
<Grid x:Name="gd" Grid.Row="1" Margin="10,0,10,0" VerticalAlignment="Center">
|
||||
|
||||
</Grid>
|
||||
<Grid Grid.Row="2">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label x:Name="lbTemp" Content="26.5℃" Margin="0,0,0,0" Foreground="#FF0000" FontSize="12" HorizontalAlignment="Left" VerticalAlignment="Center"/>
|
||||
<Label x:Name="lbTime" Grid.Column="1" Content="2023.02.31" Margin="0,0,20,0" FontSize="12" Foreground="#4E89FF" HorizontalAlignment="Right" VerticalAlignment="Center"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Border>
|
||||
<Grid Grid.Row="1">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="50"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Name="lbDaogui" Content="导轨1" Foreground="#333333" FontSize="12" FontWeight="Bold"/>
|
||||
<Border Grid.Column="1" Margin="0,0,10,0" Height="15" CornerRadius="5" BorderThickness="4" Background="#C4D1FF" BorderBrush="#C4D1FF"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
54
middleware/zdhsys/Control/DevLiquid.xaml.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace zdhsys.Control
|
||||
{
|
||||
/// <summary>
|
||||
/// DevLiquid.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class DevLiquid : UserControl
|
||||
{
|
||||
public DevLiquid()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void SetUI(int num, string path, string name, string status, string temp, string time,string daogui)
|
||||
{
|
||||
double wid = ActualWidth;
|
||||
double wids = wid / (num + 1);
|
||||
Console.WriteLine("wids=" + wids);
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
DevDevice newButton = new DevDevice();
|
||||
int index = i + 1;
|
||||
newButton.SetUI("设备" + index, path);
|
||||
// 在 Grid 的列定义中增加一个新列
|
||||
//gd.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
|
||||
gd.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(wids) });
|
||||
|
||||
// 将新按钮添加到 Grid 的新列
|
||||
Grid.SetColumn(newButton, i);
|
||||
gd.Children.Add(newButton);
|
||||
}
|
||||
|
||||
lbName.Content = name;
|
||||
lbStatus.Content = status;
|
||||
lbTemp.Content = !string.IsNullOrEmpty(temp) ? temp + "℃" : "";
|
||||
lbTime.Content = time;
|
||||
lbDaogui.Content = daogui;
|
||||
}
|
||||
}
|
||||
}
|
||||
20
middleware/zdhsys/Control/DevOperation.xaml
Normal file
@@ -0,0 +1,20 @@
|
||||
<UserControl x:Class="zdhsys.Control.DevOperation"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:zdhsys.Control"
|
||||
mc:Ignorable="d"
|
||||
Loaded="UserControl_Loaded"
|
||||
d:DesignHeight="40" d:DesignWidth="200">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<local:DevButton2 Grid.Column="0" x:Name="btn_details"/>
|
||||
<local:DevButton2 Grid.Column="1" x:Name="btn_edit" Margin="10,0,10,0"/>
|
||||
<local:DevButton2 Grid.Column="2" x:Name="btn_del"/>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
68
middleware/zdhsys/Control/DevOperation.xaml.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace zdhsys.Control
|
||||
{
|
||||
/// <summary>
|
||||
/// DevOperation.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class DevOperation : UserControl
|
||||
{
|
||||
public DevOperation()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
public event RoutedEventHandler Click_Details;
|
||||
public event RoutedEventHandler Click_Update;
|
||||
public event RoutedEventHandler Click_Delete;
|
||||
public object obj;
|
||||
private void UserControl_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
btn_details.SetUI("\\Image\\details.png", "#027AFF", "详情");
|
||||
btn_del.SetUI("\\Image\\delete.png", "#FF0000", "删除");
|
||||
btn_edit.SetUI("\\Image\\edit.png", "#027AFF", "修改");
|
||||
|
||||
btn_details.Click += Btn_Click;
|
||||
btn_del.Click += Btn_Click;
|
||||
btn_edit.Click += Btn_Click;
|
||||
}
|
||||
|
||||
private void Btn_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
DevButton2 btn = sender as DevButton2;
|
||||
if(btn.Text == "详情")
|
||||
{
|
||||
if (Click_Details != null)
|
||||
{
|
||||
Click_Details.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
else if (btn.Text == "修改")
|
||||
{
|
||||
if (Click_Update != null)
|
||||
{
|
||||
Click_Update.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
else if (btn.Text == "删除")
|
||||
{
|
||||
if (Click_Delete != null)
|
||||
{
|
||||
Click_Delete.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
18
middleware/zdhsys/Control/DevOperation2.xaml
Normal file
@@ -0,0 +1,18 @@
|
||||
<UserControl x:Class="zdhsys.Control.DevOperation2"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:zdhsys.Control"
|
||||
mc:Ignorable="d"
|
||||
Loaded="UserControl_Loaded"
|
||||
d:DesignHeight="40" d:DesignWidth="150">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<local:DevButton2 Grid.Column="0" x:Name="btn_edit" Margin="0,0,0,0"/>
|
||||
<local:DevButton2 Grid.Column="1" x:Name="btn_del"/>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
58
middleware/zdhsys/Control/DevOperation2.xaml.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace zdhsys.Control
|
||||
{
|
||||
/// <summary>
|
||||
/// DevOperation.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class DevOperation2 : UserControl
|
||||
{
|
||||
public DevOperation2()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
public event RoutedEventHandler Click_Update;
|
||||
public event RoutedEventHandler Click_Delete;
|
||||
public object obj;
|
||||
private void UserControl_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
btn_del.SetUI("\\Image\\delete.png", "#FF0000", "删除");
|
||||
btn_edit.SetUI("\\Image\\edit.png", "#027AFF", "修改");
|
||||
|
||||
btn_del.Click += Btn_Click;
|
||||
btn_edit.Click += Btn_Click;
|
||||
}
|
||||
|
||||
private void Btn_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
DevButton2 btn = sender as DevButton2;
|
||||
if (btn.Text == "修改")
|
||||
{
|
||||
if (Click_Update != null)
|
||||
{
|
||||
Click_Update.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
else if (btn.Text == "删除")
|
||||
{
|
||||
if (Click_Delete != null)
|
||||
{
|
||||
Click_Delete.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
18
middleware/zdhsys/Control/DevOperation3.xaml
Normal file
@@ -0,0 +1,18 @@
|
||||
<UserControl x:Class="zdhsys.Control.DevOperation3"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:zdhsys.Control"
|
||||
mc:Ignorable="d"
|
||||
Loaded="UserControl_Loaded"
|
||||
d:DesignHeight="40" d:DesignWidth="150">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<local:DevButton2 Grid.Column="0" x:Name="btn_edit" Margin="0,0,2,0"/>
|
||||
<local:DevButton2 Grid.Column="1" x:Name="btn_del"/>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
60
middleware/zdhsys/Control/DevOperation3.xaml.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace zdhsys.Control
|
||||
{
|
||||
/// <summary>
|
||||
/// DevOperation.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class DevOperation3 : UserControl
|
||||
{
|
||||
public DevOperation3()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
public event RoutedEventHandler Click_Up;
|
||||
public event RoutedEventHandler Click_Down;
|
||||
public object obj;
|
||||
private readonly string move_up = "上移";
|
||||
private readonly string move_down = "下移";
|
||||
private void UserControl_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
btn_del.SetUI("\\Image\\move_up.png", "#FF0000", move_up);
|
||||
btn_edit.SetUI("\\Image\\move_down.png", "#027AFF", move_down);
|
||||
|
||||
btn_del.Click += Btn_Click;
|
||||
btn_edit.Click += Btn_Click;
|
||||
}
|
||||
|
||||
private void Btn_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
DevButton2 btn = sender as DevButton2;
|
||||
if (btn.Text == move_up)
|
||||
{
|
||||
if (Click_Up != null)
|
||||
{
|
||||
Click_Up.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
else if (btn.Text == move_down)
|
||||
{
|
||||
if (Click_Down != null)
|
||||
{
|
||||
Click_Down.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
38
middleware/zdhsys/Control/DevPaging.xaml
Normal file
@@ -0,0 +1,38 @@
|
||||
<UserControl x:Class="zdhsys.Control.DevPaging"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:zdhsys.Control"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="30" d:DesignWidth="520">
|
||||
<UserControl.Resources>
|
||||
<Style x:Key="common" TargetType="Control">
|
||||
<Setter Property="HorizontalAlignment" Value="Center"/>
|
||||
<Setter Property="VerticalAlignment" Value="Center"/>
|
||||
<Setter Property="FontSize" Value="15"/>
|
||||
</Style>
|
||||
</UserControl.Resources>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Label x:Name="lb_all" Content="共22条" Style="{StaticResource common}"/>
|
||||
<ComboBox x:Name="cbb" Background="White" Style="{StaticResource common}" Margin="20,0,0,0"/>
|
||||
<Button x:Name="btn_left" Click="btn_left_Click" Background="Transparent" Width="30" Height="30" Margin="20,0,0,0" Style="{StaticResource NoBorderButtonStyle2}">
|
||||
<StackPanel Margin="7,0,0,0">
|
||||
<Image x:Name="img_left" Width="15" Height="15" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button x:Name="btn_1" Content="1" Style="{StaticResource NoBorderButtonStyle2}"/>
|
||||
<Button x:Name="btn_2" Content="2" Style="{StaticResource NoBorderButtonStyle2}"/>
|
||||
<Button x:Name="btn_3" Content="3" Style="{StaticResource NoBorderButtonStyle2}"/>
|
||||
<Button x:Name="btn_4" Content="4" Style="{StaticResource NoBorderButtonStyle2}"/>
|
||||
<Button x:Name="btn_5" Content="5" Style="{StaticResource NoBorderButtonStyle2}"/>
|
||||
<Button x:Name="btn_Right" Click="btn_Right_Click" Background="Transparent" Width="30" Height="30" Margin="5,0,0,0" Style="{StaticResource NoBorderButtonStyle2}">
|
||||
<StackPanel Margin="0,0,8,0">
|
||||
<Image x:Name="img_right" Width="15" Height="15" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button x:Name="btn_go" Click="btn_go_Click" Content="前往" Foreground="#333333" Background="Transparent" Width="35" Margin="20,0,0,0" Style="{StaticResource NoBorderButtonStyle2}"/>
|
||||
<TextBox x:Name="txt" HorizontalContentAlignment="Center" PreviewTextInput="txt_PreviewTextInput" Foreground="#333333" Width="40" Height="20" Margin="10,0,0,0"/>
|
||||
<Label Content="页" Style="{StaticResource common}"/>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
300
middleware/zdhsys/Control/DevPaging.xaml.cs
Normal file
@@ -0,0 +1,300 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace zdhsys.Control
|
||||
{
|
||||
/// <summary>
|
||||
/// DevPaging.xaml 的交互逻辑
|
||||
/// 本控件为自定义分页控件
|
||||
/// </summary>
|
||||
public partial class DevPaging : UserControl
|
||||
{
|
||||
public DevPaging()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
InitUI();
|
||||
}
|
||||
public event RoutedEventHandler Click;
|
||||
private void InitUI()
|
||||
{
|
||||
img_left.Source = new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + "\\Image\\arrowLeft.png")); ;
|
||||
img_right.Source = new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + "\\Image\\arrowRight.png"));
|
||||
|
||||
cbb.Items.Add("10条/页");
|
||||
cbb.Items.Add("20条/页");
|
||||
cbb.Items.Add("30条/页");
|
||||
cbb.SelectedIndex = 0;
|
||||
cbb.SelectionChanged += Cbb_SelectionChanged;
|
||||
btn_1.Click += Btn_Click;
|
||||
btn_2.Click += Btn_Click;
|
||||
btn_3.Click += Btn_Click;
|
||||
btn_4.Click += Btn_Click;
|
||||
btn_5.Click += Btn_Click;
|
||||
}
|
||||
|
||||
private void Btn_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Button btn = sender as Button;
|
||||
int p = int.Parse(btn.Content.ToString());
|
||||
page = p;
|
||||
if (Click != null)
|
||||
{
|
||||
Click.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
|
||||
private void Cbb_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
SetNum(all_num);
|
||||
if (Click != null)
|
||||
{
|
||||
Click.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取分页,每页显示数量
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int getPageNum()
|
||||
{
|
||||
if (cbb.SelectedIndex == 1)
|
||||
{
|
||||
return 20;
|
||||
}
|
||||
else if (cbb.SelectedIndex == 2)
|
||||
{
|
||||
return 30;
|
||||
}
|
||||
return 10;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当前选中页--默认为第1页就算没数据也是。
|
||||
/// </summary>
|
||||
public int page = 1;
|
||||
|
||||
/// <summary>
|
||||
/// 总页数
|
||||
/// </summary>
|
||||
public int all_page;
|
||||
|
||||
/// <summary>
|
||||
/// 记录总条数
|
||||
/// </summary>
|
||||
public int all_num;
|
||||
|
||||
/// <summary>
|
||||
/// 设置记录总数
|
||||
/// </summary>
|
||||
/// <param name="num"></param>
|
||||
public void SetNum(int num)
|
||||
{
|
||||
all_num = num;
|
||||
lb_all.Content = "共" + num + "条";
|
||||
int pageSingle = getPageNum();
|
||||
double d = num * 1.0 / pageSingle;
|
||||
int pg = (int)d;
|
||||
if (d > pg)
|
||||
{
|
||||
pg++;
|
||||
}
|
||||
all_page = pg;
|
||||
//先全部放开。
|
||||
btn_1.Visibility = Visibility.Visible;
|
||||
btn_2.Visibility = Visibility.Visible;
|
||||
btn_3.Visibility = Visibility.Visible;
|
||||
btn_4.Visibility = Visibility.Visible;
|
||||
btn_5.Visibility = Visibility.Visible;
|
||||
btn_1.Content = 1;
|
||||
btn_2.Content = 2;
|
||||
btn_3.Content = 3;
|
||||
btn_4.Content = 4;
|
||||
btn_5.Content = 5;
|
||||
if (pg == 0)
|
||||
{
|
||||
btn_1.Visibility = Visibility.Collapsed;
|
||||
btn_2.Visibility = Visibility.Collapsed;
|
||||
btn_3.Visibility = Visibility.Collapsed;
|
||||
btn_4.Visibility = Visibility.Collapsed;
|
||||
btn_5.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
else if (pg == 1)
|
||||
{
|
||||
btn_2.Visibility = Visibility.Collapsed;
|
||||
btn_3.Visibility = Visibility.Collapsed;
|
||||
btn_4.Visibility = Visibility.Collapsed;
|
||||
btn_5.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
else if (pg == 2)
|
||||
{
|
||||
btn_3.Visibility = Visibility.Collapsed;
|
||||
btn_4.Visibility = Visibility.Collapsed;
|
||||
btn_5.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
else if (pg == 3)
|
||||
{
|
||||
btn_4.Visibility = Visibility.Collapsed;
|
||||
btn_5.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
else if (pg == 4)
|
||||
{
|
||||
btn_5.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
//这里多做一个判断,就是删除了之后,当数量已经不能支撑当前页数,就减1
|
||||
if (num == 0)
|
||||
{
|
||||
page = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (getPageNum() * (page - 1) >= num)
|
||||
{
|
||||
if (page > 1)
|
||||
{
|
||||
page--;
|
||||
}
|
||||
//if (Click != null)
|
||||
//{
|
||||
// Click.Invoke(this, null);
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void btn_go_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(txt.Text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int p = int.Parse(txt.Text);
|
||||
// 如果超出范围,就显示当前页码
|
||||
if (p <= 0 || p > all_page)
|
||||
{
|
||||
txt.Text = page.ToString();
|
||||
return;
|
||||
}
|
||||
//设置当前页码
|
||||
page = p;
|
||||
|
||||
if (all_page < 5)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//处理跳转页码
|
||||
//判断页码是否在当前显示的范围。如果是的话,就不处理
|
||||
if (btn_1.Content.ToString() == p.ToString()
|
||||
|| btn_2.Content.ToString() == p.ToString()
|
||||
|| btn_3.Content.ToString() == p.ToString()
|
||||
|| btn_4.Content.ToString() == p.ToString()
|
||||
|| btn_5.Content.ToString() == p.ToString())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (p + 2 <= all_page)
|
||||
{
|
||||
btn_3.Content = page;
|
||||
btn_4.Content = page + 1;
|
||||
btn_5.Content = page + 2;
|
||||
}
|
||||
else if (p + 1 == all_page)
|
||||
{
|
||||
btn_3.Content = page - 1;
|
||||
btn_4.Content = page;
|
||||
btn_5.Content = page + 1;
|
||||
}
|
||||
else if (p == all_page)
|
||||
{
|
||||
btn_3.Content = page - 2;
|
||||
btn_4.Content = page - 1;
|
||||
btn_5.Content = page;
|
||||
}
|
||||
if (Click != null)
|
||||
{
|
||||
Click.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 只能输入整数
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void txt_PreviewTextInput(object sender, TextCompositionEventArgs e)
|
||||
{
|
||||
if (!int.TryParse(e.Text, out _))
|
||||
{
|
||||
e.Handled = true; // 阻止输入
|
||||
}
|
||||
}
|
||||
|
||||
private void btn_left_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (page == 1)
|
||||
{
|
||||
return;//最小值了。
|
||||
}
|
||||
page--;
|
||||
txt.Text = page.ToString();
|
||||
if (Click != null)
|
||||
{
|
||||
Click.Invoke(this, e);
|
||||
}
|
||||
flush();
|
||||
}
|
||||
|
||||
private void flush()
|
||||
{
|
||||
//这里要判断一下,如果页面上没有这个页码的话,就刷新一下按钮的显示
|
||||
//判断页码是否在当前显示的范围。如果是的话,就不处理
|
||||
if (btn_1.Content.ToString() == page.ToString()
|
||||
|| btn_2.Content.ToString() == page.ToString()
|
||||
|| btn_3.Content.ToString() == page.ToString()
|
||||
|| btn_4.Content.ToString() == page.ToString()
|
||||
|| btn_5.Content.ToString() == page.ToString())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (page + 2 <= all_page)
|
||||
{
|
||||
btn_3.Content = page;
|
||||
btn_4.Content = page + 1;
|
||||
btn_5.Content = page + 2;
|
||||
}
|
||||
else if (page + 1 == all_page)
|
||||
{
|
||||
btn_3.Content = page - 1;
|
||||
btn_4.Content = page;
|
||||
btn_5.Content = page + 1;
|
||||
}
|
||||
else if (page == all_page)
|
||||
{
|
||||
btn_3.Content = page - 2;
|
||||
btn_4.Content = page - 1;
|
||||
btn_5.Content = page;
|
||||
}
|
||||
}
|
||||
|
||||
private void btn_Right_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (page == all_page)
|
||||
{
|
||||
return;
|
||||
}
|
||||
page++;
|
||||
txt.Text = page.ToString();
|
||||
if (Click != null)
|
||||
{
|
||||
Click.Invoke(this, e);
|
||||
}
|
||||
flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
23
middleware/zdhsys/Control/DevRobot.xaml
Normal file
@@ -0,0 +1,23 @@
|
||||
<UserControl x:Class="zdhsys.Control.DevRobot"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:zdhsys.Control"
|
||||
mc:Ignorable="d"
|
||||
Loaded="UserControl_Loaded"
|
||||
MouseLeftButtonDown="UserControl_MouseLeftButtonDown"
|
||||
MouseEnter="UserControl_MouseEnter"
|
||||
MouseLeave="UserControl_MouseLeave"
|
||||
d:DesignHeight="100" d:DesignWidth="80">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<Label x:Name="lbName" Content="导轨机器人" Style="{StaticResource CommonStyleBold}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
<Image x:Name="img" Grid.Row="1" Height="40" Width="40"/>
|
||||
<Label x:Name="lbStatus" Grid.Row="2" Content="自检中..." FontSize="12" Foreground="#4E89FF" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
95
middleware/zdhsys/Control/DevRobot.xaml.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using zdhsys.entity;
|
||||
using zdhsys.Popup;
|
||||
using zdhsys.Unitils;
|
||||
|
||||
namespace zdhsys.Control
|
||||
{
|
||||
/// <summary>
|
||||
/// DevRobot.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class DevRobot : UserControl
|
||||
{
|
||||
public DevRobot()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void SetUI(string name, string status, string path)
|
||||
{
|
||||
Uri imageUri = new Uri(AppDomain.CurrentDomain.BaseDirectory + path);
|
||||
BitmapImage bitmapImage = new BitmapImage(imageUri);
|
||||
img.Source = bitmapImage;
|
||||
lbName.Content = name;
|
||||
lbStatus.Content = status;
|
||||
DevName = name;
|
||||
}
|
||||
HomeDeviceInfo info;
|
||||
private void UserControl_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (info != null)
|
||||
{
|
||||
info.Close();
|
||||
info = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
Point p = GlobalUnitils.GetScreenPosition(this);
|
||||
Console.WriteLine(p.X + " - " + p.Y);
|
||||
info = new HomeDeviceInfo(p);
|
||||
info.Show();
|
||||
}
|
||||
}
|
||||
|
||||
public string DevName = "";
|
||||
public Heart ht;
|
||||
public RobotHeart rh;
|
||||
|
||||
private void UserControl_MouseEnter(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (info != null)
|
||||
{
|
||||
info.Close();
|
||||
info = null;
|
||||
}
|
||||
Point p = GlobalUnitils.GetScreenPosition(this);
|
||||
info = new HomeDeviceInfo(p);
|
||||
if (ht != null)
|
||||
{
|
||||
info.SetUI(DevName, ht.rob_sta == 0 ? "空闲" : "执行中", ht.ID + "", rh.cmd + "");
|
||||
}
|
||||
else
|
||||
{
|
||||
info.SetUI(DevName, "断开", "", "");
|
||||
}
|
||||
info.Show();
|
||||
}
|
||||
|
||||
private void UserControl_MouseLeave(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (info != null)
|
||||
{
|
||||
info.Close();
|
||||
info = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
44
middleware/zdhsys/Control/DevTextBox.xaml
Normal file
@@ -0,0 +1,44 @@
|
||||
<UserControl x:Class="zdhsys.Control.DevTextBox"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:zdhsys.Control"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="50" d:DesignWidth="100">
|
||||
<UserControl.Resources>
|
||||
<Style x:Key="FlatTextBoxStyle" TargetType="TextBox">
|
||||
<Setter Property="Background" Value="White"/>
|
||||
<Setter Property="BorderBrush" Value="Gray"/>
|
||||
<Setter Property="Foreground" Value="Black"/>
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
<Setter Property="Padding" Value="2"/>
|
||||
<Setter Property="SnapsToDevicePixels" Value="True"/>
|
||||
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="TextBox">
|
||||
<Border Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
CornerRadius="5">
|
||||
<ScrollViewer x:Name="PART_ContentHost"/>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter TargetName="PART_ContentHost" Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsFocused" Value="True">
|
||||
<Setter TargetName="PART_ContentHost" Property="Background" Value="LightBlue"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</UserControl.Resources>
|
||||
<Grid Background="White" VerticalAlignment="Center">
|
||||
<TextBox Padding="5,0,0,0" Height="30" x:Name="textBox" Style="{StaticResource FlatTextBoxStyle}" Foreground="Gray" Text="请输入姓名" GotFocus="TextBox_GotFocus" LostFocus="TextBox_GotFocus" VerticalContentAlignment="Center" />
|
||||
</Grid>
|
||||
</UserControl>
|
||||
81
middleware/zdhsys/Control/DevTextBox.xaml.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace zdhsys.Control
|
||||
{
|
||||
/// <summary>
|
||||
/// DevTextBox.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class DevTextBox : UserControl
|
||||
{
|
||||
public DevTextBox()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
private string Tips = "";
|
||||
public void SetUI(string tips)
|
||||
{
|
||||
textBox.Text = tips;
|
||||
Tips = tips;
|
||||
}
|
||||
|
||||
public string Text()
|
||||
{
|
||||
if (textBox.Text == Tips) return "";
|
||||
return textBox.Text;
|
||||
}
|
||||
|
||||
public void SetText(string text)
|
||||
{
|
||||
textBox.Text = text;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置只能输入数字
|
||||
/// </summary>
|
||||
public void SetNumber()
|
||||
{
|
||||
textBox.PreviewKeyDown += TextBox_PreviewKeyDown;
|
||||
}
|
||||
|
||||
private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
// 只允许输入数字和一些特殊按键
|
||||
if (!((Key.D0 <= e.Key && e.Key <= Key.D9) || // 数字键盘上的数字
|
||||
(Key.NumPad0 <= e.Key && e.Key <= Key.NumPad9) || // 主键盘上的数字
|
||||
e.Key == Key.Back || // 退格键
|
||||
e.Key == Key.Delete || // 删除键
|
||||
e.Key == Key.Tab || // Tab 键
|
||||
e.Key == Key.Left || e.Key == Key.Right)) // 左右方向键
|
||||
{
|
||||
e.Handled = true; // 拦截非数字键
|
||||
}
|
||||
}
|
||||
|
||||
private void TextBox_GotFocus(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (textBox.Text == Tips)
|
||||
{
|
||||
textBox.Text = "";
|
||||
textBox.Foreground = Brushes.Black;
|
||||
}
|
||||
else if (string.IsNullOrEmpty(textBox.Text))
|
||||
{
|
||||
textBox.Text = Tips;
|
||||
textBox.Foreground = Brushes.Gray;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
39
middleware/zdhsys/Control/DeviceGroup.xaml
Normal file
@@ -0,0 +1,39 @@
|
||||
<UserControl x:Class="zdhsys.Control.DeviceGroup"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:zdhsys.Control"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="150" d:DesignWidth="300">
|
||||
<Grid>
|
||||
<Border x:Name="bd" CornerRadius="10" Margin="3" Background="White" BorderBrush="#4E89FF" BorderThickness="1">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="1.5*"/>
|
||||
<RowDefinition Height="2.5*"/>
|
||||
<RowDefinition Height="1*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label x:Name="lbName" Content="清洗设备" Margin="20,0,0,0" Style="{StaticResource CommonStyleBold}" HorizontalAlignment="Left" VerticalAlignment="Center"/>
|
||||
<Label x:Name="lbStatus" Grid.Column="1" Content="自检中..." Margin="0,0,20,0" FontSize="12" Foreground="#4E89FF" HorizontalAlignment="Right" VerticalAlignment="Center"/>
|
||||
</Grid>
|
||||
<Grid x:Name="gd" Grid.Row="1" Margin="10,0,10,0" VerticalAlignment="Center">
|
||||
|
||||
</Grid>
|
||||
<Grid Grid.Row="2">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label x:Name="lbTemp" Content="26.5℃" Margin="20,0,0,0" Foreground="#FF0000" FontSize="12" HorizontalAlignment="Left" VerticalAlignment="Center"/>
|
||||
<Label x:Name="lbTime" Grid.Column="1" Content="2023.02.31" Margin="0,0,20,0" FontSize="12" Foreground="#333333" HorizontalAlignment="Right" VerticalAlignment="Center"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
61
middleware/zdhsys/Control/DeviceGroup.xaml.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace zdhsys.Control
|
||||
{
|
||||
/// <summary>
|
||||
/// DeviceGroup.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class DeviceGroup : UserControl
|
||||
{
|
||||
public DeviceGroup()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void SetUI(int num,string path,string name,string status,string temp,string time)
|
||||
{
|
||||
Console.WriteLine("DeviceGroup width="+this.ActualWidth);
|
||||
double wid = ActualWidth;
|
||||
double wids = wid / (num + 1);
|
||||
Console.WriteLine("wids=" + wids);
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
DevDevice newButton = new DevDevice();
|
||||
int index = i + 1;
|
||||
newButton.SetUI("设备" + index, path);
|
||||
// 在 Grid 的列定义中增加一个新列
|
||||
//gd.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
|
||||
gd.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(wids) });
|
||||
|
||||
// 将新按钮添加到 Grid 的新列
|
||||
Grid.SetColumn(newButton, i);
|
||||
gd.Children.Add(newButton);
|
||||
}
|
||||
|
||||
lbName.Content = name;
|
||||
lbStatus.Content = status;
|
||||
if(!string.IsNullOrEmpty(temp))
|
||||
{
|
||||
lbTemp.Content = temp + "℃";
|
||||
}
|
||||
else
|
||||
{
|
||||
lbTemp.Content = "";
|
||||
}
|
||||
lbTime.Content = time;
|
||||
}
|
||||
}
|
||||
}
|
||||
20
middleware/zdhsys/Control/DeviceTab.xaml
Normal file
@@ -0,0 +1,20 @@
|
||||
<UserControl x:Class="zdhsys.Control.DeviceTab"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:zdhsys.Control"
|
||||
mc:Ignorable="d"
|
||||
Loaded="UserControl_Loaded"
|
||||
d:DesignHeight="30" d:DesignWidth="300">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="80*"/>
|
||||
<ColumnDefinition Width="80*"/>
|
||||
<ColumnDefinition Width="80*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<local:TabButton x:Name="btn_device" Grid.Column="0"/>
|
||||
<local:TabButton x:Name="btn_device_group" Grid.Column="1" Visibility="Hidden"/>
|
||||
<local:TabButton x:Name="btn_class" Grid.Column="2" Visibility="Hidden"/>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
75
middleware/zdhsys/Control/DeviceTab.xaml.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace zdhsys.Control
|
||||
{
|
||||
/// <summary>
|
||||
/// DeviceTab.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class DeviceTab : UserControl
|
||||
{
|
||||
public DeviceTab()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public event RoutedEventHandler Click_Device;
|
||||
public event RoutedEventHandler Click_DeviceGroup;
|
||||
public event RoutedEventHandler Click_Class;
|
||||
|
||||
public string str_1 = "设备管理";
|
||||
public string str_2 = "设备组管理";
|
||||
public string str_3 = "类别管理";
|
||||
|
||||
private void UserControl_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
btn_device.SetUI(str_1);
|
||||
btn_device.Click += Btn_Click;
|
||||
btn_device.SetCheck(true);
|
||||
|
||||
|
||||
btn_device_group.SetUI(str_2);
|
||||
btn_device_group.Click += Btn_Click;
|
||||
btn_device_group.SetCheck(false);
|
||||
|
||||
btn_class.SetUI(str_3);
|
||||
btn_class.Click += Btn_Click;
|
||||
btn_class.SetCheck(false);
|
||||
}
|
||||
|
||||
private void Btn_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
TabButton tab = sender as TabButton;
|
||||
if (tab.Text == str_1)
|
||||
{
|
||||
btn_device.SetCheck(true);
|
||||
btn_device_group.SetCheck(false);
|
||||
btn_class.SetCheck(false);
|
||||
if (Click_Device != null)
|
||||
{
|
||||
Click_Device.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
else if (tab.Text == str_2)
|
||||
{
|
||||
btn_device.SetCheck(false);
|
||||
btn_device_group.SetCheck(true);
|
||||
btn_class.SetCheck(false);
|
||||
if (Click_DeviceGroup != null)
|
||||
{
|
||||
Click_DeviceGroup.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
else if (tab.Text == str_3)
|
||||
{
|
||||
btn_device.SetCheck(false);
|
||||
btn_device_group.SetCheck(false);
|
||||
btn_class.SetCheck(true);
|
||||
if (Click_Class != null)
|
||||
{
|
||||
Click_Class.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
49
middleware/zdhsys/Control/DevpButton.xaml
Normal file
@@ -0,0 +1,49 @@
|
||||
<UserControl x:Class="zdhsys.Control.DevpButton"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:zdhsys.Control"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="40" d:DesignWidth="150">
|
||||
<Grid>
|
||||
<Button x:Name="btn" Click="btn_Click" Background="LightBlue" BorderBrush="Transparent">
|
||||
<Button.Template>
|
||||
<ControlTemplate TargetType="Button">
|
||||
<Grid>
|
||||
<Border Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="5">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="1*"/>
|
||||
<ColumnDefinition Width="0.2*"/>
|
||||
<ColumnDefinition Width="2*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Image x:Name="img" HorizontalAlignment="Right" Width="15" Height="15" Margin="5"/>
|
||||
<TextBlock x:Name="tbk" Grid.Column="2" Text="Button Text" VerticalAlignment="Center" Margin="5"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
</Button.Template>
|
||||
</Button>
|
||||
<Button x:Name="btn2" Click="btn_Click" Background="White" BorderBrush="Transparent">
|
||||
<Button.Template>
|
||||
<ControlTemplate TargetType="Button">
|
||||
<Grid>
|
||||
<Border Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="5">
|
||||
<Grid>
|
||||
<Image x:Name="img2" Width="15" Height="15"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
</Button.Template>
|
||||
</Button>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
189
middleware/zdhsys/Control/DevpButton.xaml.cs
Normal file
@@ -0,0 +1,189 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace zdhsys.Control
|
||||
{
|
||||
/// <summary>
|
||||
/// DevpButton.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class DevpButton : UserControl
|
||||
{
|
||||
public DevpButton()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private bool flag = false; // 是否选中
|
||||
private bool max = true; // 是大,还是小
|
||||
// 按钮文本
|
||||
public string btnName = "主页";
|
||||
|
||||
Image img;
|
||||
Image img2;
|
||||
TextBlock tbk;
|
||||
// 把单击事件传出去。
|
||||
public event RoutedEventHandler Click;
|
||||
|
||||
// 配色
|
||||
string hex1 = "#98A3FE";
|
||||
string hex2 = "#FFFFFF";
|
||||
string hex3 = "#465785";
|
||||
private static string basePath = "\\Image\\menu\\";
|
||||
// 白色ICO
|
||||
string imgPath = basePath + "主页.png";
|
||||
// 黑色ICO
|
||||
string imgPath2 = basePath + "主页2.png";
|
||||
|
||||
// 封装主菜单所有ICO切换
|
||||
public void Set_Name(string name)
|
||||
{
|
||||
InitUI();
|
||||
btnName = name;
|
||||
switch (btnName)
|
||||
{
|
||||
case "主页":
|
||||
imgPath = basePath + "主页.png";
|
||||
imgPath2 = basePath + "主页2.png";
|
||||
break;
|
||||
case "配方管理":
|
||||
imgPath = basePath + "配方.png";
|
||||
imgPath2 = basePath + "配方2.png";
|
||||
break;
|
||||
case "流程管理":
|
||||
imgPath = basePath + "流程.png";
|
||||
imgPath2 = basePath + "流程2.png";
|
||||
break;
|
||||
case "设备管理":
|
||||
imgPath = basePath + "设备.png";
|
||||
imgPath2 = basePath + "设备2.png";
|
||||
break;
|
||||
case "数据管理":
|
||||
imgPath = basePath + "数据.png";
|
||||
imgPath2 = basePath + "数据2.png";
|
||||
break;
|
||||
}
|
||||
updateUI(hex2, hex3, imgPath2);
|
||||
}
|
||||
|
||||
|
||||
// 大小按钮单击事件
|
||||
private void btn_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
flag = true;
|
||||
if (flag)
|
||||
{
|
||||
if (max)
|
||||
updateUI(hex1, hex2, imgPath);
|
||||
else
|
||||
updateUI2(hex1, imgPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (max)
|
||||
updateUI(hex2, hex3, imgPath2);
|
||||
else
|
||||
updateUI2(hex2, imgPath2);
|
||||
}
|
||||
if(Click != null)
|
||||
Click.Invoke(this, e);
|
||||
}
|
||||
|
||||
// 更新大按钮界面
|
||||
private void updateUI(string hexValue, string hex, string path)
|
||||
{
|
||||
Color color = (Color)ColorConverter.ConvertFromString(hexValue);
|
||||
SolidColorBrush brush = new SolidColorBrush(color);
|
||||
btn.Background = brush;
|
||||
Uri imageUri = new Uri(AppDomain.CurrentDomain.BaseDirectory + path);
|
||||
BitmapImage bitmapImage = new BitmapImage(imageUri);
|
||||
img.Source = bitmapImage;
|
||||
Color color2 = (Color)ColorConverter.ConvertFromString(hex);
|
||||
SolidColorBrush brush2 = new SolidColorBrush(color2);
|
||||
tbk.Foreground = brush2;
|
||||
tbk.Text = btnName;
|
||||
// 这里加长一点,与其它4个中文的文本长度对齐。
|
||||
if(btnName == "主页")
|
||||
{
|
||||
tbk.Text = "主页" + '\u00A0' + '\u00A0' + '\u00A0' + '\u00A0' + '\u00A0' + '\u00A0' + '\u00A0';
|
||||
}
|
||||
tbk.FontSize = 15;
|
||||
tbk.FontFamily = new FontFamily("Microsoft YaHei");
|
||||
tbk.FontWeight = FontWeights.Bold;
|
||||
}
|
||||
// 更新小按钮界面
|
||||
private void updateUI2(string hexValue, string path)
|
||||
{
|
||||
Color color = (Color)ColorConverter.ConvertFromString(hexValue);
|
||||
SolidColorBrush brush = new SolidColorBrush(color);
|
||||
btn2.Background = brush;
|
||||
Uri imageUri = new Uri(AppDomain.CurrentDomain.BaseDirectory + path);
|
||||
BitmapImage bitmapImage = new BitmapImage(imageUri);
|
||||
img2.Source = bitmapImage;
|
||||
}
|
||||
|
||||
// 取消选中状态
|
||||
public void setFocus(bool check)
|
||||
{
|
||||
flag = check;
|
||||
if (flag)
|
||||
{
|
||||
if (max)
|
||||
updateUI(hex1, hex2, imgPath);
|
||||
else
|
||||
updateUI2(hex1, imgPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (max)
|
||||
updateUI(hex2, hex3, imgPath2);
|
||||
else
|
||||
updateUI2(hex2, imgPath2);
|
||||
}
|
||||
}
|
||||
|
||||
// 设置大小状态
|
||||
public void setCollapsed(bool see)
|
||||
{
|
||||
if (see)
|
||||
{
|
||||
this.Width = 150;
|
||||
btn.Visibility = Visibility.Visible;
|
||||
btn2.Visibility = Visibility.Collapsed;
|
||||
max = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Width = 25;
|
||||
btn.Visibility = Visibility.Collapsed;
|
||||
btn2.Visibility = Visibility.Visible;
|
||||
max = false;
|
||||
}
|
||||
setFocus(flag);
|
||||
}
|
||||
|
||||
private void InitUI()
|
||||
{
|
||||
// 找出控件里面子控件
|
||||
img = btn.Template.FindName("img", btn) as Image;
|
||||
img2 = btn2.Template.FindName("img2", btn2) as Image;
|
||||
tbk = btn.Template.FindName("tbk", btn) as TextBlock;
|
||||
|
||||
//小状态的按钮,先隐藏。 这里注意:如果在代码里面写了隐藏,上面的img2就会找不到。为null
|
||||
//只能先获取对象,后做隐藏处理。
|
||||
btn2.Visibility = Visibility.Collapsed;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
18
middleware/zdhsys/Control/FlowButton.xaml
Normal file
@@ -0,0 +1,18 @@
|
||||
<UserControl x:Class="zdhsys.Control.FlowButton"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:zdhsys.Control"
|
||||
mc:Ignorable="d"
|
||||
MouseDoubleClick="UserControl_MouseDoubleClick"
|
||||
d:DesignHeight="80" d:DesignWidth="120">
|
||||
<Grid>
|
||||
<Grid.RenderTransform>
|
||||
<TranslateTransform x:Name="translateTransform" />
|
||||
</Grid.RenderTransform>
|
||||
<Border x:Name="bd" CornerRadius="5" Margin="3" Background="White" BorderBrush="#0080FF" BorderThickness="2">
|
||||
<Label x:Name="tbk" Grid.Column="2" Content="Button" VerticalAlignment="Center" HorizontalContentAlignment="Center" Margin="0"/>
|
||||
</Border>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
97
middleware/zdhsys/Control/FlowButton.xaml.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace zdhsys.Control
|
||||
{
|
||||
/// <summary>
|
||||
/// DevButton.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class FlowButton : UserControl
|
||||
{
|
||||
public FlowButton()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public event RoutedEventHandler Click;
|
||||
public object obj;
|
||||
public long ID;
|
||||
|
||||
/// <summary>
|
||||
/// 设置按钮样式
|
||||
/// </summary>
|
||||
/// <param name="hexBG">按钮背景色</param>
|
||||
/// <param name="hexBd">按钮边框色</param>
|
||||
/// <param name="hexTxt">按钮文本颜色</param>
|
||||
/// <param name="txt">按钮文本</param>
|
||||
public void SetUI(string hexBG, string hexBd, string hexTxt, string txt)
|
||||
{
|
||||
Color color = (Color)ColorConverter.ConvertFromString(hexBG);
|
||||
SolidColorBrush brush = new SolidColorBrush(color);
|
||||
bd.Background = brush;
|
||||
|
||||
Color color1 = (Color)ColorConverter.ConvertFromString(hexBd);
|
||||
SolidColorBrush brush1 = new SolidColorBrush(color1);
|
||||
bd.BorderBrush = brush1;
|
||||
|
||||
Color color2 = (Color)ColorConverter.ConvertFromString(hexTxt);
|
||||
SolidColorBrush brush2 = new SolidColorBrush(color2);
|
||||
tbk.Foreground = brush2;
|
||||
tbk.Content = txt;
|
||||
}
|
||||
|
||||
|
||||
private void UserControl_MouseDoubleClick(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (Click != null)
|
||||
{
|
||||
Click.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
|
||||
#region 拖动
|
||||
|
||||
//private bool isDragging;
|
||||
//private Point startPoint;
|
||||
//protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
|
||||
//{
|
||||
// base.OnMouseLeftButtonDown(e);
|
||||
|
||||
// isDragging = true;
|
||||
// startPoint = e.GetPosition(this);
|
||||
// bd.CaptureMouse();
|
||||
//}
|
||||
|
||||
//protected override void OnMouseMove(MouseEventArgs e)
|
||||
//{
|
||||
// base.OnMouseMove(e);
|
||||
|
||||
// if (isDragging)
|
||||
// {
|
||||
// Point endPoint = e.GetPosition(this);
|
||||
// double offsetX = endPoint.X - startPoint.X;
|
||||
// double offsetY = endPoint.Y - startPoint.Y;
|
||||
|
||||
// translateTransform.X += offsetX;
|
||||
// translateTransform.Y += offsetY;
|
||||
|
||||
// startPoint = endPoint;
|
||||
// }
|
||||
//}
|
||||
|
||||
//protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
|
||||
//{
|
||||
// base.OnMouseLeftButtonUp(e);
|
||||
|
||||
// isDragging = false;
|
||||
|
||||
// bd.ReleaseMouseCapture();
|
||||
//}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
19
middleware/zdhsys/Control/FlowButton2.xaml
Normal file
@@ -0,0 +1,19 @@
|
||||
<UserControl x:Class="zdhsys.Control.FlowButton2"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:zdhsys.Control"
|
||||
mc:Ignorable="d"
|
||||
Loaded="UserControl_Loaded"
|
||||
MouseRightButtonDown="UserControl_MouseRightButtonDown"
|
||||
d:DesignHeight="80" d:DesignWidth="120">
|
||||
<Grid x:Name="gd">
|
||||
<Grid.RenderTransform>
|
||||
<TranslateTransform x:Name="translateTransform" />
|
||||
</Grid.RenderTransform>
|
||||
<Border x:Name="bd" CornerRadius="6" Margin="6" Background="White" BorderBrush="#0080FF" BorderThickness="2">
|
||||
<Label x:Name="tbk" Grid.Column="2" Content="Button" VerticalAlignment="Center" HorizontalContentAlignment="Center" Margin="0"/>
|
||||
</Border>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
302
middleware/zdhsys/Control/FlowButton2.xaml.cs
Normal file
@@ -0,0 +1,302 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
using zdhsys.Unitils;
|
||||
|
||||
namespace zdhsys.Control
|
||||
{
|
||||
/// <summary>
|
||||
/// DevButton.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class FlowButton2 : UserControl
|
||||
{
|
||||
public FlowButton2()
|
||||
{
|
||||
InitializeComponent();
|
||||
//ID = GlobalUnitils.GetNowTime(DateTime.Now);
|
||||
}
|
||||
|
||||
public event RoutedEventHandler Click;
|
||||
/// <summary>
|
||||
/// 绑定设备实体用
|
||||
/// </summary>
|
||||
public object obj;
|
||||
/// <summary>
|
||||
/// 流程ID。 因为会有设备重复的情况,不适合使用设备的ID做为唯一
|
||||
/// </summary>
|
||||
public long ID;
|
||||
//背景颜色
|
||||
public string tempHexBG = "";
|
||||
//边框颜色
|
||||
public string tempHexBd = "";
|
||||
//字体颜色
|
||||
public string tempHexTxt = "";
|
||||
//文本内容
|
||||
public string tempTxt = "";
|
||||
//操作指令
|
||||
public int CMD = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 设置按钮样式
|
||||
/// </summary>
|
||||
/// <param name="hexBG">按钮背景色</param>
|
||||
/// <param name="hexBd">按钮边框色</param>
|
||||
/// <param name="hexTxt">按钮文本颜色</param>
|
||||
/// <param name="txt">按钮文本</param>
|
||||
public void SetUI(string hexBG, string hexBd, string hexTxt, string txt)
|
||||
{
|
||||
tempHexBG = hexBG;
|
||||
tempHexBd = hexBd;
|
||||
tempHexTxt = hexTxt;
|
||||
tempTxt = txt;
|
||||
Color color = (Color)ColorConverter.ConvertFromString(hexBG);
|
||||
SolidColorBrush brush = new SolidColorBrush(color);
|
||||
bd.Background = brush;
|
||||
Color color1 = (Color)ColorConverter.ConvertFromString(hexBd);
|
||||
SolidColorBrush brush1 = new SolidColorBrush(color1);
|
||||
bd.BorderBrush = brush1;
|
||||
|
||||
Color color2 = (Color)ColorConverter.ConvertFromString(hexTxt);
|
||||
SolidColorBrush brush2 = new SolidColorBrush(color2);
|
||||
tbk.Foreground = brush2;
|
||||
tbk.Content = txt;
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置背景色和边框颜色
|
||||
/// </summary>
|
||||
/// <param name="hexBG"></param>
|
||||
public void SetBackColor(string hexBG)
|
||||
{
|
||||
tempHexBG = hexBG;
|
||||
tempHexBd = hexBG;
|
||||
Color color = (Color)ColorConverter.ConvertFromString(hexBG);
|
||||
SolidColorBrush brush = new SolidColorBrush(color);
|
||||
bd.Background = brush;
|
||||
|
||||
Color color1 = (Color)ColorConverter.ConvertFromString(hexBG);
|
||||
SolidColorBrush brush1 = new SolidColorBrush(color1);
|
||||
bd.BorderBrush = brush1;
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置字体颜色
|
||||
/// </summary>
|
||||
/// <param name="hexTxt"></param>
|
||||
public void SetForeColor(string hexTxt)
|
||||
{
|
||||
Color color2 = (Color)ColorConverter.ConvertFromString(hexTxt);
|
||||
SolidColorBrush brush2 = new SolidColorBrush(color2);
|
||||
tbk.Foreground = brush2;
|
||||
tempHexTxt = hexTxt;
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置显示文本内容
|
||||
/// </summary>
|
||||
/// <param name="txt"></param>
|
||||
public void SetText(string txt)
|
||||
{
|
||||
tbk.Content = txt;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回控件的内部坐标
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Point getPoint()
|
||||
{
|
||||
Point p = new Point(0, 0)
|
||||
{
|
||||
X = startPoint.X - translateTransform.X,
|
||||
Y = startPoint.Y - translateTransform.Y
|
||||
};
|
||||
return p;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取当前单击位置是否有画线的情况
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string getEllipse()
|
||||
{
|
||||
Point p = getPoint();
|
||||
for (int i = 0; i < ps.Count; i++)
|
||||
{
|
||||
if (ps[i].Data.FillContains(p))
|
||||
{
|
||||
//Console.WriteLine($" ellipse name={ps[i].Name}");
|
||||
return ps[i].Name;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
/// <summary>
|
||||
/// 返回当前控件的相对坐标
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Point getTranslateTransform()
|
||||
{
|
||||
return new Point(translateTransform.X, translateTransform.Y);
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置当前控件的相对坐标
|
||||
/// </summary>
|
||||
/// <param name="p"></param>
|
||||
public void SetTranslateTransform(Point p)
|
||||
{
|
||||
translateTransform.X += p.X;
|
||||
translateTransform.Y += p.Y;
|
||||
}
|
||||
|
||||
#region 拖动
|
||||
//是否拖拽
|
||||
private bool isDragging;
|
||||
/// <summary>
|
||||
/// 当前单击坐标
|
||||
/// </summary>
|
||||
public Point startPoint;
|
||||
/// <summary>
|
||||
/// 单击圆的位置名称
|
||||
/// </summary>
|
||||
public string clickName;
|
||||
/// <summary>
|
||||
/// 鼠标按下
|
||||
/// </summary>
|
||||
/// <param name="e"></param>
|
||||
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
|
||||
{
|
||||
base.OnMouseLeftButtonDown(e);
|
||||
startPoint = e.GetPosition(this);
|
||||
bool flag = false;
|
||||
Point p = new Point(0, 0)
|
||||
{
|
||||
X = startPoint.X - translateTransform.X,
|
||||
Y = startPoint.Y - translateTransform.Y
|
||||
};
|
||||
//过滤掉4个圆。点击这4个圆,不移动当前控件。
|
||||
for (int i = 0; i < ps.Count; i++)
|
||||
{
|
||||
if (ps[i].Data.FillContains(p))
|
||||
{
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
isDragging = true;
|
||||
_ = bd.CaptureMouse();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 鼠标移动
|
||||
/// </summary>
|
||||
/// <param name="e"></param>
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
|
||||
if (isDragging)
|
||||
{
|
||||
Point endPoint = e.GetPosition(this);
|
||||
double offsetX = endPoint.X - startPoint.X;
|
||||
double offsetY = endPoint.Y - startPoint.Y;
|
||||
|
||||
translateTransform.X += offsetX;
|
||||
translateTransform.Y += offsetY;
|
||||
|
||||
startPoint = endPoint;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 鼠标松开
|
||||
/// </summary>
|
||||
/// <param name="e"></param>
|
||||
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
|
||||
{
|
||||
base.OnMouseLeftButtonUp(e);
|
||||
isDragging = false;
|
||||
startPoint = e.GetPosition(this);
|
||||
bd.ReleaseMouseCapture();
|
||||
}
|
||||
|
||||
#endregion
|
||||
/// <summary>
|
||||
/// 保存4个圆的路径。用于判断是否点击了这些圆,哪个圆
|
||||
/// </summary>
|
||||
private static List<Path> ps = new List<Path>();
|
||||
|
||||
private void UserControl_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ps.Add(AddEllipse("left", new Point(7, 40)));
|
||||
ps.Add(AddEllipse("top", new Point(60, 7)));
|
||||
ps.Add(AddEllipse("right", new Point(113, 40)));
|
||||
ps.Add(AddEllipse("bottom", new Point(60, 73)));
|
||||
}
|
||||
/// <summary>
|
||||
/// 返回左上右下的圆心坐标。可用于主界面画线的时候用到
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public Point getStartPointByName(string name)
|
||||
{
|
||||
if (name == "left")
|
||||
{
|
||||
return new Point(7, 40);
|
||||
}
|
||||
else if (name == "top")
|
||||
{
|
||||
return new Point(60, 7);
|
||||
}
|
||||
else if (name == "right")
|
||||
{
|
||||
return new Point(113, 40);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Point(60, 73);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 添加圆型路径
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="p"></param>
|
||||
/// <returns></returns>
|
||||
private Path AddEllipse(string name, Point p)
|
||||
{
|
||||
// 创建圆形路径
|
||||
Path path = new Path
|
||||
{
|
||||
Stroke = new SolidColorBrush(Color.FromArgb(255, 2, 122, 255)),
|
||||
StrokeThickness = 2,
|
||||
Fill = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255))
|
||||
};
|
||||
EllipseGeometry ellipse = new EllipseGeometry
|
||||
{
|
||||
Center = p, // 设置圆心坐标
|
||||
RadiusX = 6, // 半径
|
||||
RadiusY = 6
|
||||
};
|
||||
path.Data = ellipse;
|
||||
path.Name = name;
|
||||
// 添加路径到 Grid
|
||||
_ = gd.Children.Add(path);
|
||||
return path;
|
||||
}
|
||||
/// <summary>
|
||||
/// 右键编辑
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void UserControl_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (Click != null)
|
||||
{
|
||||
Click.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
14
middleware/zdhsys/Control/ImageButton.xaml
Normal file
@@ -0,0 +1,14 @@
|
||||
<UserControl x:Class="zdhsys.Control.ImageButton"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:zdhsys.Control"
|
||||
mc:Ignorable="d"
|
||||
Background="White"
|
||||
MouseLeftButtonDown="UserControl_MouseLeftButtonDown"
|
||||
d:DesignHeight="40" d:DesignWidth="40">
|
||||
<Grid>
|
||||
<Image x:Name="img" Width="15" Height="15"/>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
47
middleware/zdhsys/Control/ImageButton.xaml.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace zdhsys.Control
|
||||
{
|
||||
/// <summary>
|
||||
/// ImageButton.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class ImageButton : UserControl
|
||||
{
|
||||
public ImageButton()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
public event RoutedEventHandler Click;
|
||||
private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (Click != null)
|
||||
{
|
||||
Click.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetUI(string path)
|
||||
{
|
||||
Uri imageUri = new Uri(AppDomain.CurrentDomain.BaseDirectory + path);
|
||||
BitmapImage bitmapImage = new BitmapImage(imageUri);
|
||||
if (img != null)
|
||||
{
|
||||
img.Source = bitmapImage;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
16
middleware/zdhsys/Control/MyControl.xaml
Normal file
@@ -0,0 +1,16 @@
|
||||
<UserControl x:Class="zdhsys.Control.MyControl"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:zdhsys.Control"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="300" d:DesignWidth="300">
|
||||
<Grid>
|
||||
<Grid.RenderTransform>
|
||||
<TranslateTransform x:Name="translateTransform" />
|
||||
</Grid.RenderTransform>
|
||||
<Label x:Name="myLabel" Content="Sample Text"
|
||||
Background="LightBlue" HorizontalAlignment="Center" VerticalAlignment="Center" />
|
||||
</Grid>
|
||||
</UserControl>
|
||||
84
middleware/zdhsys/Control/MyControl.xaml.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace zdhsys.Control
|
||||
{
|
||||
/// <summary>
|
||||
/// MyControl.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class MyControl : UserControl
|
||||
{
|
||||
public MyControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private bool isDragging;
|
||||
private Point startPoint;
|
||||
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
|
||||
{
|
||||
base.OnMouseLeftButtonDown(e);
|
||||
|
||||
isDragging = true;
|
||||
startPoint = e.GetPosition(this);
|
||||
|
||||
myLabel.CaptureMouse();
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
|
||||
if (isDragging)
|
||||
{
|
||||
//Point endPoint = e.GetPosition(this);
|
||||
Point endPoint = e.GetPosition((UIElement)Parent);
|
||||
//if (endPoint.X < 15 || endPoint.Y < 1) return;
|
||||
double offsetX = endPoint.X - startPoint.X;
|
||||
double offsetY = endPoint.Y - startPoint.Y;
|
||||
|
||||
double left = Canvas.GetLeft(this) + translateTransform.X;
|
||||
double top = Canvas.GetTop(this) + translateTransform.Y;
|
||||
double width = ActualWidth;
|
||||
double height = ActualHeight;
|
||||
|
||||
Console.WriteLine($"坐标: ({left}, {top}), 大小: {width} x {height}");
|
||||
if (left < 0)
|
||||
{
|
||||
translateTransform.X += Math.Abs(left);
|
||||
return;
|
||||
}
|
||||
if (top < -10)
|
||||
{
|
||||
translateTransform.Y += Math.Abs(top) - 10;
|
||||
return;
|
||||
}
|
||||
translateTransform.X += offsetX;
|
||||
translateTransform.Y += offsetY;
|
||||
Console.WriteLine("endPoint=" + endPoint.X + "," + endPoint.Y);
|
||||
startPoint = endPoint;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
|
||||
{
|
||||
base.OnMouseLeftButtonUp(e);
|
||||
|
||||
isDragging = false;
|
||||
|
||||
myLabel.ReleaseMouseCapture();
|
||||
}
|
||||
}
|
||||
}
|
||||
18
middleware/zdhsys/Control/OptionTab.xaml
Normal file
@@ -0,0 +1,18 @@
|
||||
<UserControl x:Class="zdhsys.Control.OptionTab"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:zdhsys.Control"
|
||||
mc:Ignorable="d"
|
||||
Loaded="UserControl_Loaded"
|
||||
d:DesignHeight="30" d:DesignWidth="200">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="80*"/>
|
||||
<ColumnDefinition Width="80*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<local:TabButton x:Name="btn_Option" Grid.Column="0"/>
|
||||
<local:TabButton x:Name="btn_SubOption" Grid.Column="1"/>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
69
middleware/zdhsys/Control/OptionTab.xaml.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace zdhsys.Control
|
||||
{
|
||||
/// <summary>
|
||||
/// OptionTab.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class OptionTab : UserControl
|
||||
{
|
||||
public OptionTab()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public event RoutedEventHandler Click_Option;
|
||||
public event RoutedEventHandler Click_SubOption;
|
||||
|
||||
public string str_1 = "小瓶";
|
||||
public string str_2 = "大瓶";
|
||||
|
||||
private void UserControl_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
btn_Option.SetUI(str_1);
|
||||
btn_Option.Click += Btn_Click;
|
||||
btn_Option.SetCheck(true);
|
||||
|
||||
|
||||
btn_SubOption.SetUI(str_2);
|
||||
btn_SubOption.Click += Btn_Click;
|
||||
btn_SubOption.SetCheck(false);
|
||||
}
|
||||
|
||||
private void Btn_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
TabButton tab = sender as TabButton;
|
||||
if (tab.Text == str_1)
|
||||
{
|
||||
btn_Option.SetCheck(true);
|
||||
btn_SubOption.SetCheck(false);
|
||||
if (Click_Option != null)
|
||||
{
|
||||
Click_Option.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
else if (tab.Text == str_2)
|
||||
{
|
||||
btn_Option.SetCheck(false);
|
||||
btn_SubOption.SetCheck(true);
|
||||
if (Click_SubOption != null)
|
||||
{
|
||||
Click_SubOption.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
24
middleware/zdhsys/Control/SwitchButton.xaml
Normal file
@@ -0,0 +1,24 @@
|
||||
<UserControl x:Class="zdhsys.Control.SwitchButton"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:zdhsys.Control"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="30" d:DesignWidth="200">
|
||||
<Grid>
|
||||
<Border BorderThickness="1" BorderBrush="#027AFF" CornerRadius="15"/>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Border x:Name="bd_resp" BorderThickness="1" CornerRadius="15" Background="#027AFF">
|
||||
<Button x:Name="btn_resp" Height="28" Width="100" Click="btn_resp_Click" Content="反应类设备" Style="{StaticResource NoBorderButtonStyle0}" Foreground="White"/>
|
||||
</Border>
|
||||
<Border x:Name="bd_move" Grid.Column="1" BorderThickness="1" CornerRadius="15">
|
||||
<Button x:Name="btn_move" Height="28" Width="100" Click="btn_move_Click" Content="转移类设备" Style="{StaticResource NoBorderButtonStyle0}" Foreground="#027AFF"/>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
61
middleware/zdhsys/Control/SwitchButton.xaml.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace zdhsys.Control
|
||||
{
|
||||
/// <summary>
|
||||
/// SwitchButton.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class SwitchButton : UserControl
|
||||
{
|
||||
public SwitchButton()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public bool flagLeft = true;
|
||||
public event RoutedEventHandler Click;
|
||||
|
||||
private void btn_resp_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
btn_resp.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFFFF"));
|
||||
bd_resp.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#027AFF"));
|
||||
|
||||
btn_move.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#027AFF"));
|
||||
bd_move.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFFFF"));
|
||||
|
||||
flagLeft = true;
|
||||
if (Click != null)
|
||||
{
|
||||
Click.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
|
||||
private void btn_move_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
btn_move.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFFFF"));
|
||||
bd_move.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#027AFF"));
|
||||
|
||||
btn_resp.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#027AFF"));
|
||||
bd_resp.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFFFF"));
|
||||
|
||||
flagLeft = false;
|
||||
if (Click != null)
|
||||
{
|
||||
Click.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
17
middleware/zdhsys/Control/TabButton.xaml
Normal file
@@ -0,0 +1,17 @@
|
||||
<UserControl x:Class="zdhsys.Control.TabButton"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:zdhsys.Control"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="35" d:DesignWidth="80">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="6*"/>
|
||||
<RowDefinition Height="1*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Button x:Name="btn" Click="btn_Click" Content="设备管理" Width="80" Style="{StaticResource NoBorderButtonStyle1}"/>
|
||||
<Border Name="bd" Grid.Row="1" Width="30" Height="3" BorderThickness="2" BorderBrush="#027AFF" Background="#027AFF" VerticalAlignment="Top"/>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
67
middleware/zdhsys/Control/TabButton.xaml.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace zdhsys.Control
|
||||
{
|
||||
/// <summary>
|
||||
/// TabButton.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class TabButton : UserControl
|
||||
{
|
||||
public TabButton()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public event RoutedEventHandler Click;
|
||||
|
||||
public string Text;
|
||||
public void SetUI(string content)
|
||||
{
|
||||
btn.Content = content;
|
||||
Text = content;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设备选中状态
|
||||
/// </summary>
|
||||
/// <param name="flag"></param>
|
||||
public void SetCheck(bool flag)
|
||||
{
|
||||
if (flag)
|
||||
{
|
||||
Color color = (Color)ColorConverter.ConvertFromString("#333333");
|
||||
SolidColorBrush brush = new SolidColorBrush(color);
|
||||
btn.Foreground = brush;
|
||||
bd.Visibility = Visibility.Visible;
|
||||
}
|
||||
else
|
||||
{
|
||||
Color color = (Color)ColorConverter.ConvertFromString("#999999");
|
||||
SolidColorBrush brush = new SolidColorBrush(color);
|
||||
btn.Foreground = brush;
|
||||
bd.Visibility = Visibility.Hidden;
|
||||
}
|
||||
}
|
||||
|
||||
private void btn_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (Click != null)
|
||||
{
|
||||
Click.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
555
middleware/zdhsys/Device/Dev_BG.cs
Normal file
@@ -0,0 +1,555 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO.MemoryMappedFiles;
|
||||
using System.IO;
|
||||
using System.IO.Ports;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using System.Windows.Forms;
|
||||
using EasyModbus;
|
||||
using System.IO.Pipes;
|
||||
using System.Net.Sockets;
|
||||
using Newtonsoft.Json;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
|
||||
namespace zdhsys
|
||||
{
|
||||
internal partial class Dev_BG
|
||||
{
|
||||
|
||||
public Dev_BG()
|
||||
{
|
||||
sub_dev_Vave = new bg_in_out_water();
|
||||
}
|
||||
|
||||
public bg_in_out_water sub_dev_Vave;
|
||||
|
||||
public string chaoshengspd = "set_mixer_speed 15 ";//设置搅拌转速;
|
||||
public string chaoshengpower = "set_mixer_pow 15 ";//设置超声功率;
|
||||
|
||||
public string mixstart = "mixer_start 15\r\n";
|
||||
public string mixend = "mixer_stop 15\r\n";
|
||||
|
||||
public string tempset = "set_pid_temp 1 ";//设置温度
|
||||
public string tempstart = "pid_enable 1 1";//开始温控
|
||||
public string tempstop = "pid_enable 1 0";//开始温控
|
||||
|
||||
public string ComPortName = "COM3";
|
||||
SerialPort serialPort_Dev_BG;
|
||||
|
||||
public bool openPort()
|
||||
{
|
||||
serialPort_Dev_BG = new SerialPort(ComPortName, 115200, Parity.None, 8, StopBits.One);
|
||||
try
|
||||
{
|
||||
serialPort_Dev_BG.Open();
|
||||
// throw new Exception();
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MessageBox.Show(e.Message.ToString());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Thread lisn_th;
|
||||
public void start_lsn()
|
||||
{
|
||||
lisn_th = new Thread(lispro);
|
||||
lisn_th.Start();
|
||||
}
|
||||
|
||||
public string rcvdata;
|
||||
bool checking = false;
|
||||
private void lispro()
|
||||
{
|
||||
//byte[] receiveData = new byte[serialPort1.BytesToRead];//接收到的数据 serialPort1.Read(receiveData, 0, receiveData.Length);//读取数据
|
||||
while (serialPort_Dev_BG.IsOpen)
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
if (checking)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (serialPort_Dev_BG.BytesToRead > 0)
|
||||
{
|
||||
rcvdata = serialPort_Dev_BG.ReadLine();
|
||||
Console.Write(rcvdata); // 输出到控制台
|
||||
//textBox1.Text = data;
|
||||
// textBox1.Lines = data.Split('\n');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class bg_dev_status_cfg
|
||||
{
|
||||
public int TotalSTA;//0 before initial; 1 initialed and idle; 2 working; 3 finish; 4 error
|
||||
public int [] pumpsta;//1号泵 对应1-4路
|
||||
public int [] pumpsta_curspd;
|
||||
// public int pump2sta;//2号泵 对应5-8路,
|
||||
// public int pump3sta;//3号泵 对应9-12路
|
||||
|
||||
public int [] pumpVavsta;//1号泵阀门,进1 出0
|
||||
// public int pump2Vavsta;//2号泵阀门,进1 出0
|
||||
// public int pump3Vavsta;//3号泵阀门,进1 出0
|
||||
|
||||
public int motorUDsta;//电机上下状态,上0, 下1
|
||||
public int motorFBsta;//电机前后状态,后0,前1
|
||||
|
||||
public int[] sonarSta;//12路超声状态
|
||||
public int[] sonarPowSet;//12路超声功率设置
|
||||
public int[] sonarSpeedSet;//12路超声速度设置
|
||||
|
||||
public int[] heatSta;//12路加热状态
|
||||
public int[] heatTempSet;//12路加热温度设置
|
||||
|
||||
public int[] waterLevLow;//清洗低位
|
||||
public int[] waterLevHigh;//清洗高位
|
||||
|
||||
public int pumpSpd; //齿轮泵速度
|
||||
public int pumpSpdHigh;//齿轮泵高速
|
||||
public int pumpSpdLow;//齿轮泵低速度
|
||||
|
||||
public int greepPumpSpd;//蠕动泵速度
|
||||
|
||||
public bg_dev_status_cfg()
|
||||
{
|
||||
pumpsta = new int[3];
|
||||
pumpsta_curspd = new int[3];
|
||||
pumpVavsta = new int[3];
|
||||
|
||||
sonarSta = new int[12];
|
||||
sonarPowSet = new int[12];
|
||||
heatSta = new int[12];
|
||||
heatTempSet = new int[12];
|
||||
waterLevLow = new int[12];
|
||||
waterLevHigh = new int[12];
|
||||
sonarSpeedSet = new int[12];
|
||||
|
||||
pumpSpd = 500;//默认500
|
||||
|
||||
for(int i=0;i<3;i++)
|
||||
{
|
||||
pumpsta[i] = 0;
|
||||
pumpsta_curspd[i] = 0;
|
||||
pumpVavsta[i]= 0;
|
||||
}
|
||||
|
||||
for(int i=0;i<12;i++)
|
||||
{
|
||||
sonarSta[i] = 0;
|
||||
sonarPowSet[i]= 20;
|
||||
sonarSpeedSet[i] = 100;
|
||||
heatSta[i] = 0;
|
||||
heatTempSet[i] = 60;
|
||||
waterLevHigh[i] = 55;
|
||||
}
|
||||
}
|
||||
|
||||
public void loadfromcfg()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public bg_dev_status_cfg m_Status_cfg = new bg_dev_status_cfg();//当前设备状态与参数
|
||||
|
||||
public void motorliftup()
|
||||
{
|
||||
string cmd1 = "motor_dir_set 1 0\r\n";
|
||||
byte[] array1 = System.Text.Encoding.ASCII.GetBytes(cmd1);
|
||||
serialPort_Dev_BG.Write(array1, 0, array1.Length);
|
||||
Thread.Sleep(500);
|
||||
|
||||
string cmd2 = "motor1_2_run\r\n";
|
||||
byte[] array2 = System.Text.Encoding.ASCII.GetBytes(cmd2);
|
||||
serialPort_Dev_BG.Write(array2, 0, array2.Length);
|
||||
|
||||
m_Status_cfg.motorUDsta = 0;
|
||||
}
|
||||
|
||||
public void motorliftDowm()
|
||||
{
|
||||
string cmd1 = "motor_dir_set 1 1\r\n";
|
||||
byte[] array1 = System.Text.Encoding.ASCII.GetBytes(cmd1);
|
||||
serialPort_Dev_BG.Write(array1, 0, array1.Length);
|
||||
Thread.Sleep(500);
|
||||
|
||||
string cmd2 = "motor1_2_run\r\n";
|
||||
byte[] array2 = System.Text.Encoding.ASCII.GetBytes(cmd2);
|
||||
serialPort_Dev_BG.Write(array2, 0, array2.Length);
|
||||
|
||||
m_Status_cfg.motorUDsta = 1;
|
||||
}
|
||||
|
||||
public void motorfront()
|
||||
{
|
||||
string cmd1 = "motor_dir_set 2 1\r\n";
|
||||
byte[] array1 = System.Text.Encoding.ASCII.GetBytes(cmd1);
|
||||
serialPort_Dev_BG.Write(array1, 0, array1.Length);
|
||||
Thread.Sleep(1000);
|
||||
|
||||
string cmd2 = "motor3_4_run\r\n";
|
||||
byte[] array2 = System.Text.Encoding.ASCII.GetBytes(cmd2);
|
||||
serialPort_Dev_BG.Write(array2, 0, array2.Length);
|
||||
|
||||
m_Status_cfg.motorFBsta = 1;
|
||||
}
|
||||
public void motorback()
|
||||
{
|
||||
string cmd1 = "motor_dir_set 2 0\r\n";
|
||||
byte[] array1 = System.Text.Encoding.ASCII.GetBytes(cmd1);
|
||||
serialPort_Dev_BG.Write(array1, 0, array1.Length);
|
||||
Thread.Sleep(1000);
|
||||
|
||||
string cmd2 = "motor3_4_run\r\n";
|
||||
byte[] array2 = System.Text.Encoding.ASCII.GetBytes(cmd2);
|
||||
serialPort_Dev_BG.Write(array2, 0, array2.Length);
|
||||
|
||||
m_Status_cfg.motorFBsta = 0;
|
||||
}
|
||||
|
||||
//node : 1, 2
|
||||
//chn: 1-6,7
|
||||
//temp = 60
|
||||
public void set_temp(int node,int chn, int val)
|
||||
{
|
||||
string cmd = "set_pid_temp "+node.ToString()+" "+chn.ToString()+" "+val.ToString()+ "\r\n";
|
||||
// string cmd = tempset + " " + val.ToString() + "\r\n";
|
||||
byte[] array = System.Text.Encoding.ASCII.GetBytes(cmd);
|
||||
serialPort_Dev_BG.Write(array, 0, array.Length);
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
|
||||
//node : 1, 2
|
||||
//chn: 1-6,7
|
||||
//action = 1
|
||||
public void start_temp(int node, int chn)
|
||||
{
|
||||
string cmd ="pid_enable " + node.ToString()+ " " +chn.ToString()+ " 1\r\n";
|
||||
// string cmd = tempstart + " " + "\r\n";
|
||||
byte[] array = System.Text.Encoding.ASCII.GetBytes(cmd);
|
||||
serialPort_Dev_BG.Write(array, 0, array.Length);
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
//node : 1, 2
|
||||
//chn: 1-6
|
||||
//action = 0
|
||||
public void stop_temp(int node, int chn)
|
||||
{
|
||||
string cmd = "pid_enable " + node.ToString() + " " + chn.ToString() + " 0\r\n";
|
||||
byte[] array = System.Text.Encoding.ASCII.GetBytes(cmd);
|
||||
serialPort_Dev_BG.Write(array, 0, array.Length);
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
|
||||
//超声控制
|
||||
//测试代码,全开,15为全部发送
|
||||
public void set_sonar_rotationspd(int spd)
|
||||
{
|
||||
string cmd = chaoshengspd + " " + spd.ToString() + "\r\n";
|
||||
byte[] array = System.Text.Encoding.ASCII.GetBytes(cmd);
|
||||
serialPort_Dev_BG.Write(array, 0, array.Length);
|
||||
}
|
||||
|
||||
public void set_sonar_mixpower(int pow)
|
||||
{
|
||||
string cmd = chaoshengpower + " " + pow.ToString() + "\r\n";
|
||||
byte[] array = System.Text.Encoding.ASCII.GetBytes(cmd);
|
||||
serialPort_Dev_BG.Write(array, 0, array.Length);
|
||||
}
|
||||
|
||||
public void start_sonar()
|
||||
{
|
||||
string cmd0 = "set_mixer_pow 15 20\r\n";
|
||||
byte[] array0 = System.Text.Encoding.ASCII.GetBytes(cmd0);
|
||||
serialPort_Dev_BG.Write(array0, 0, array0.Length);
|
||||
Thread.Sleep(500);
|
||||
string cmd = mixstart + " 15 " + "\r\n";
|
||||
byte[] array = System.Text.Encoding.ASCII.GetBytes(cmd);
|
||||
serialPort_Dev_BG.Write(array, 0, array.Length);
|
||||
}
|
||||
|
||||
public void stop_sonar()
|
||||
{
|
||||
string cmd = mixend + " 15 " + "\r\n";
|
||||
byte[] array = System.Text.Encoding.ASCII.GetBytes(cmd);
|
||||
serialPort_Dev_BG.Write(array, 0, array.Length);
|
||||
}
|
||||
|
||||
//测试代码 独立开
|
||||
//说明:独立ID和实际ID关系待查
|
||||
//
|
||||
public void set_sonar_rotationspd(int ID, int spd)
|
||||
{
|
||||
string cmd = "set_mixer_speed "+ ID.ToString() + " " + spd.ToString() + "\r\n";
|
||||
byte[] array = System.Text.Encoding.ASCII.GetBytes(cmd);
|
||||
serialPort_Dev_BG.Write(array, 0, array.Length);
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
|
||||
public void set_sonar_mixpower(int ID, int pow)
|
||||
{
|
||||
string cmd = "set_mixer_pow " + ID.ToString() + " " + pow.ToString() + "\r\n";
|
||||
byte[] array = System.Text.Encoding.ASCII.GetBytes(cmd);
|
||||
serialPort_Dev_BG.Write(array, 0, array.Length);
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
|
||||
public void start_sonar(int ID)
|
||||
{
|
||||
string cmd = mixstart + " "+ID.ToString() + "\r\n";
|
||||
byte[] array = System.Text.Encoding.ASCII.GetBytes(cmd);
|
||||
serialPort_Dev_BG.Write(array, 0, array.Length);
|
||||
}
|
||||
public void stop_sonar(int ID)
|
||||
{
|
||||
string cmd = mixend + " "+ID.ToString() + "\r\n";
|
||||
byte[] array = System.Text.Encoding.ASCII.GetBytes(cmd);
|
||||
serialPort_Dev_BG.Write(array, 0, array.Length);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//超声控制
|
||||
|
||||
|
||||
|
||||
public void runpump(int chn, int action, int speed)//启动停止泵,注意!泵2和3是反的,这里加了修正by jgl20240124
|
||||
{
|
||||
int realchn;
|
||||
if (chn == 2) { realchn = 3; } //2号和3号是反的
|
||||
else if (chn == 3) { realchn = 2; }//2号和3号是反的
|
||||
else if (chn == 1) { realchn = 1; }//1号是对的
|
||||
else { return; }//通道错误,不发数据
|
||||
string cmd = "run_gear_pump "+ realchn.ToString()+" " + action.ToString() + " " + speed.ToString() + " \r\n";
|
||||
byte[] array = System.Text.Encoding.ASCII.GetBytes(cmd);
|
||||
serialPort_Dev_BG.Write(array, 0, array.Length);
|
||||
|
||||
//状态记录采用原来的
|
||||
m_Status_cfg.pumpsta_curspd[chn - 1] = speed;
|
||||
m_Status_cfg.pumpsta[chn - 1] = action;
|
||||
}
|
||||
|
||||
public void start_pump_out(int chn, int spd)//设置阀门为出水
|
||||
{
|
||||
string cmd = "run_valve_test "+chn.ToString()+" 0\r\n";
|
||||
byte[] array = System.Text.Encoding.ASCII.GetBytes(cmd);
|
||||
serialPort_Dev_BG.Write(array, 0, array.Length);
|
||||
// runpump(1,2000);
|
||||
m_Status_cfg.pumpVavsta[chn - 1] = 0;
|
||||
Thread.Sleep(1000);
|
||||
|
||||
}
|
||||
public void start_pump_in(int chn,int spd)//设置阀门为进水
|
||||
{
|
||||
string cmd = "run_valve_test " + chn.ToString() + " 1\r\n";
|
||||
byte[] array = System.Text.Encoding.ASCII.GetBytes(cmd);
|
||||
serialPort_Dev_BG.Write(array, 0, array.Length);
|
||||
m_Status_cfg.pumpVavsta[chn - 1] = 1;
|
||||
Thread.Sleep(1000);
|
||||
|
||||
}
|
||||
|
||||
public void start_pump(int chn,int spd)//启动泵,注意!泵2和3是反的,这里加了修正by jgl20240124
|
||||
{
|
||||
/* int realchn;
|
||||
if(chn ==2){ realchn = 3; } //2号和3号是反的
|
||||
else if(chn==3){ realchn = 2; }//2号和3号是反的
|
||||
else if(chn==1){ realchn = 1; }//1号是对的
|
||||
else { return; }//通道错误,不发数据
|
||||
Thread.Sleep(1000);
|
||||
string cmd1 = "run_gear_pump " + realchn.ToString() + " 1 " + spd.ToString() + "\r\n";
|
||||
byte[] array1 = System.Text.Encoding.ASCII.GetBytes(cmd1);
|
||||
serialPort_Dev_BG.Write(array1, 0, array1.Length);*/
|
||||
runpump(chn,1, spd);
|
||||
}
|
||||
|
||||
public ushort get_sta()
|
||||
{
|
||||
checking = true;
|
||||
Thread.Sleep(500);
|
||||
string cmd1 = "switchScan \r\n";
|
||||
byte[] array1 = System.Text.Encoding.ASCII.GetBytes(cmd1);
|
||||
serialPort_Dev_BG.Write(array1, 0, array1.Length);
|
||||
string data;
|
||||
ushort podsta = 0;
|
||||
|
||||
int cnt = 0;
|
||||
int rcv = 0;
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (serialPort_Dev_BG.BytesToRead > 0)
|
||||
{
|
||||
|
||||
data = serialPort_Dev_BG.ReadLine();
|
||||
|
||||
bool result = ushort.TryParse(data, out podsta); //i now = 108
|
||||
rcv++;
|
||||
/// if(rcv == 2)
|
||||
//{
|
||||
if(result)
|
||||
{
|
||||
podsta = ushort.Parse(data);
|
||||
break;
|
||||
}
|
||||
|
||||
// Console.Write(rcvdata); // 输出到控制台
|
||||
}
|
||||
cnt++;
|
||||
if(cnt >30) {
|
||||
break;
|
||||
}
|
||||
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
|
||||
Thread.Sleep(500);
|
||||
checking = false;
|
||||
return podsta;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void stopPump(int chn)
|
||||
{
|
||||
runpump(chn,0, 0);
|
||||
}
|
||||
|
||||
public int cycles = 1;
|
||||
public int status = 0;
|
||||
Thread run_th;
|
||||
public bool isrunning;
|
||||
|
||||
public void start_run()
|
||||
{
|
||||
isrunning = true;
|
||||
run_th = new Thread(runProcess);
|
||||
run_th.Start();
|
||||
// run_th.Join();
|
||||
}
|
||||
|
||||
public void stop_run()
|
||||
{
|
||||
if (run_th.IsAlive)
|
||||
{
|
||||
run_th.Abort();
|
||||
}
|
||||
Thread.Sleep(1000);
|
||||
StopALL_VAV();
|
||||
Thread.Sleep(1000);
|
||||
stop_sonar();
|
||||
status = 4;
|
||||
Thread.Sleep(1000);
|
||||
motorliftup();//X到位
|
||||
status = 6;
|
||||
Thread.Sleep(1000);
|
||||
motorback();
|
||||
Thread.Sleep(5 * 1000);
|
||||
status = 0;
|
||||
m_Status_cfg.TotalSTA = 1;
|
||||
|
||||
}
|
||||
|
||||
public void initialdev()
|
||||
{
|
||||
m_Status_cfg.TotalSTA = 2;
|
||||
StopALL_VAV();
|
||||
Thread.Sleep(1000);
|
||||
stop_sonar();
|
||||
// status = 4;
|
||||
Thread.Sleep(1000);
|
||||
motorliftup();//X到位
|
||||
// status = 6;
|
||||
Thread.Sleep(1000);
|
||||
motorback();
|
||||
Thread.Sleep(10 * 1000);
|
||||
// status = 0;
|
||||
m_Status_cfg.TotalSTA = 1;
|
||||
}
|
||||
|
||||
|
||||
public void runProcess()
|
||||
{
|
||||
status = 1;
|
||||
motorliftDowm();//到位
|
||||
Thread.Sleep(25 * 1000);
|
||||
status = 2;
|
||||
for (int i = 0; i < cycles; i++)
|
||||
{
|
||||
//搅拌
|
||||
start_sonar();
|
||||
status = 3;
|
||||
Thread.Sleep(10 * 1000);
|
||||
//吸附
|
||||
stop_sonar();
|
||||
status = 4;
|
||||
motorfront();
|
||||
Thread.Sleep(45 * 1000);
|
||||
runOutWaterAuto_duli(1,500,30);
|
||||
Thread.Sleep(5 * 1000);
|
||||
runInWaterAuto_duli(1,500,50);
|
||||
motorback();
|
||||
Thread.Sleep(15 * 1000);
|
||||
start_sonar();
|
||||
Thread.Sleep(10 * 1000);
|
||||
stop_sonar();
|
||||
// moveY_dir(true);//Y下降
|
||||
// Thread.Sleep(10 * 1000);
|
||||
// Thread.Sleep(10 * 1000);
|
||||
//进出水
|
||||
// start_pump_in();
|
||||
// Thread.Sleep(10 * 1000);
|
||||
// start_pump_out();//进水
|
||||
// Thread.Sleep(10 * 1000);
|
||||
// stopPump();
|
||||
// moveY_dir(false);//Y下降
|
||||
}
|
||||
Thread.Sleep(2 * 1000);
|
||||
motorliftup();//X到位
|
||||
status = 6;
|
||||
Thread.Sleep(30 * 1000);
|
||||
status = 0;
|
||||
isrunning = false;
|
||||
|
||||
m_Status_cfg.TotalSTA = 3;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void online_ctl_initial()
|
||||
{
|
||||
// stop_run();
|
||||
Thread th;
|
||||
th = new Thread(initialdev);
|
||||
th.Start();
|
||||
}
|
||||
|
||||
public void online_ctl_run()
|
||||
{
|
||||
if (m_Status_cfg.TotalSTA != 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
m_Status_cfg.TotalSTA = 2;
|
||||
// stop_run();
|
||||
start_run();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
869
middleware/zdhsys/Device/Dev_BG_sub.cs
Normal file
@@ -0,0 +1,869 @@
|
||||
using EasyModbus;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace zdhsys
|
||||
{
|
||||
internal partial class Dev_BG
|
||||
{
|
||||
private Process pythonprocess;
|
||||
|
||||
public void stopPythonDet()
|
||||
{
|
||||
// 当您想要终止 Python 脚本时
|
||||
if (!pythonprocess.HasExited)
|
||||
{
|
||||
pythonprocess.Kill(); // 终止 Python 进程
|
||||
}
|
||||
|
||||
Console.WriteLine("Python 进程已终止");
|
||||
}
|
||||
|
||||
public void startPythonDet()
|
||||
{
|
||||
// Python 解释器的路径
|
||||
string pythonInterpreter = @"D:\python311\python.exe"; // 替换为您的 Python 解释器路径
|
||||
|
||||
// Python 脚本的路径
|
||||
string scriptPath = @"D:\botdet\databot\bot.py";
|
||||
|
||||
// 创建并启动 Python 进程
|
||||
ProcessStartInfo start = new ProcessStartInfo
|
||||
{
|
||||
FileName = pythonInterpreter,
|
||||
Arguments = scriptPath,
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
CreateNoWindow = true
|
||||
};
|
||||
|
||||
pythonprocess = new Process { StartInfo = start };
|
||||
pythonprocess.Start();
|
||||
|
||||
// 在这里添加代码,根据您的需求执行其他任务
|
||||
// 例如,等待一段时间
|
||||
// Thread.Sleep(10000); // 等待10秒
|
||||
|
||||
// 当您想要终止 Python 脚本时
|
||||
// if (!pythonprocess.HasExited)
|
||||
// {
|
||||
// pythonprocess.Kill(); // 终止 Python 进程
|
||||
// }
|
||||
|
||||
// Console.WriteLine("Python 进程已终止");
|
||||
}
|
||||
|
||||
|
||||
public void getCmdfromUDP()
|
||||
{
|
||||
// UDP 端口
|
||||
int UDP_PORT = 5006;
|
||||
// 创建一个 UdpClient 用于读取传入的数据
|
||||
UdpClient udpClient = new UdpClient(UDP_PORT);
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
// 获取发送方的 IP 和端口
|
||||
IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
|
||||
|
||||
// 接收来自发送方的数据
|
||||
Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint);
|
||||
string returnData = Encoding.ASCII.GetString(receiveBytes);
|
||||
// 检查接收到的数据是否为空
|
||||
if (!string.IsNullOrWhiteSpace(returnData))
|
||||
{
|
||||
var receivedData = JsonConvert.DeserializeObject<Dictionary<int, List<object>>>(returnData);
|
||||
if (receivedData != null && receivedData.Count > 0)
|
||||
{
|
||||
// 处理接收到的数据
|
||||
// Console.WriteLine("Received: " + returnData);
|
||||
// DealWithCmd(receivedData);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 处理空数据
|
||||
// Console.WriteLine("Received empty data");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Received an empty message");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public void DealWithCmd(string receivedData) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class bg_in_out_water
|
||||
{
|
||||
IPEndPoint Vaves_Ctl_IP;//电磁阀的IP
|
||||
int Vaves_Ctl_IP_port = 8234;//电磁阀通信端口
|
||||
ModbusClient m_modbusClient;
|
||||
|
||||
public struct pod_ctl_st
|
||||
{
|
||||
public int podInPosSta;//瓶子在位状态
|
||||
public int waterInVaveSTA;//进阀门状态
|
||||
public int waterOutVaveSTA;//出阀门状态
|
||||
public float waterLeve;//液面高度百分比
|
||||
}
|
||||
|
||||
|
||||
public pod_ctl_st[] m_PodSTA = new pod_ctl_st[12];
|
||||
Thread th_readPod;
|
||||
|
||||
private void UpdatePodStatus(Dictionary<int, List<object>> bottleData)
|
||||
{
|
||||
foreach (var item in bottleData)
|
||||
{
|
||||
int bottleNumber = item.Key - 1; // 减1是因为数组索引从0开始
|
||||
var bottleInfo = item.Value;
|
||||
|
||||
// 更新瓶子状态
|
||||
m_PodSTA[bottleNumber].podInPosSta = Convert.ToInt32(bottleInfo[0]);
|
||||
m_PodSTA[bottleNumber].waterLeve = Convert.ToSingle(bottleInfo[1]);
|
||||
|
||||
// Console.WriteLine($"Bottle {bottleNumber + 1}: InPosSta = {m_PodSTA[bottleNumber].podInPosSta}, WaterLevel = {m_PodSTA[bottleNumber].waterLeve}");
|
||||
}
|
||||
}
|
||||
|
||||
public void getpodstafromUDP()
|
||||
{
|
||||
// UDP 端口
|
||||
int UDP_PORT = 5005;
|
||||
// 创建一个 UdpClient 用于读取传入的数据
|
||||
UdpClient udpClient = new UdpClient(UDP_PORT);
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
// 获取发送方的 IP 和端口
|
||||
IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
|
||||
|
||||
// 接收来自发送方的数据
|
||||
Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint);
|
||||
string returnData = Encoding.ASCII.GetString(receiveBytes);
|
||||
// 检查接收到的数据是否为空
|
||||
if (!string.IsNullOrWhiteSpace(returnData))
|
||||
{
|
||||
var receivedData = JsonConvert.DeserializeObject<Dictionary<int, List<object>>>(returnData);
|
||||
if (receivedData != null && receivedData.Count > 0)
|
||||
{
|
||||
// 处理接收到的数据
|
||||
// Console.WriteLine("Received: " + returnData);
|
||||
UpdatePodStatus(receivedData);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 处理空数据
|
||||
// Console.WriteLine("Received empty data");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Received an empty message");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bg_in_out_water() //初始化函数
|
||||
{
|
||||
// 创建Modbus客户端实例
|
||||
m_modbusClient = new ModbusClient("192.168.1.7", 8234); // 替换为你的设备IP地址和端口号
|
||||
m_modbusClient.Connect();
|
||||
Console.WriteLine("Connected to device");
|
||||
GetVaves_ALL_status();
|
||||
// 写入单个线圈(例如,地址1,状态true)
|
||||
Thread.Sleep(1000);
|
||||
for (int i = 1; i <= 24; i++)
|
||||
{
|
||||
SetVaves_status(i, 0);
|
||||
}
|
||||
|
||||
Console.WriteLine("Coil at address 1 written.");
|
||||
|
||||
th_readPod = new Thread(getpodstafromUDP);//创建读取线程
|
||||
th_readPod.Start();
|
||||
|
||||
}
|
||||
public bool GetVaves_ALL_status()
|
||||
{
|
||||
// 读取保持寄存器(例如,从地址0开始读取10个寄存器)
|
||||
int[] registers = m_modbusClient.ReadHoldingRegisters(0, 24); // 替换为你的寄存器地址和数量
|
||||
if (registers != null)
|
||||
{
|
||||
// Console.WriteLine("Read " + registers.Length + " registers:");
|
||||
int ID = 1;
|
||||
foreach (int register in registers)
|
||||
{
|
||||
// Console.WriteLine("ID=" + ID + " data=" + register);
|
||||
|
||||
// m_PodSTA[ID-1].waterOutVaveSTA = false;//更新阀门位置的函数
|
||||
// m_PodSTA[ID-1].waterInVaveSTA = false;
|
||||
ID++;
|
||||
}
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
ID = i + 1;
|
||||
m_PodSTA[i].waterInVaveSTA = registers[i * 2];
|
||||
m_PodSTA[i].waterOutVaveSTA = registers[i * 2 + 1];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Failed to read registers.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public bool SetVaves_status(int ID, int val)
|
||||
{
|
||||
if (ID <= 0 || ID > 24)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (val != 0 && val != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
m_modbusClient.WriteSingleRegister(ID - 1, val);
|
||||
Console.WriteLine($"Coil at address {ID}={val} written.");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
GetVaves_ALL_status();
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool outWater(int ID, float dstvalue)//放水直到dst停止,ID从1开始-12
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool inWater(int ID, float dstvalue)//加水直到dstvalue停止,ID从1开始-12
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void pod1InWater(int pmpspd)
|
||||
{
|
||||
//阀门控制
|
||||
sub_dev_Vave.SetVaves_status(1, 1);
|
||||
//通道1开启
|
||||
start_pump_in(1, 0);
|
||||
Thread.Sleep(1000);
|
||||
start_pump(1, pmpspd);//泵控制
|
||||
}
|
||||
public void pod1InWaterStop()
|
||||
{
|
||||
stopPump(1);//泵控制
|
||||
Thread.Sleep(1000);
|
||||
//阀门控制
|
||||
sub_dev_Vave.SetVaves_status(1, 0);
|
||||
}
|
||||
public void pod1OutWater(int pmpspd)
|
||||
{
|
||||
//阀门控制
|
||||
sub_dev_Vave.SetVaves_status(2, 1);
|
||||
//通道1开启
|
||||
start_pump_out(1, 0);
|
||||
Thread.Sleep(1000);
|
||||
start_pump(1, pmpspd);//泵控制
|
||||
}
|
||||
public void pod1OutWaterStop()
|
||||
{
|
||||
stopPump(1);//泵控制
|
||||
Thread.Sleep(1000);
|
||||
//阀门控制
|
||||
sub_dev_Vave.SetVaves_status(2, 0);
|
||||
}
|
||||
|
||||
public float targetlvin = 50;
|
||||
public float targetlvout = 30;
|
||||
private void processinwater()
|
||||
{
|
||||
float currentlv = sub_dev_Vave.m_PodSTA[0].waterLeve;
|
||||
if (currentlv - targetlvin > 0)
|
||||
{
|
||||
Console.WriteLine("target reached! return!");
|
||||
return;
|
||||
}
|
||||
Console.WriteLine("start in water!");
|
||||
pod1InWater(500);
|
||||
// this.pBVpod1pump.BackColor = Color.LightGreen;
|
||||
while (currentlv - targetlvin < -2)
|
||||
{
|
||||
currentlv = sub_dev_Vave.m_PodSTA[0].waterLeve;
|
||||
Thread.Sleep(100);//每隔100 检查一次
|
||||
}
|
||||
Console.WriteLine("in target reached, stop!");
|
||||
pod1InWaterStop();
|
||||
pod1OutWaterStop();
|
||||
//this.pBVpod1pump.BackColor = Color.DarkGray;
|
||||
|
||||
}
|
||||
Thread p1inth;
|
||||
public void runpod1InWater()
|
||||
{
|
||||
if (p1inth != null)
|
||||
{
|
||||
if (p1inth.IsAlive)
|
||||
{
|
||||
p1inth.Abort();
|
||||
p1inth = null;
|
||||
}
|
||||
}
|
||||
p1inth = new Thread(processinwater);
|
||||
p1inth.Start();
|
||||
}
|
||||
|
||||
public void runpod1OutWater()
|
||||
{
|
||||
if (p1inth != null)
|
||||
{
|
||||
if (p1inth.IsAlive)
|
||||
{
|
||||
p1inth.Abort();
|
||||
p1inth = null;
|
||||
}
|
||||
}
|
||||
p1inth = new Thread(processoutwater);
|
||||
p1inth.Start();
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void processoutwater()
|
||||
{
|
||||
float currentlv = sub_dev_Vave.m_PodSTA[0].waterLeve;
|
||||
if (currentlv - targetlvout < 0)
|
||||
{
|
||||
Console.WriteLine("target reached! return!");
|
||||
return;
|
||||
}
|
||||
Console.WriteLine("start out water!");
|
||||
pod1OutWater(500);
|
||||
// this.pBVpod1pump.BackColor = Color.LightGreen;
|
||||
while (currentlv - targetlvout > 2)
|
||||
{
|
||||
currentlv = sub_dev_Vave.m_PodSTA[0].waterLeve;
|
||||
Thread.Sleep(100);//每隔100 检查一次
|
||||
}
|
||||
Console.WriteLine("out target reached, stop!");
|
||||
pod1InWaterStop();
|
||||
pod1OutWaterStop();
|
||||
//this.pBVpod1pump.BackColor = Color.DarkGray;
|
||||
}
|
||||
public int duliQuitFlag = 0;
|
||||
public void runInWaterAuto_duli(int ID, int pumpspeed,float targetLv)
|
||||
{
|
||||
if(ID<=0 || ID > 12) { return; }
|
||||
duliQuitFlag = 0;
|
||||
int i = ID - 1;
|
||||
float currentlv = sub_dev_Vave.m_PodSTA[i].waterLeve;
|
||||
float start_lv = currentlv;
|
||||
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
if (currentlv - targetLv > 0)
|
||||
{
|
||||
Console.WriteLine("ID="+ID.ToString()+" target reached"+ " "+targetLv.ToString() +" return!");
|
||||
return;
|
||||
}
|
||||
|
||||
//打开进水阀门
|
||||
int openvavID = 2 * i + 1;
|
||||
int zuPumpID = (int)(i / 4) + 1;
|
||||
Console.WriteLine("进水 ID=" + ID.ToString() + " 阀门=" + openvavID.ToString() + " 泵+阀=" + zuPumpID.ToString());
|
||||
|
||||
sub_dev_Vave.SetVaves_status(openvavID, 1);
|
||||
//切换进水组电磁阀
|
||||
start_pump_in(zuPumpID, 0);
|
||||
Thread.Sleep(500);
|
||||
//启动进水泵
|
||||
stopwatch.Start();
|
||||
start_pump(zuPumpID, pumpspeed);//泵控制
|
||||
|
||||
while (currentlv - targetLv < -2)
|
||||
{
|
||||
currentlv = sub_dev_Vave.m_PodSTA[i].waterLeve;
|
||||
Thread.Sleep(100);//每隔100 检查一次
|
||||
if(duliQuitFlag==1)
|
||||
{
|
||||
Console.WriteLine("inwater forced quit!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
stopwatch.Stop();
|
||||
TimeSpan elapsedTime = stopwatch.Elapsed;
|
||||
|
||||
Console.WriteLine($"ID={ID}, from lv={start_lv} to lv={targetLv} with pumpspeed{pumpspeed}, " +
|
||||
$"the time is{elapsedTime},out target reached, stop! ");
|
||||
//关闭进水泵
|
||||
stopPump(zuPumpID);//泵控制
|
||||
|
||||
Thread.Sleep(1000);
|
||||
//阀门控制
|
||||
sub_dev_Vave.SetVaves_status(openvavID, 0);
|
||||
//关闭阀门
|
||||
Console.WriteLine();
|
||||
|
||||
}
|
||||
|
||||
public int in159Flag = 0;
|
||||
//1 5 9 inwater
|
||||
public void runInWater159(int pumpspeed, float targetlv)
|
||||
{
|
||||
in159Flag = 0;
|
||||
float curlv1 = sub_dev_Vave.m_PodSTA[0].waterLeve;
|
||||
float curlv5 = sub_dev_Vave.m_PodSTA[4].waterLeve;
|
||||
float curlv9 = sub_dev_Vave.m_PodSTA[8].waterLeve;
|
||||
int[] addwaterSTA = new int[3];
|
||||
//int[] pumpSTA = new int[3];
|
||||
|
||||
addwaterSTA[0] = 0;
|
||||
addwaterSTA[1] = 0;
|
||||
addwaterSTA[2] = 0;
|
||||
|
||||
if(curlv1 - targetlv >0)
|
||||
{
|
||||
Console.WriteLine("ID= 1 target reached" + " " + curlv1.ToString() + " return!");
|
||||
addwaterSTA[0] = 1;
|
||||
}
|
||||
if (curlv5 - targetlv > 0)
|
||||
{
|
||||
Console.WriteLine("ID= 5 target reached" + " " + curlv5.ToString() + " return!");
|
||||
addwaterSTA[1] = 1;
|
||||
}
|
||||
if (curlv9 - targetlv > 0)
|
||||
{
|
||||
Console.WriteLine("ID= 9 target reached" + " " + curlv9.ToString() + " return!");
|
||||
addwaterSTA[2] = 1;
|
||||
}
|
||||
for(int i = 0;i<3;i++)
|
||||
{
|
||||
if (addwaterSTA[i] == 0)
|
||||
{
|
||||
int openvavID_in = 8 * i + 1;
|
||||
sub_dev_Vave.SetVaves_status(openvavID_in, 1);//设置进出水电磁阀
|
||||
Thread.Sleep(100);
|
||||
int zuPumpID = i +1;
|
||||
start_pump_in(zuPumpID, 0);//设置泵为进水
|
||||
Thread.Sleep(500);
|
||||
//
|
||||
}
|
||||
}
|
||||
//开起泵
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
if (addwaterSTA[i] == 0)
|
||||
{
|
||||
int zuPumpID = i + 1;
|
||||
//启动泵
|
||||
start_pump(zuPumpID, pumpspeed);//泵控制启动
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
}
|
||||
//状态检测
|
||||
while (true)
|
||||
{
|
||||
curlv1 = sub_dev_Vave.m_PodSTA[0].waterLeve;
|
||||
curlv5 = sub_dev_Vave.m_PodSTA[4].waterLeve;
|
||||
curlv9 = sub_dev_Vave.m_PodSTA[8].waterLeve;
|
||||
|
||||
if ((curlv1 - targetlv > 0)&&(addwaterSTA[0] == 0))
|
||||
{
|
||||
Console.WriteLine("ID= 1 target reached" + " " + curlv1.ToString() + " return!");
|
||||
addwaterSTA[0] = 1;
|
||||
stopPump(1);//泵控制
|
||||
Thread.Sleep(500);
|
||||
sub_dev_Vave.SetVaves_status(1, 0);
|
||||
//关闭阀门
|
||||
}
|
||||
if ((curlv5 - targetlv > 0) && (addwaterSTA[1] == 0))
|
||||
{
|
||||
Console.WriteLine("ID= 5 target reached" + " " + curlv5.ToString() + " return!");
|
||||
addwaterSTA[1] = 1;
|
||||
stopPump(2);//泵控制
|
||||
Thread.Sleep(500);
|
||||
sub_dev_Vave.SetVaves_status(9, 0);
|
||||
//关闭阀门
|
||||
}
|
||||
if ((curlv9 - targetlv > 0)&& (addwaterSTA[2] == 0))
|
||||
{
|
||||
Console.WriteLine("ID= 9 target reached" + " " + curlv9.ToString() + " return!");
|
||||
addwaterSTA[2] = 1;
|
||||
stopPump(3);//泵控制
|
||||
Thread.Sleep(500);
|
||||
sub_dev_Vave.SetVaves_status(17, 0);
|
||||
//关闭阀门
|
||||
}
|
||||
if (addwaterSTA[1] + addwaterSTA[2] + addwaterSTA[0] >= 3)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void runOutWaterAuto_duli(int ID, int pumpspeed, float targetLv)
|
||||
{
|
||||
if (ID <= 0 || ID > 12) { return; }
|
||||
duliQuitFlag = 0;
|
||||
int i = ID - 1;
|
||||
float currentlv = sub_dev_Vave.m_PodSTA[i].waterLeve;
|
||||
|
||||
float start_lv = currentlv;
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
|
||||
if (currentlv - targetLv < 0)
|
||||
{
|
||||
Console.WriteLine("ID=" + ID.ToString() + " target reached" + " " + targetLv.ToString() + " return!");
|
||||
return;
|
||||
}
|
||||
//打开进水阀门
|
||||
int openvavID_out = 2 * ID;
|
||||
int zuPumpID = (int)(i / 4) + 1;
|
||||
Console.WriteLine("出水 ID=" + ID.ToString() + " 阀门=" + openvavID_out.ToString() + " 泵+阀=" + zuPumpID.ToString());
|
||||
|
||||
sub_dev_Vave.SetVaves_status(openvavID_out, 1);
|
||||
//切换出水组电磁阀
|
||||
start_pump_out(zuPumpID, 0);
|
||||
Thread.Sleep(500);
|
||||
//启动出泵
|
||||
stopwatch.Start();
|
||||
start_pump(zuPumpID, pumpspeed);//泵控制
|
||||
|
||||
while (currentlv - targetLv > 2)
|
||||
{
|
||||
currentlv = sub_dev_Vave.m_PodSTA[i].waterLeve;
|
||||
Thread.Sleep(100);//每隔100 检查一次
|
||||
if (duliQuitFlag == 1)
|
||||
{
|
||||
Console.WriteLine("outwater forced quit!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
stopwatch.Stop();
|
||||
TimeSpan elapsedTime = stopwatch.Elapsed;
|
||||
Console.WriteLine($"ID={ID}, from lv={start_lv} to lv={targetLv} with pumpspeed{pumpspeed}, " +
|
||||
$"the time is{elapsedTime},out target reached, stop! ");
|
||||
//关闭进水泵
|
||||
stopPump(zuPumpID);//泵控制
|
||||
Thread.Sleep(1000);
|
||||
//阀门控制
|
||||
sub_dev_Vave.SetVaves_status(openvavID_out, 0);
|
||||
//关闭阀门
|
||||
}
|
||||
|
||||
public void StopALL_VAV()
|
||||
{
|
||||
Console.WriteLine("stop ALL pumps");
|
||||
stopPump(1);//泵控制
|
||||
Thread.Sleep(500);
|
||||
stopPump(2);//泵控制
|
||||
Thread.Sleep(500);
|
||||
stopPump(3);//泵控制
|
||||
Thread.Sleep(500);
|
||||
Console.WriteLine("close ALL VAVS");
|
||||
for (int i = 1; i <= 24; i++)
|
||||
{
|
||||
sub_dev_Vave.SetVaves_status(i, 0);
|
||||
}
|
||||
}
|
||||
//组 1,2,3
|
||||
public int AddwaterQuitFLG = 0;
|
||||
public void run_inWater_Zu(int Zu_ID, int pumpspeed, float targetLv)
|
||||
{
|
||||
if (Zu_ID <= 0 || Zu_ID > 3) { return; }
|
||||
AddwaterQuitFLG = 0;
|
||||
|
||||
int lowpumpspeed = Math.Min(pumpspeed, 500);
|
||||
int realpumpspdcmd = pumpspeed;
|
||||
|
||||
int [] ID = new int[4];//通路号
|
||||
int[] idx = new int[4];//索引号
|
||||
int[] ID_status = new int[4];//4个子通路状态
|
||||
float[] currentlev = new float[4];
|
||||
float[] lev_err = new float[4];
|
||||
|
||||
int reachnum = 0;//已满通路数字
|
||||
for(int j=0;j<4;j++)
|
||||
{
|
||||
ID[j] = (Zu_ID-1)*4+j+1;
|
||||
idx[j] = ID[j] - 1;
|
||||
currentlev[j] = sub_dev_Vave.m_PodSTA[idx[j]].waterLeve;
|
||||
lev_err[j] = currentlev[j] - targetLv;
|
||||
if(lev_err[j]>=0)
|
||||
{
|
||||
ID_status[j] = 1;//当前通路已满
|
||||
reachnum++;
|
||||
Console.WriteLine("通路已满:" + ID[j].ToString() + " level=" + currentlev[j].ToString() + " target=" + targetLv.ToString());
|
||||
// realpumpspdcmd = lowpumpspeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
ID_status[j] = 0;//当前通路未满
|
||||
}
|
||||
}
|
||||
if(reachnum==4)//全部4个已经到达目标
|
||||
{
|
||||
Console.WriteLine("Zu_ID=" + Zu_ID.ToString() + "ALL target reached" + " " + targetLv.ToString() + " return!");
|
||||
for(int j=0;j<4;)
|
||||
{
|
||||
Console.WriteLine("ID=" + ID[j].ToString() + " lv=" + currentlev[j].ToString());
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(reachnum>=1)
|
||||
{
|
||||
realpumpspdcmd = lowpumpspeed;//有一个通路已满,速度换为龟速
|
||||
}
|
||||
|
||||
//切换进水组电磁阀
|
||||
start_pump_in(Zu_ID, 0);
|
||||
//打开需要加水的瓶子阀门
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
if (ID_status[j] == 0)//打开未满通路进水阀门
|
||||
{
|
||||
int openvavID1 = 2 * idx[j] + 1;
|
||||
sub_dev_Vave.SetVaves_status(openvavID1, 1);
|
||||
Console.WriteLine("进水 ID=" + ID[j].ToString() + " 阀门=" + openvavID1.ToString() + "打开");
|
||||
}
|
||||
}
|
||||
Thread.Sleep(500);
|
||||
//启动泵
|
||||
start_pump(Zu_ID, realpumpspdcmd);//泵控制启动
|
||||
|
||||
//循环检查,并关闭对应阀门
|
||||
while(true)
|
||||
{
|
||||
// int reachnum_dy = 0;
|
||||
for (int j = 0; j < 4; j++)//对每一个通路检查
|
||||
{
|
||||
currentlev[j] = sub_dev_Vave.m_PodSTA[idx[j]].waterLeve;
|
||||
lev_err[j] = currentlev[j] - targetLv;
|
||||
//只检查未满的通路
|
||||
if (ID_status[j] == 0)
|
||||
{
|
||||
if (lev_err[j] >= -1)//当前通路已满液
|
||||
{
|
||||
reachnum++;
|
||||
ID_status[j] = 1;
|
||||
Console.WriteLine("通路已满:" + ID[j].ToString() + " level=" + currentlev[j].ToString() + " target=" + targetLv.ToString());
|
||||
if (reachnum >= 4)//全部满了
|
||||
{
|
||||
stopPump(Zu_ID);//泵控制,停止
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
else if (reachnum == 1)//第一个满了时,切换泵速度
|
||||
{
|
||||
if (realpumpspdcmd != lowpumpspeed)//有一个通路已满时,采用低速
|
||||
{
|
||||
Console.WriteLine("using low pump speed 500");
|
||||
realpumpspdcmd = lowpumpspeed;
|
||||
stopPump(Zu_ID);//泵控制
|
||||
Thread.Sleep(500);
|
||||
start_pump(Zu_ID, realpumpspdcmd);//泵控制
|
||||
}
|
||||
|
||||
}
|
||||
int openvavID1 = 2 * idx[j] + 1;
|
||||
sub_dev_Vave.SetVaves_status(openvavID1, 0);//关闭阀门
|
||||
}
|
||||
}
|
||||
}
|
||||
if(reachnum >= 4)
|
||||
{
|
||||
Console.WriteLine("加液体完成,正常退出!");
|
||||
break;
|
||||
}
|
||||
if(AddwaterQuitFLG ==1)
|
||||
{
|
||||
Console.WriteLine("外部指令退出!关闭所有阀门和泵");
|
||||
stopPump(Zu_ID);//泵控制
|
||||
Thread.Sleep(500);
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
int openvavID1 = 2 * idx[j] + 1;
|
||||
sub_dev_Vave.SetVaves_status(openvavID1, 0);
|
||||
Console.WriteLine("进水 ID=" + ID[j].ToString() + " 阀门=" + openvavID1.ToString() + "关闭");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void run_outWater_Zu(int Zu_ID, int pumpspeed, float targetLv)
|
||||
{
|
||||
if (Zu_ID <= 0 || Zu_ID > 3) { return; }
|
||||
AddwaterQuitFLG = 0;
|
||||
|
||||
int lowpumpspeed = Math.Min(pumpspeed, 500);
|
||||
int realpumpspdcmd = pumpspeed;
|
||||
|
||||
int[] ID = new int[4];//通路号
|
||||
int[] idx = new int[4];//索引号
|
||||
int[] ID_status = new int[4];//4个子通路状态
|
||||
float[] currentlev = new float[4];
|
||||
float[] lev_err = new float[4];
|
||||
|
||||
int reachnum = 0;//已达到目标通路数字
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
ID[j] = (Zu_ID - 1) * 4 + j + 1;
|
||||
idx[j] = ID[j] - 1;
|
||||
currentlev[j] = sub_dev_Vave.m_PodSTA[idx[j]].waterLeve;
|
||||
lev_err[j] = targetLv -currentlev[j];
|
||||
if (lev_err[j] >= 0)
|
||||
{
|
||||
ID_status[j] = 1;//当前通路已达到目标
|
||||
reachnum++;
|
||||
Console.WriteLine("通路已达到目标:" + ID[j].ToString() + " level=" + currentlev[j].ToString() + " target=" + targetLv.ToString());
|
||||
// realpumpspdcmd = lowpumpspeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
ID_status[j] = 0;//当前通路未达到目标
|
||||
}
|
||||
}
|
||||
if (reachnum == 4)//全部4个已经到达目标
|
||||
{
|
||||
Console.WriteLine("Zu_ID=" + Zu_ID.ToString() + "ALL target reached" + " " + targetLv.ToString() + " return!");
|
||||
for (int j = 0; j < 4;)
|
||||
{
|
||||
Console.WriteLine("ID=" + ID[j].ToString() + " lv=" + currentlev[j].ToString());
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (reachnum >= 1)
|
||||
{
|
||||
realpumpspdcmd = lowpumpspeed;//有一个通路已满,速度换为龟速
|
||||
}
|
||||
|
||||
//切换出水组电磁阀
|
||||
start_pump_out(Zu_ID, 0);
|
||||
//打开需要加水的瓶子阀门
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
if (ID_status[j] == 0)//打开未满通路进水阀门
|
||||
{
|
||||
int openvavID1 = 2 * idx[j] + 2;
|
||||
sub_dev_Vave.SetVaves_status(openvavID1, 1);
|
||||
Console.WriteLine("出水 ID=" + ID[j].ToString() + " 阀门=" + openvavID1.ToString() + "打开");
|
||||
}
|
||||
}
|
||||
Thread.Sleep(500);
|
||||
//启动泵
|
||||
start_pump(Zu_ID, realpumpspdcmd);//泵控制启动
|
||||
|
||||
//循环检查,并关闭对应阀门
|
||||
while (true)
|
||||
{
|
||||
// int reachnum_dy = 0;
|
||||
for (int j = 0; j < 4; j++)//对每一个通路检查
|
||||
{
|
||||
currentlev[j] = sub_dev_Vave.m_PodSTA[idx[j]].waterLeve;
|
||||
lev_err[j] = targetLv - currentlev[j];
|
||||
//只检查未满的通路
|
||||
if (ID_status[j] == 0)
|
||||
{
|
||||
if (lev_err[j] >= 0)//当前通路已满液
|
||||
{
|
||||
reachnum++;
|
||||
ID_status[j] = 1;
|
||||
Console.WriteLine("通路已达到目标:" + ID[j].ToString() + " level=" + currentlev[j].ToString() + " target=" + targetLv.ToString());
|
||||
if (reachnum >= 4)//全部满了
|
||||
{
|
||||
stopPump(Zu_ID);//泵控制,停止
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
else if (reachnum == 1)//第一个满了时,切换泵速度
|
||||
{
|
||||
if (realpumpspdcmd != lowpumpspeed)//有一个通路已满时,采用低速
|
||||
{
|
||||
Console.WriteLine("using low pump speed 500");
|
||||
realpumpspdcmd = lowpumpspeed;
|
||||
stopPump(Zu_ID);//泵控制
|
||||
Thread.Sleep(500);
|
||||
start_pump(Zu_ID, realpumpspdcmd);//泵控制
|
||||
}
|
||||
|
||||
}
|
||||
int openvavID1 = 2 * idx[j] + 2;
|
||||
sub_dev_Vave.SetVaves_status(openvavID1, 0);//关闭阀门
|
||||
}
|
||||
}
|
||||
}
|
||||
if (reachnum >= 4)
|
||||
{
|
||||
Console.WriteLine("加液体完成,正常退出!");
|
||||
break;
|
||||
}
|
||||
if (AddwaterQuitFLG == 1)
|
||||
{
|
||||
Console.WriteLine("外部指令退出!关闭所有阀门和泵");
|
||||
stopPump(Zu_ID);//泵控制
|
||||
Thread.Sleep(500);
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
int openvavID1 = 2 * idx[j] + 2;
|
||||
sub_dev_Vave.SetVaves_status(openvavID1, 0);
|
||||
Console.WriteLine("出水 ID=" + ID[j].ToString() + " 阀门=" + openvavID1.ToString() + "关闭");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
361
middleware/zdhsys/Device/Dev_CZ.cs
Normal file
@@ -0,0 +1,361 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.Drawing;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace zdhsys
|
||||
{
|
||||
public class Dev_CZ
|
||||
{
|
||||
public Dev_CZ() {
|
||||
start_com();
|
||||
currentdata_cz = new chengzhongdata();
|
||||
rstPod = -1;
|
||||
rstPodval = -1;
|
||||
}
|
||||
|
||||
DateTimeOffset nowOffset;
|
||||
DateTimeOffset nowOffset_lastmsg;// 用于计算相邻间隔时间
|
||||
|
||||
Thread recvudp_chengzhong = null;//开启和接收udp线程
|
||||
//string data
|
||||
string udprcvdata_chengzhong;//
|
||||
UdpClient client_cz;//udp通信本机端
|
||||
IPAddress remoteIp_CZ;//设备地址
|
||||
IPEndPoint remoteEndPoint_CZ;//设备IP udp接收
|
||||
IPEndPoint remoteEndPoint_CZ_forsend;//设备IP udp发送
|
||||
int port = 5555;
|
||||
public int latest_dev_state;//最新设备状态
|
||||
public int latest_pod;//最新设备状态 pod
|
||||
public double latest_val;//最新设备反馈值
|
||||
public int timegap;
|
||||
|
||||
|
||||
public int rstPod;//接受到的称量的瓶子
|
||||
public double rstPodval;//称量结果
|
||||
bool newrstarrvied = false;
|
||||
|
||||
public struct memrst//pod = 0; 表示大瓶子;pod = 1-12 小瓶子
|
||||
{
|
||||
public int pod;
|
||||
public double val;
|
||||
}
|
||||
public memrst latest_mem_rst;
|
||||
|
||||
public memrst GetMemrst()
|
||||
{
|
||||
if(newrstarrvied)
|
||||
{
|
||||
newrstarrvied= false;
|
||||
latest_mem_rst.pod = rstPod;
|
||||
latest_mem_rst.val = rstPodval;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("warning, no new mem result got!");
|
||||
latest_mem_rst.pod = -1;
|
||||
latest_mem_rst.val = -1;
|
||||
}
|
||||
return latest_mem_rst;
|
||||
}
|
||||
|
||||
|
||||
struct chengzhongdata
|
||||
{
|
||||
public int status;
|
||||
public int podID;
|
||||
public int val;
|
||||
}
|
||||
chengzhongdata currentdata_cz;
|
||||
|
||||
struct chengzhongCMD
|
||||
{
|
||||
public int cmd;
|
||||
public int podID;
|
||||
public int addval;
|
||||
}
|
||||
chengzhongCMD currentCMD_cz;
|
||||
|
||||
|
||||
private void start_com()//初始化和启动udp
|
||||
{
|
||||
recvudp_chengzhong = new Thread(runrecv_chengzhong);
|
||||
recvudp_chengzhong.Start();
|
||||
}
|
||||
|
||||
private bool checkconnection()//检查链接,10秒超时
|
||||
{
|
||||
nowOffset = DateTimeOffset.Now;
|
||||
int timestampOffset = (int)(nowOffset - nowOffset_lastmsg).TotalSeconds;
|
||||
timegap = timestampOffset;
|
||||
if (timestampOffset > 10)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private void waitforok()//等待设备就绪,cmd == 8
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
Thread.Sleep(500);
|
||||
if(checkconnection())
|
||||
{
|
||||
if(latest_dev_state ==8)
|
||||
{
|
||||
break;
|
||||
}
|
||||
Console.WriteLine("not ready");
|
||||
Console.WriteLine(latest_dev_state.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
Console.WriteLine("device ready 8");
|
||||
}
|
||||
//发送指令
|
||||
//cmd = 1 初始化
|
||||
//cmd = 3 通知设备已收到数据
|
||||
//cmd = 4 发送称大瓶子指令
|
||||
//cmd = 5 定量加液体指令 podID val
|
||||
//cmd = 6 发送称小瓶子指令 podID
|
||||
private void sendcmd(int cmd, int ID, double val)//发送指令
|
||||
{
|
||||
// waitforok();
|
||||
string cmdsend = "{\"cmd\": ,\"ID\":-1,\"val\":-1}";
|
||||
JObject objs = JObject.Parse(cmdsend);
|
||||
objs["cmd"] = cmd;
|
||||
objs["ID"] = ID;
|
||||
objs["val"] = val;
|
||||
|
||||
string jsonstring = objs.ToString();
|
||||
|
||||
Console.WriteLine(jsonstring);
|
||||
byte[] senddata = System.Text.Encoding.UTF8.GetBytes(jsonstring);
|
||||
Console.WriteLine(remoteEndPoint_CZ_forsend.ToString());
|
||||
client_cz.Send(senddata, senddata.Length, remoteEndPoint_CZ_forsend);
|
||||
}
|
||||
|
||||
private void cmd_result()
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
sendcmd(3, -1, -1);
|
||||
Thread.Sleep(500);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//返回-1 表示链接断开或设备错误,其他,返回当前工作状态 8 空闲,9 错误,其他时候对应指令
|
||||
public int get_current_state()
|
||||
{
|
||||
if(checkconnection())
|
||||
{
|
||||
return latest_dev_state;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
//等待设备ok,发送初始化,确认初始化指令已收到
|
||||
public bool sendcmd_initial_until_start()
|
||||
{
|
||||
waitforok();
|
||||
Console.WriteLine("check dev state ok, send cmd");
|
||||
int cnt = 0;
|
||||
while(true)
|
||||
{
|
||||
cnt++;
|
||||
sendcmd(1, -1, -1);//发送初始化命令
|
||||
Thread.Sleep(1000);
|
||||
int state = get_current_state();
|
||||
Console.WriteLine(state.ToString());
|
||||
if (state == 1)
|
||||
{
|
||||
Console.WriteLine("send ok, device start initial");
|
||||
return true;
|
||||
}
|
||||
if(cnt > 10)
|
||||
{
|
||||
Console.WriteLine("send failed! ,time out break!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
//等待设备ok,发送指令,确认指令已收到
|
||||
public bool sendcmd_mem1_until_start()//称大瓶子
|
||||
{
|
||||
waitforok();
|
||||
Console.WriteLine("check dev state ok, send cmd");
|
||||
int cnt = 0;
|
||||
while (true)
|
||||
{
|
||||
cnt++;
|
||||
sendcmd(4, -1, -1);//发送命令
|
||||
Thread.Sleep(1000);
|
||||
int state = get_current_state();
|
||||
Console.WriteLine(state.ToString());
|
||||
if (state == 4)
|
||||
{
|
||||
Console.WriteLine("send ok, device start initial");
|
||||
return true;
|
||||
}
|
||||
if (cnt > 10)
|
||||
{
|
||||
Console.WriteLine("send failed! ,time out break!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
//等待设备ok,发送指令,确认指令已收到
|
||||
public bool sendcmd_Add_until_start(int podID, double val)//加磁核
|
||||
{
|
||||
waitforok();
|
||||
Console.WriteLine("check dev state ok, send cmd");
|
||||
int cnt = 0;
|
||||
while (true)
|
||||
{
|
||||
cnt++;
|
||||
sendcmd(5, podID, val);//发送命令
|
||||
Thread.Sleep(1000);
|
||||
int state = get_current_state();
|
||||
Console.WriteLine(state.ToString());
|
||||
if (state == 5)
|
||||
{
|
||||
Console.WriteLine("send ok, device start");
|
||||
return true;
|
||||
}
|
||||
if (cnt > 10)
|
||||
{
|
||||
Console.WriteLine("send failed! ,time out break!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
//等待设备ok,发送指令,确认指令已收到
|
||||
public bool sendcmd_Mem2_until_start(int podID)//称小瓶子
|
||||
{
|
||||
waitforok();
|
||||
Console.WriteLine("check dev state ok, send cmd");
|
||||
int cnt = 0;
|
||||
while (true)
|
||||
{
|
||||
cnt++;
|
||||
sendcmd(6, podID, -1);//发送命令
|
||||
Thread.Sleep(1000);
|
||||
int state = get_current_state();
|
||||
Console.WriteLine(state.ToString());
|
||||
if (state == 6)
|
||||
{
|
||||
Console.WriteLine("send ok, device start");
|
||||
return true;
|
||||
}
|
||||
if (cnt > 10)
|
||||
{
|
||||
Console.WriteLine("send failed! ,time out break!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//向设备反馈
|
||||
public bool sendcmd_havereceived()
|
||||
{
|
||||
sendcmd(3, -1, -1);//发送已收到指令
|
||||
rstPod = latest_pod;
|
||||
rstPodval = latest_val;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//udp 初始化, 接受udp信息
|
||||
private void runrecv_chengzhong()
|
||||
{
|
||||
client_cz = new UdpClient(5555);
|
||||
remoteIp_CZ = IPAddress.Parse("192.168.1.222");
|
||||
int remotePort = 5555;
|
||||
remoteEndPoint_CZ = new IPEndPoint(remoteIp_CZ, remotePort);
|
||||
remoteEndPoint_CZ_forsend = new IPEndPoint(remoteIp_CZ, remotePort);
|
||||
CancellationTokenSource cts = new CancellationTokenSource();
|
||||
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] data = client_cz.Receive(ref remoteEndPoint_CZ);
|
||||
if (data != null)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder("");
|
||||
sb.Append(Encoding.UTF8.GetString(data));
|
||||
// Console.WriteLine(sb);
|
||||
udprcvdata_chengzhong = sb.ToString();
|
||||
// Console.WriteLine(udprcvdata_chengzhong);
|
||||
try
|
||||
{
|
||||
string json_str_form = "{\"status\": 1,\"id\":0,\"val\":0}";
|
||||
JToken jTokenform = JToken.Parse(json_str_form);
|
||||
JObject objs = JObject.Parse(udprcvdata_chengzhong);
|
||||
|
||||
if (jTokenform.Type != objs.Type)
|
||||
{
|
||||
Console.WriteLine("JSON格式不正确!");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Console.WriteLine("JSON格式正确!");
|
||||
currentdata_cz.status = int.Parse(objs["status"].ToString());
|
||||
currentdata_cz.podID = int.Parse(objs["id"].ToString());
|
||||
currentdata_cz.val = int.Parse(objs["val"].ToString());
|
||||
//objs[]
|
||||
latest_dev_state = currentdata_cz.status;
|
||||
if (currentdata_cz.status == 3)
|
||||
{
|
||||
Console.WriteLine("got mesure val!");
|
||||
Console.WriteLine(currentdata_cz.podID.ToString());
|
||||
Console.WriteLine(currentdata_cz.val.ToString());
|
||||
latest_pod = currentdata_cz.podID;
|
||||
latest_val = currentdata_cz.val;
|
||||
sendcmd_havereceived();
|
||||
|
||||
}
|
||||
nowOffset_lastmsg = DateTimeOffset.Now;
|
||||
|
||||
}
|
||||
}
|
||||
catch(Exception ex) {
|
||||
Console.WriteLine(ex.Message.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// tbudpdata.Text = ex.ToString();
|
||||
// Console.WriteLine(ex.ToString());
|
||||
MessageBox.Show("UDP异常", ex.Message);
|
||||
// break;
|
||||
}
|
||||
// Thread.Sleep(1000);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
75
middleware/zdhsys/ExperimentData.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace zdhsys
|
||||
{
|
||||
public class ExperimentData
|
||||
{
|
||||
public string TaskId { get; set; }
|
||||
public string ExperimentName { get; set; }
|
||||
public List<Material> Materials { get; set; }
|
||||
public List<Container> Containers { get; set; }
|
||||
public List<Equipment> Equipments { get; set; }
|
||||
public List<WorkflowStep> RobotWorkflow { get; set; }
|
||||
}
|
||||
|
||||
public class Material
|
||||
{
|
||||
public string MaterialId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Amount { get; set; }
|
||||
public string Unit { get; set; }
|
||||
public string Purity { get; set; }
|
||||
public string State { get; set; }
|
||||
public string Formula {get; set;}
|
||||
}
|
||||
|
||||
public class Container
|
||||
{
|
||||
public string ContainerId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Capacity { get; set; }
|
||||
public string Unit { get; set; }
|
||||
public string MaterialOfConstruction { get; set; }
|
||||
public string Shape { get; set; }
|
||||
public string HeatResistant { get; set; }
|
||||
public string PressureRating { get; set; }
|
||||
}
|
||||
|
||||
public class Equipment
|
||||
{
|
||||
public string EquipmentId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public Dictionary<string, string> Parameters { get; set; }
|
||||
}
|
||||
|
||||
public class WorkflowStep
|
||||
{
|
||||
public string StepId { get; set; }
|
||||
public string Description { get; set; }
|
||||
public List<Action> Actions { get; set; }
|
||||
public List<string> Dependencies { get; set; }
|
||||
public StepOutput StepOutput { get; set; }
|
||||
}
|
||||
|
||||
public class Action
|
||||
{
|
||||
public string ActionType { get; set; }
|
||||
public string ContainerId { get; set; }
|
||||
public string MaterialId { get; set; }
|
||||
public string EquipmentId { get; set; }
|
||||
}
|
||||
|
||||
public class StepOutput
|
||||
{
|
||||
public string ContainerId { get; set; }
|
||||
public List<MaterialContent> Contents { get; set; }
|
||||
}
|
||||
|
||||
public class MaterialContent
|
||||
{
|
||||
public string MaterialId { get; set; }
|
||||
public string Amount { get; set; }
|
||||
public string Unit { get; set; }
|
||||
}
|
||||
}
|
||||
BIN
middleware/zdhsys/ICONS66.ico
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
middleware/zdhsys/Image/Group 345.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
middleware/zdhsys/Image/add.png
Normal file
|
After Width: | Height: | Size: 274 B |
BIN
middleware/zdhsys/Image/arrowLeft.png
Normal file
|
After Width: | Height: | Size: 770 B |
BIN
middleware/zdhsys/Image/arrowRight.png
Normal file
|
After Width: | Height: | Size: 638 B |
BIN
middleware/zdhsys/Image/delete.png
Normal file
|
After Width: | Height: | Size: 354 B |
BIN
middleware/zdhsys/Image/details.png
Normal file
|
After Width: | Height: | Size: 144 B |
BIN
middleware/zdhsys/Image/edit.png
Normal file
|
After Width: | Height: | Size: 507 B |
BIN
middleware/zdhsys/Image/import.png
Normal file
|
After Width: | Height: | Size: 430 B |
BIN
middleware/zdhsys/Image/menu/主页.png
Normal file
|
After Width: | Height: | Size: 992 B |
BIN
middleware/zdhsys/Image/menu/主页2.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
middleware/zdhsys/Image/menu/数据.png
Normal file
|
After Width: | Height: | Size: 627 B |
BIN
middleware/zdhsys/Image/menu/数据2.png
Normal file
|
After Width: | Height: | Size: 949 B |
BIN
middleware/zdhsys/Image/menu/流程.png
Normal file
|
After Width: | Height: | Size: 560 B |
BIN
middleware/zdhsys/Image/menu/流程2.png
Normal file
|
After Width: | Height: | Size: 665 B |
BIN
middleware/zdhsys/Image/menu/设备.png
Normal file
|
After Width: | Height: | Size: 811 B |
BIN
middleware/zdhsys/Image/menu/设备2.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
middleware/zdhsys/Image/menu/配方.png
Normal file
|
After Width: | Height: | Size: 988 B |
BIN
middleware/zdhsys/Image/menu/配方2.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
middleware/zdhsys/Image/model.png
Normal file
|
After Width: | Height: | Size: 368 B |
BIN
middleware/zdhsys/Image/move_down.png
Normal file
|
After Width: | Height: | Size: 7.5 KiB |
BIN
middleware/zdhsys/Image/move_up.png
Normal file
|
After Width: | Height: | Size: 7.3 KiB |
BIN
middleware/zdhsys/Image/save.png
Normal file
|
After Width: | Height: | Size: 455 B |
BIN
middleware/zdhsys/Image/see.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
middleware/zdhsys/Image/停止.png
Normal file
|
After Width: | Height: | Size: 893 B |
BIN
middleware/zdhsys/Image/列表收起.png
Normal file
|
After Width: | Height: | Size: 778 B |
BIN
middleware/zdhsys/Image/初始化.png
Normal file
|
After Width: | Height: | Size: 815 B |
BIN
middleware/zdhsys/Image/多边形 1.png
Normal file
|
After Width: | Height: | Size: 466 B |
BIN
middleware/zdhsys/Image/安全运行.png
Normal file
|
After Width: | Height: | Size: 766 B |
BIN
middleware/zdhsys/Image/实验分析,试剂,实验,检验,DNA检验,化学.png
Normal file
|
After Width: | Height: | Size: 374 B |
BIN
middleware/zdhsys/Image/实验室.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
middleware/zdhsys/Image/恢复.png
Normal file
|
After Width: | Height: | Size: 425 B |
BIN
middleware/zdhsys/Image/抽查检查.png
Normal file
|
After Width: | Height: | Size: 723 B |
BIN
middleware/zdhsys/Image/搜索.png
Normal file
|
After Width: | Height: | Size: 516 B |