添加middleware

This commit is contained in:
2025-03-02 15:11:22 +08:00
parent 329f5c8310
commit 84ee8354c0
924 changed files with 112743 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace zdhsys.Unitils
{
public class GetParentWindows
{
/// <summary>
/// 获取当前用户控件所在的左上角坐标
/// 用于给弹窗定位,只覆盖,当前自定义控件。不是当前软件,也不是全屏。
/// </summary>
/// <param name="win"></param>
/// <returns></returns>
public static Point GetPoint(UserControl win)
{
Point relativePoint = win.TransformToAncestor(Application.Current.MainWindow).Transform(new Point(0, 0)); // 获取相对于主窗体的位置
// 获取主窗体的位置
double mainWindowLeft = Application.Current.MainWindow.Left;
double mainWindowTop = Application.Current.MainWindow.Top;
// 计算控件相对于主窗体的位置
double controlX = mainWindowLeft + relativePoint.X;
double controlY = mainWindowTop + relativePoint.Y;
return new Point(controlX, controlY);
//当前主窗体
//Window parentWindow = Window.GetWindow(this);
//if (parentWindow != null)
//{
// info.Left = parentWindow.Left;
// info.Top = parentWindow.Top;
// info.Width = parentWindow.ActualWidth;
// info.Height = parentWindow.ActualHeight;
//}
}
public static Point GetPoint2(UserControl win)
{
GeneralTransform transform = win.TransformToAncestor(win.Parent as UIElement);
Point position = transform.Transform(new Point(0, 0));
Console.WriteLine($"position({position.X},{position.Y})");
return position;
}
}
}

View File

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace zdhsys.Unitils
{
public class GlobalEnum
{
public enum UnitOfMeasurement
{
,
,
,
,
,
}
public enum UnitBottle
{
,
}
/// <summary>
/// 设备类别--指定通信协议
/// </summary>
public enum UnitDeviceType
{
,
,
,
,
,
,
}
}
}

View File

@@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace zdhsys.Unitils
{
public class GlobalUnitils
{
public static DateTime GetByLong(long timestamp)
{
//DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(timestamp);
DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); // 当地时区
DateTime dt = startTime.AddSeconds(timestamp);
return dt;
}
public static string GetByLong2(long timestamp)
{
//DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(timestamp);
DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); // 当地时区
DateTime dt = startTime.AddSeconds(timestamp);
return dt.ToString("yyyy-MM-dd HH:mm:ss");
}
public static long GetNowTime(DateTime dateTime)
{
//DateTime dateTime = DateTime.Now; // 示例 DateTime
//DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
//long timestamp = (long)(dateTime.ToUniversalTime() - epoch).TotalSeconds;
//long timestamp = (dateTime.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
//Console.WriteLine(timestamp);
DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); // 当地时区
long timeStamp = (long)(dateTime - startTime).TotalSeconds; // 相差秒数
//Console.WriteLine(timeStamp);
return timeStamp;
}
public static Point GetScreenPosition(FrameworkElement element)
{
// 获取自定义控件在屏幕上的位置
Point position = element.PointToScreen(new Point(0, 0));
return position;
}
/// <summary>
/// 生成随机数
/// </summary>
/// <returns></returns>
public static long GetRandomLongNumber()
{
byte[] bytes = new byte[8];
using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider())
{
rng.GetBytes(bytes);
}
return BitConverter.ToInt64(bytes, 0);
}
}
}

View File

@@ -0,0 +1,300 @@
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.Media;
namespace zdhsys.Unitils
{
public class GridViewUnitls
{
/// <summary>
/// 给表格添加一行分割线
/// </summary>
/// <param name="gridContent"></param>
/// <param name="gridHeader"></param>
public static void AddSpLine(Grid gridContent, Grid gridHeader)
{
RowDefinition newRow2 = new RowDefinition
{
Height = new GridLength(1)
};
// 添加新行到 Grid
gridContent.RowDefinitions.Add(newRow2);
for (int i = 0; i < gridHeader.ColumnDefinitions.Count; i++)
{
ColumnDefinition newColumn = new ColumnDefinition
{
Width = new GridLength(GetColumnWidth2(gridHeader, i))
};
gridContent.ColumnDefinitions.Add(newColumn);
// 添加对应的控件到新的格子中
Border border = new Border();
Color color2 = (Color)ColorConverter.ConvertFromString("#E8E8E8");
SolidColorBrush brush2 = new SolidColorBrush(color2);
border.Background = brush2;
Grid.SetRow(border, gridContent.RowDefinitions.Count - 1);
Grid.SetColumn(border, i);
_ = gridContent.Children.Add(border);
}
}
public static void AddSpLine2(Grid gridHeader,int spanColumn, double width)
{
RowDefinition newRow2 = new RowDefinition
{
Height = new GridLength(1)
};
// 添加新行到 Grid
gridHeader.RowDefinitions.Add(newRow2);
ColumnDefinition newColumn = new ColumnDefinition
{
Width = new GridLength(width)
};
gridHeader.ColumnDefinitions.Add(newColumn);
// 添加对应的控件到新的格子中
Border border = new Border();
Color color2 = (Color)ColorConverter.ConvertFromString("#FFFFFF");
SolidColorBrush brush2 = new SolidColorBrush(color2);
border.Background = brush2;
Grid.SetRow(border, gridHeader.RowDefinitions.Count - 1);
Grid.SetColumn(border, 0);
Grid.SetColumnSpan(border, spanColumn);
_ = gridHeader.Children.Add(border);
}
/// <summary>
/// 获取实际列宽
/// </summary>
/// <param name="grid"></param>
/// <param name="columnIndex"></param>
/// <returns></returns>
public static double GetColumnWidth2(Grid grid, int columnIndex)
{
if (columnIndex >= 0 && columnIndex < grid.ColumnDefinitions.Count)
{
ColumnDefinition columnDefinition = grid.ColumnDefinitions[columnIndex];
return columnDefinition.ActualWidth; // 获取列宽度的值
}
else
{
return 0; // 或者返回其他默认值或错误处理
}
}
public static void AddCell(Grid gridContent, int index,string content)
{
TextBlock newTextBlock = new TextBlock
{
Text = content,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
Color color = (Color)ColorConverter.ConvertFromString("#333333");
newTextBlock.Foreground = new SolidColorBrush(color);
Grid.SetRow(newTextBlock, gridContent.RowDefinitions.Count - 1);
Grid.SetColumn(newTextBlock, index);
gridContent.Children.Add(newTextBlock);
}
public static void AddCell2(Grid gridContent, int index, string content)
{
TextBlock newTextBlock = new TextBlock
{
Text = content,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
Color color = (Color)ColorConverter.ConvertFromString("#333333");
newTextBlock.Foreground = new SolidColorBrush(color);
Border border = new Border
{
BorderBrush = Brushes.White,
BorderThickness = new Thickness(2, 0, 0, 0),
Child = newTextBlock // newTextBlock 为之前创建的 TextBlock
};
Grid.SetRow(border, gridContent.RowDefinitions.Count - 1);
Grid.SetColumn(border, index);
gridContent.Children.Add(border);
}
public static void AddCellTextBox(Grid gridContent, int index, string content, object obj,bool flag)
{
// 创建 TextBox 控件
TextBox textBox = new TextBox
{
BorderThickness = new Thickness(0),
Text = content,
TextAlignment = TextAlignment.Center,
VerticalContentAlignment = VerticalAlignment.Center,
Tag = obj,
IsEnabled = flag
};
Color color = (Color)ColorConverter.ConvertFromString("#333333");
textBox.Foreground = new SolidColorBrush(color);
Grid.SetRow(textBox, gridContent.RowDefinitions.Count - 1);
Grid.SetColumn(textBox, index);
gridContent.Children.Add(textBox);
}
public static void AddCell(Grid gridContent, int index, string content, int spanColumn)
{
TextBlock newTextBlock = new TextBlock
{
Text = content,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
Color color = (Color)ColorConverter.ConvertFromString("#333333");
newTextBlock.Foreground = new SolidColorBrush(color);
Border border = new Border
{
BorderBrush = Brushes.White,
BorderThickness = new Thickness(2, 0, 0, 0),
Child = newTextBlock // newTextBlock 为之前创建的 TextBlock
};
Grid.SetRow(border, gridContent.RowDefinitions.Count - 1);
Grid.SetColumn(border, index);
Grid.SetColumnSpan(border, spanColumn);
gridContent.Children.Add(border);
}
public static void AddCell(Grid gridContent, int index, string content,string hex)
{
TextBlock newTextBlock = new TextBlock
{
Text = content,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
Color color = (Color)ColorConverter.ConvertFromString(hex);
newTextBlock.Foreground = new SolidColorBrush(color);
Grid.SetRow(newTextBlock, gridContent.RowDefinitions.Count - 1);
Grid.SetColumn(newTextBlock, index);
gridContent.Children.Add(newTextBlock);
}
public static string ColorHexNormal = "#00BC32";
public static string ColorHexBreak = "#FF0909";
public static void AddCellStatus(Grid gridContent, int index, string content, string hex)
{
//拼装一下,在前面加一个点。
content = "·" + new string('\u0020', 3) + content;
TextBlock newTextBlock = new TextBlock
{
Text = content,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
Color color = (Color)ColorConverter.ConvertFromString(hex);
newTextBlock.Foreground = new SolidColorBrush(color);
Grid.SetRow(newTextBlock, gridContent.RowDefinitions.Count - 1);
Grid.SetColumn(newTextBlock, index);
gridContent.Children.Add(newTextBlock);
}
/// <summary>
/// 按表头添加1列
/// </summary>
/// <param name="gridContent"></param>
/// <param name="gridHeader"></param>
/// <param name="index"></param>
public static void AddColumn(Grid gridContent, Grid gridHeader,int index)
{
ColumnDefinition newColumn = new ColumnDefinition
{
Width = new GridLength(GridViewUnitls.GetColumnWidth2(gridHeader, index))
};
gridContent.ColumnDefinitions.Add(newColumn);
}
/// <summary>
/// 添加指定宽度的列
/// </summary>
/// <param name="gridContent"></param>
/// <param name="width"></param>
public static void AddColumn2(Grid gridContent, double width)
{
ColumnDefinition newColumn = new ColumnDefinition
{
Width = new GridLength(width)
};
gridContent.ColumnDefinitions.Add(newColumn);
}
public static void AddRow(Grid gridContent)
{
RowDefinition newRow = new RowDefinition
{
Height = new GridLength(40)
};
// 添加新行到 Grid
gridContent.RowDefinitions.Add(newRow);
}
public static void AddRow(Grid gridContent, double width)
{
RowDefinition newRow = new RowDefinition
{
Height = new GridLength(width)
};
// 添加新行到 Grid
gridContent.RowDefinitions.Add(newRow);
}
public static void AddCellCheck(Grid gridContent, int index,object obj)
{
CheckBox check = new CheckBox
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
Tag = obj
};
Grid.SetRow(check, gridContent.RowDefinitions.Count - 1);
Grid.SetColumn(check, index);
_ = gridContent.Children.Add(check);
}
public static List<CheckBox> FindCheckBoxesInGrid(Grid grid)
{
List<CheckBox> checkboxes = new List<CheckBox>();
foreach (UIElement element in grid.Children)
{
if (element is CheckBox checkbox)
{
checkboxes.Add(checkbox);
}
//else if (element is Grid childGrid)
//{
// checkboxes.AddRange(FindCheckBoxesInGrid(childGrid));
//}
}
return checkboxes;
}
public static void CheckBoxesInGrid(Grid grid, bool flag)
{
for (int i = 0; i < grid.Children.Count; i++)
{
UIElement element = grid.Children[i];
if (element is CheckBox checkbox)
{
checkbox.IsChecked = flag;
grid.Children[i] = checkbox;
}
}
}
}
}

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace zdhsys.Unitils
{
public class RoborUnitils
{
public static TCPHelper robot;
public static bool ConnectRobot(string ip,int port)
{
robot = new TCPHelper();
robot.Connect(ip, port);
if (robot.Connected())
{
return true;
}
return false;
}
}
}

View File

@@ -0,0 +1,216 @@
using zdhsys.entity;
namespace zdhsys.Unitils
{
public class RobotCmd
{
/// <summary>
/// 从目标位置取瓶子
/// </summary>
/// <param name="src"></param>
/// <returns></returns>
public static RobotHeart TakeBottle(string src)
{
// cmd = 2 取瓶子
RobotHeart rh = new RobotHeart
{
cmd = 2,
point = 1
};
MoveData md = new MoveData
{
ID_src = int.Parse(src),
ID_dst = 0
};
rh.data = md;
return rh;
}
/// <summary>
/// 将瓶子放到目标位置
/// </summary>
/// <param name="src"></param>
/// <returns></returns>
public static RobotHeart PutTheBottle(string src)
{
// cmd = 3 放瓶子
RobotHeart rh = new RobotHeart
{
cmd = 3,
point = 1
};
MoveData md = new MoveData
{
ID_src = 0,
ID_dst = int.Parse(src)
};
rh.data = md;
return rh;
}
/// <summary>
/// 移动瓶子
/// </summary>
/// <param name="src">当前位置</param>
/// <param name="dst">目标位置</param>
/// <returns></returns>
public static RobotHeart MoveBottle(string src, string dst)
{
// cmd = 1 移动瓶子
RobotHeart rh = new RobotHeart
{
cmd = 1,
point = 1
};
MoveData md = new MoveData
{
ID_src = int.Parse(src),
ID_dst = int.Parse(dst)
};
rh.data = md;
return rh;
}
/// <summary>
/// A6 接药水操作
/// </summary>
/// <param name="src"></param>
/// <returns></returns>
public static RobotHeart WaterIntake(string src)
{
// cmd = 6 接药水操作
RobotHeart rh = new RobotHeart
{
cmd = 6,
point = 1
};
MoveData md = new MoveData
{
ID_src = int.Parse(src),
ID_dst = 0
};
rh.data = md;
return rh;
}
/// <summary>
/// A7 接药水操作_返回
/// </summary>
/// <param name="src"></param>
/// <returns></returns>
public static RobotHeart WaterReturn(string src)
{
// cmd = 7 接药水操作_返回
RobotHeart rh = new RobotHeart
{
cmd = 7,
point = 1
};
MoveData md = new MoveData
{
ID_src = int.Parse(src),
ID_dst = 0
};
rh.data = md;
return rh;
}
/// <summary>
/// 机械臂回0指的是机械臂收起但导轨不运动
/// </summary>
/// <returns></returns>
public static RobotHeart ArmRetraction()
{
RobotHeart rh = new RobotHeart
{
cmd = 4,
point = 1
};
MoveData md = new MoveData
{
ID_src = 0,
ID_dst = 0
};
rh.data = md;
return rh;
}
/// <summary>
/// 去位置ID10时使用防止碰撞
/// </summary>
/// <returns></returns>
public static RobotHeart ArmReturn10()
{
//机械臂回0位置(机械臂收起朝向平行导轨去位置ID10时使用防止碰撞)
RobotHeart rh = new RobotHeart
{
cmd = 10,
point = 1
};
MoveData md = new MoveData
{
ID_src = 0,
ID_dst = 0
};
rh.data = md;
return rh;
}
/// <summary>
/// 机械臂收起同时导轨运动到0位置
/// </summary>
/// <returns></returns>
public static RobotHeart ArmReturn_0()
{
RobotHeart rh = new RobotHeart
{
cmd = 5,
point = 1
};
MoveData md = new MoveData
{
ID_src = 0,
ID_dst = 0
};
rh.data = md;
return rh;
}
/// <summary>
/// 急停
/// </summary>
/// <returns></returns>
public static RobotHeart ArmScram()
{
RobotHeart rh = new RobotHeart
{
cmd = 0,
point = 1
};
MoveData md = new MoveData
{
ID_src = 0,
ID_dst = 0
};
rh.data = md;
return rh;
}
/// <summary>
/// 软件复位(不要随意使用)
/// </summary>
/// <returns></returns>
public static RobotHeart SoftwareReset()
{
RobotHeart rh = new RobotHeart
{
cmd = 9,
point = 1
};
MoveData md = new MoveData
{
ID_src = 0,
ID_dst = 0
};
rh.data = md;
return rh;
}
}
}

View File

@@ -0,0 +1,415 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using zdhsys.Bean;
using zdhsys.entity;
namespace zdhsys.Unitils
{
public class SeeJsons
{
public List<List<List<PrintCmd>>> getJson(int flowId, string str)
{
List<FlowModel> fms = SqlHelper.GetFlowModelInfo();
FlowModel fm = fms.Find(x => x.Id == flowId);
// 1.先查看原流程。把包硅反应这个切分开来。
List<FlowInfo> infos = JsonConvert.DeserializeObject<List<FlowInfo>>(fm.FlowJson);
// 判断包硅反应分割几个小流程。一般2个。这里做动态分割
List<int> bg = new List<int>();
for (int i = 0; i < infos.Count; i++)
{
if (infos[i].tempTxt == "包硅反应")
{
bg.Add(i);
Console.WriteLine("包硅反应 index=" + i);
}
}
// 配方数据
List<string> vs = JsonConvert.DeserializeObject<List<string>>(str);
// 第一个瓶子的流程。 其它重复。
List<DevInfo> di = JsonConvert.DeserializeObject<List<DevInfo>>(vs[0]);
List<List<int>> vvs = new List<List<int>>();
// 如果没有包硅反应,那么这个流程图就是整个流程。
if (bg.Count == 0)
{
List<int> vs1 = new List<int>();
for (int i = 0; i < di.Count; i++)
{
vs1.Add(i);
}
vs1.Add(di.Count);
vvs.Add(vs1);
}
else
{
// 2.首先是分几个小流程
for (int i = 0; i <= bg.Count; i++)
{
if (i == 0)
{
List<int> vs1 = new List<int>();
for (int k = 0; k < di.Count; k++)
{
if (k < bg[i])
{
vs1.Add(k);
}
}
vvs.Add(vs1);
}
else if (i < bg.Count) //中间段
{
List<int> vs1 = new List<int>();
for (int k = 0; k < di.Count; k++)
{
if (k > bg[i - 1] && k < bg[i])
{
vs1.Add(k);
//Console.WriteLine("包硅反应 index=" + i);
}
}
vvs.Add(vs1);
}
else if (i == bg.Count) //最后段
{
List<int> vs1 = new List<int>();
for (int k = 0; k < di.Count; k++)
{
if (k > bg[i - 1])
{
vs1.Add(k);
//Console.WriteLine("包硅反应 index=" + i);
}
}
vvs.Add(vs1);
}
}
}
Console.WriteLine("流程段:" + vvs.Count);
// 设备列表
List<DeviceInfoModel> devices = SqlHelper.GetDeviceInfo();
// 先找出包硅反应的设备组
GlobalEnum.UnitDeviceType udt = GlobalEnum.UnitDeviceType.;
int index = Array.IndexOf(Enum.GetValues(typeof(GlobalEnum.UnitDeviceType)), udt);
// 包硅设备
DeviceInfoModel baogui = null;
// 包硅反应的点位坐标
DevicePoint dpt = null;
// 先找出包硅设备。
baogui = devices.Find(x => x.DeviceGroupId == index.ToString());
if (baogui != null && !string.IsNullOrEmpty(baogui.PointJson))
{
dpt = JsonConvert.DeserializeObject<DevicePoint>(baogui.PointJson);
Console.WriteLine("包硅反应点位坐标不为空。");
}
List<List<List<PrintCmd>>> pppc = new List<List<List<PrintCmd>>>();
for (int i = 0; i < vvs.Count; i++)
{
List<List<PrintCmd>> ppc = new List<List<PrintCmd>>();
for (int k = 0; k < vs.Count; k++)
{
List<PrintCmd> pc = new List<PrintCmd>();
for (int j = 0; j < vvs[i].Count; j++)
{
List<DevInfo> dif = JsonConvert.DeserializeObject<List<DevInfo>>(vs[k]);
for (int n = 0; n < dif.Count; n++)
{
if (vvs[i][j] == n)
{
if (n < infos.Count)
{
string src = "";
if (infos[n].DeviceId == baogui.Id)
{
//包硅设备. index 从0开始。但是点位从1开始。这里+1
src = getDpoint(dpt, k + 1);
}
else
{
DeviceInfoModel ddim = devices.Find(x => x.Id == infos[n].DeviceId);
src = (int)ddim.X + "";
}
// 0抓=2 1接=6+7 2放=3 3=放+工作+抓
if (infos[n].Cmd == 0)
{
Console.WriteLine($"设备ID={dif[n].Id} 流程Cmd= 2 {src} 0");
PrintCmd pcd = new PrintCmd
{
cmd = "2 " + src + " 0",
opt = 0,
device = devices.Find(x => x.Id == dif[n].Id).DeviceId
};
pc.Add(pcd);
PrintCmd pcd2 = new PrintCmd
{
opt = 1,
device = devices.Find(x => x.Id == dif[n].Id).DeviceId,
devInfo = dif[n]
};
if (!isZero(pcd2.devInfo))
{
pc.Add(pcd2);
}
}
else if (infos[n].Cmd == 1)
{
Console.WriteLine($"设备ID={dif[n].Id} 流程Cmd= 6 {src} 0 sleep(30)流程Cmd= 7 {src} 0");
PrintCmd pcd = new PrintCmd
{
cmd = "6 " + src + " 0",
opt = 0,
device = devices.Find(x => x.Id == dif[n].Id).DeviceId
};
PrintCmd pcd2 = new PrintCmd
{
opt = 1,
device = devices.Find(x => x.Id == dif[n].Id).DeviceId,
devInfo = dif[n]
};
PrintCmd pcd3 = new PrintCmd
{
cmd = "7 " + src + " 0",
opt = 0,
device = devices.Find(x => x.Id == dif[n].Id).DeviceId
};
if (!isZero(pcd2.devInfo))
{
pc.Add(pcd);
pc.Add(pcd2);
pc.Add(pcd3);
}
}
else if (infos[n].Cmd == 2)
{
Console.WriteLine($"设备ID={dif[n].Id} 流程Cmd= 3 {src} 0");
PrintCmd pcd = new PrintCmd
{
cmd = "3 0 " + src,
opt = 0,
device = devices.Find(x => x.Id == dif[n].Id).DeviceId
};
pc.Add(pcd);
}
else if (infos[n].Cmd == 3)
{
PrintCmd pcd = new PrintCmd
{
cmd = "3 0 " + src,
opt = 0,
device = devices.Find(x => x.Id == dif[n].Id).DeviceId
};
pc.Add(pcd);
PrintCmd pcd2 = new PrintCmd
{
opt = 1,
device = devices.Find(x => x.Id == dif[n].Id).DeviceId,
devInfo = dif[n]
};
if (!isZero(pcd2.devInfo))
{
pc.Add(pcd2);
}
PrintCmd pcd3 = new PrintCmd
{
cmd = "2 " + src + " 0",
opt = 0,
device = devices.Find(x => x.Id == dif[n].Id).DeviceId
};
pc.Add(pcd3);
Console.WriteLine($"设备ID={dif[n].Id} 流程Cmd= 3 {src} 0");
Console.WriteLine($"开始工作=============================");
Console.WriteLine($"设备ID={dif[n].Id} 流程Cmd= 2 {src} 0");
}
}
else
{
// 特别注意。这里使用的是 infos n-1 的,因为这个就是最后一个流程,取 cmd2。
string src = "";
if (infos[n - 1].DeviceId2 == baogui.Id)
{
//包硅设备
src = getDpoint(dpt, k + 1);
}
else
{
DeviceInfoModel ddim = devices.Find(x => x.Id == infos[n - 1].DeviceId2);
src = (int)ddim.X + "";
}
// 0抓=2 1接=6+7 2放=3
if (infos[n - 1].Cmd2 == 0)
{
Console.WriteLine($"设备ID={dif[n].Id} 流程Cmd= 2 {src} 0");
PrintCmd pcd = new PrintCmd
{
cmd = "2 " + src + " 0",
opt = 0,
device = devices.Find(x => x.Id == dif[n].Id).DeviceId
};
pc.Add(pcd);
PrintCmd pcd2 = new PrintCmd
{
opt = 1,
device = devices.Find(x => x.Id == dif[n].Id).DeviceId,
devInfo = dif[n]
};
if (!isZero(pcd2.devInfo))
{
pc.Add(pcd2);
}
}
else if (infos[n - 1].Cmd2 == 1)
{
Console.WriteLine($"设备ID={dif[n].Id} 流程Cmd= 6 {src} 0 sleep(30)流程Cmd= 7 {src} 0");
PrintCmd pcd = new PrintCmd
{
cmd = "6 " + src + " 0",
opt = 0,
device = devices.Find(x => x.Id == dif[n].Id).DeviceId
};
PrintCmd pcd2 = new PrintCmd
{
opt = 1,
device = devices.Find(x => x.Id == dif[n].Id).DeviceId,
devInfo = dif[n]
};
PrintCmd pcd3 = new PrintCmd
{
cmd = "7 " + src + " 0",
opt = 0,
device = devices.Find(x => x.Id == dif[n].Id).DeviceId
};
// 如果这个加粉液的设备参数都是0就直接跳过这个设备
if (!isZero(pcd2.devInfo))
{
pc.Add(pcd);
pc.Add(pcd2);
pc.Add(pcd3);
}
}
else if (infos[n - 1].Cmd2 == 2)
{
Console.WriteLine($"设备ID={dif[n].Id} 流程Cmd= 3 {src} 0");
PrintCmd pcd = new PrintCmd
{
cmd = "3 0 " + src,
opt = 0,
device = devices.Find(x => x.Id == dif[n].Id).DeviceId
};
pc.Add(pcd);
}
else if (infos[n - 1].Cmd2 == 3)
{
Console.WriteLine($"设备ID={dif[n].Id} 流程Cmd= 3 0 {src}");
Console.WriteLine($"开始称重");
Console.WriteLine($"设备ID={dif[n].Id} 流程Cmd= 2 {src} 0");
PrintCmd pcd = new PrintCmd
{
cmd = "3 0 " + src,
opt = 0,
device = devices.Find(x => x.Id == dif[n].Id).DeviceId
};
pc.Add(pcd);
PrintCmd pcd2 = new PrintCmd
{
opt = 1,
device = devices.Find(x => x.Id == dif[n].Id).DeviceId,
devInfo = dif[n]
};
if (!isZero(pcd2.devInfo))
{
pc.Add(pcd2);
}
PrintCmd pcd3 = new PrintCmd
{
cmd = "2 " + src + " 0",
opt = 0,
device = devices.Find(x => x.Id == dif[n].Id).DeviceId
};
pc.Add(pcd3);
}
}
break;
}
}
}
ppc.Add(pc);
Console.WriteLine("Json=" + JsonConvert.SerializeObject(pc));
Console.WriteLine("开始阶段内瓶子循环:++++++++++++++++++++++++");
}
Console.WriteLine("JsonList=" + JsonConvert.SerializeObject(ppc));
Console.WriteLine(" 开始下一段循环:-------------------------------------");
pppc.Add(ppc);
}
Console.WriteLine("JsonListList=" + JsonConvert.SerializeObject(pppc));
return pppc;
}
private bool isZero(DevInfo dio)
{
for (int i = 0; i < dio.Dfms.Count; i++)
{
if (int.TryParse(dio.Dfms[i].FieldsContent, out int ret))
{
if (ret != 0)
{
return false;
}
}
}
return true;
}
private string getDpoint(DevicePoint dpt, int index)
{
string src = "";
switch (index)
{
case 1:
src = dpt.p1;
break;
case 2:
src = dpt.p2;
break;
case 3:
src = dpt.p3;
break;
case 4:
src = dpt.p4;
break;
case 5:
src = dpt.p5;
break;
case 6:
src = dpt.p6;
break;
case 7:
src = dpt.p7;
break;
case 8:
src = dpt.p8;
break;
case 9:
src = dpt.p9;
break;
case 10:
src = dpt.p10;
break;
case 11:
src = dpt.p11;
break;
case 12:
src = dpt.p12;
break;
default:
break;
}
return src;
}
}
}

View File

@@ -0,0 +1,315 @@
using SQLite;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using zdhsys.Bean;
namespace zdhsys.Unitils
{
public class SqlHelper
{
private static SQLiteConnection db;
private static readonly string dbName = "zdhsys.db";
#region
public static void InitSQLite()
{
if (File.Exists(dbName))
{
db = new SQLiteConnection(dbName);
return;
}
// 如果数据库文件不存在,就创建一个
db = new SQLiteConnection(dbName);
//创建表
_ = db.CreateTable<Options>();
//设备表
_ = db.CreateTable<DeviceInfoModel>();
//设备组表
_ = db.CreateTable<DeviceGroupInfoModel>();
//转移类设备
_ = db.CreateTable<RobotInfoModel>();
//子配方
_ = db.CreateTable<SubOptionModel>();
//流程表
_ = db.CreateTable<FlowModel>();
}
public static void Add(object obj)
{
_ = db.Insert(obj);
}
public static void Update(object obj)
{
_ = db.Update(obj);
}
public static void Delete(object obj)
{
_ = db.Delete(obj);
}
#endregion
#region
#region
/// <summary>
/// 配方表
/// </summary>
/// <returns></returns>
public static List<Options> GetOptions()
{
return db.Query<Options>("select * from Options");
}
/// <summary>
/// 配方表按条件查询
/// </summary>
/// <param name="groupName"></param>
/// <param name="status"></param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
/// <returns></returns>
public static List<Options> GetOptionsInfoBy(string groupName, int status, string startTime, string endTime)
{
string sql = "SELECT * FROM Options WHERE 1=1 ";
if (!string.IsNullOrEmpty(groupName))
{
sql += " AND OptionName LIKE '%" + groupName + "%'";
}
if (status < 2)
{
sql += " AND Status = " + status;
}
if (!string.IsNullOrEmpty(startTime))
{
sql += " AND CreateTime > " + startTime;
}
if (!string.IsNullOrEmpty(endTime))
{
sql += " AND CreateTime < " + endTime;
}
return db.Query<Options>(sql);
}
/// <summary>
/// 子配方表
/// </summary>
/// <returns></returns>
public static List<SubOptionModel> GetSubOptionModel()
{
return db.Query<SubOptionModel>("select * from SubOptionModel");
}
/// <summary>
/// 按ID查询 - 子配方表
/// </summary>
/// <returns></returns>
public static List<SubOptionModel> GetSubOptionModelById(int Id)
{
return db.Query<SubOptionModel>("select * from SubOptionModel where Id=" + Id);
}
/// <summary>
/// 子配方表按条件查询
/// </summary>
/// <param name="groupName"></param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
/// <returns></returns>
public static List<SubOptionModel> GetSubOptionInfoBy(string groupName, string startTime, string endTime)
{
string sql = "SELECT * FROM SubOptionModel WHERE 1=1 ";
if (!string.IsNullOrEmpty(groupName))
{
sql += " AND SubOptionName LIKE '%" + groupName + "%'";
}
if (!string.IsNullOrEmpty(startTime))
{
sql += " AND CreateTime > " + startTime;
}
if (!string.IsNullOrEmpty(endTime))
{
sql += " AND CreateTime < " + endTime;
}
return db.Query<SubOptionModel>(sql);
}
#endregion
#region
/// <summary>
/// 获取所有流程
/// </summary>
/// <returns></returns>
public static List<FlowModel> GetFlowModelInfo()
{
return db.Query<FlowModel>("select * from FlowModel");
}
/// <summary>
/// 流程查询按条件
/// </summary>
/// <param name="groupName"></param>
/// <param name="status"></param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
/// <returns></returns>
public static List<FlowModel> GetFlowDataInfoBy(string groupName, int status, string startTime, string endTime)
{
string sql = "SELECT * FROM FlowModel WHERE 1=1 ";
if (!string.IsNullOrEmpty(groupName))
{
sql += " AND FlowName LIKE '%" + groupName + "%'";
}
if (status < 2)
{
sql += " AND Status = " + status;
}
if (!string.IsNullOrEmpty(startTime))
{
sql += " AND CreateTime > " + startTime;
}
if (!string.IsNullOrEmpty(endTime))
{
sql += " AND CreateTime < " + endTime;
}
return db.Query<FlowModel>(sql);
}
#endregion
#region
/// <summary>
/// 查询所有设备
/// </summary>
/// <returns></returns>
public static List<DeviceInfoModel> GetDeviceInfo()
{
List<DeviceInfoModel> vs = db.Query<DeviceInfoModel>("select * from DeviceInfoModel");
vs = vs.OrderBy(c => c.Sort).ToList();//这里不按ID排序。按Sort排序返回
return vs;
}
/// <summary>
/// 按条件查询设备
/// </summary>
/// <param name="groupName"></param>
/// <param name="status"></param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
/// <returns></returns>
public static List<DeviceInfoModel> GetDeviceInfoBy(string groupName, int status, string startTime, string endTime)
{
string sql = "SELECT * FROM DeviceInfoModel WHERE 1=1 ";
if (!string.IsNullOrEmpty(groupName))
{
sql += " AND DeviceName LIKE '%" + groupName + "%'";
}
if (status < 2)
{
sql += " AND DeviceStatus = " + status;
}
if (!string.IsNullOrEmpty(startTime))
{
sql += " AND CreateTime > " + startTime;
}
if (!string.IsNullOrEmpty(endTime))
{
sql += " AND CreateTime < " + endTime;
}
List<DeviceInfoModel> vs = db.Query<DeviceInfoModel>(sql);
vs = vs.OrderBy(c => c.Sort).ToList();//这里不按ID排序。按Sort排序返回
return vs;
}
#endregion
#region
/// <summary>
/// 查询设备组所有
/// </summary>
/// <returns></returns>
public static List<DeviceGroupInfoModel> GetDeviceGroupInfo()
{
return db.Query<DeviceGroupInfoModel>("select * from DeviceGroupInfoModel");
}
/// <summary>
/// 按ID查询
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
public static List<DeviceGroupInfoModel> GetDeviceGroupInfoById(string Id)
{
return db.Query<DeviceGroupInfoModel>("select * from DeviceGroupInfoModel where Id=" + Id);
}
/// <summary>
/// 获取设备组表记录数
/// </summary>
/// <returns></returns>
public static int CountDeviceGroupInfo()
{
return db.Query<DeviceGroupInfoModel>("select * from DeviceGroupInfoModel").Count;
}
/// <summary>
/// 按条件查询设备组记录
/// </summary>
/// <param name="groupName"></param>
/// <param name="status"></param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
/// <returns></returns>
public static List<DeviceGroupInfoModel> GetDeviceGroupInfoBy(string groupName,int status,string startTime,string endTime)
{
string sql = "SELECT * FROM DeviceGroupInfoModel WHERE 1=1 ";
if (!string.IsNullOrEmpty(groupName))
{
sql += " AND DeviceName LIKE '%" + groupName + "%'";
}
if (status < 2)
{
sql += " AND DeviceStatus = " + status;
}
if (!string.IsNullOrEmpty(startTime))
{
sql += " AND CreateTime > " + startTime ;
}
if (!string.IsNullOrEmpty(endTime))
{
sql += " AND CreateTime < " + endTime;
}
//sql += " LIMIT " + limitStart + "," + limitEnd;
return db.Query<DeviceGroupInfoModel>(sql);
}
#endregion
#region
/// <summary>
/// 查询机械臂信息
/// </summary>
/// <returns></returns>
public static List<RobotInfoModel> GetRobotInfo()
{
if (db != null)
{
return db.Query<RobotInfoModel>("select * from RobotInfoModel");
}
return null;
}
#endregion
#endregion
}
}

View File

@@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace zdhsys.Unitils
{
public class TCPHelper
{
public string ip = "127.0.0.1";
public int port = 8888;
private TcpClient tcp = new TcpClient();
private NetworkStream stream;
private Thread th = null;
public bool Connect(string ip,int port)
{
try
{
// 连接服务器
//await tcp.ConnectAsync(ip, port);
tcp.Connect(ip,port);
if (tcp.Connected)
{
stream = tcp.GetStream();
th = new Thread(new ThreadStart(Recv));
th.Start();
}
return tcp.Connected;
}
catch { }
return false;
}
public bool Connected()
{
try
{
if (tcp != null)
{
return tcp.Connected;
}
}
catch { }
return false;
}
public void Send(string json)
{
// 异步发送数据
byte[] sendData = Encoding.ASCII.GetBytes(json);
stream.Write(sendData, 0, sendData.Length);
Console.WriteLine("发送数据成功!");
}
public void Recv()
{
while (tcp.Connected)
{
try
{
// 接收数据
byte[] receiveData = new byte[1024];
int bytesRead = stream.Read(receiveData, 0, receiveData.Length);
string receiveMessage = Encoding.ASCII.GetString(receiveData, 0, bytesRead);
Console.WriteLine("接收到服务器消息:{0}", receiveMessage);
Thread.Sleep(250);
}
catch {
Console.WriteLine("TCP断开连接");
}
}
}
public void Close()
{
try
{
tcp.Close();
}
catch { }
}
}
}