|
- using BPA.Communication;
- using BPA.Helper;
- using BPA.Message;
- using BPA.Message.Enum;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- 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 WpfTest
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- /// <summary>
- /// MQTT连接信息
- /// </summary>
- public string MQTTConnection { get; set; } = "171.221.208.23,11883,admin,public1";
-
- /// <summary>
- /// Mqtt是否运行
- /// </summary>
- public bool IsRunningMqtt = false;
- /// <summary>
- /// Mqtt
- /// </summary>
- public MqttHelper mqttHelper = new MqttHelper();
-
- public MainWindow()
- {
- InitializeComponent();
- Connection();
- ThreadServer();
- //Button_Click(null, null);
- }
- public void ThreadServer()
- {
- TaskManage.GetInstance.StartLong(new Action(() =>
- {
- try
- {
- if (IsRunningMqtt)
- {
- Send(ScreenDeviceType.大炒);
-
- Send(ScreenDeviceType.小炒); Thread.Sleep(1000);
-
- Send(ScreenDeviceType.煮面机); Thread.Sleep(1000);
-
- Send(ScreenDeviceType.分餐机); Thread.Sleep(1000);
- Thread.Sleep(3000);
- }
- }
- catch (Exception ex)
- {
- MessageLog.GetInstance.ShowEx($"{Name}:线程服务异常,原因:{ex.Message}");
- }
- Thread.Sleep(100);
- }), $"{Name},线程服务");
- }
- /// <summary>
- /// 初始化连接Redis MQTT
- /// </summary>
- public void Connection()
- {
- try
- {
- //2.Mqtt连接
- if (!string.IsNullOrEmpty(this.MQTTConnection) && this.MQTTConnection.Contains(','))
- {
- string[] mqttcom = this.MQTTConnection.Split(',');
- if (mqttcom != null && mqttcom.Count() == 4)
- {
- mqttHelper.Connect(mqttcom[2], mqttcom[3], mqttcom[0], int.Parse(mqttcom[1]), $"{Name}:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
- }
- }
- mqttHelper.Disconnect = new Action(() =>
- {
- IsRunningMqtt = false;
- MessageLog.GetInstance.ShowEx($"{Name}:MQTT异常断开....");
- });
- mqttHelper.ConnectOk = new Action(() =>
- {
- IsRunningMqtt = true;//连接成功
- });
- }
- catch (Exception ex)
- {
- MessageLog.GetInstance.ShowEx($"{Name}:初始化连接 MQTT,原因:{ex.Message}");
- }
-
- }
-
- public void Send(ScreenDeviceType screen)
- {
- int k2 =new Random().Next(0, 2);
- SendScreenDataModel sendScreenData = new SendScreenDataModel();
-
- List<ORDER_STATUS> oRDER_STATUS = new List<ORDER_STATUS>() { ORDER_STATUS.WAIT, ORDER_STATUS.COOKING, ORDER_STATUS.COMPLETED_COOK, ORDER_STATUS.COMPLETED_TAKE, ORDER_STATUS.ERR_NOT_REPLY_WHEN_COOKING };
- List<string> name_s = new List<string>() { "回锅肉", "烂肉豇豆", "火爆腰花", "尖椒鸡杂", "回锅肉" };
- List<string> name_s_zm = new List<string>() { "清汤面", "鸡蛋面", "火鸡面", "回锅肉面", "鸡杂面" };
-
- List<string> name_XM = new List<string>() { "王权贵", "张哲", "李青古", "龙西", "李富贵" };
- int k = new Random().Next(0, 5);
- int M = new Random().Next(0, 5);
- if (screen == ScreenDeviceType.大炒)
- {
- sendScreenData.Name = screen;
- sendScreenData.Value = new ScreenModelMaxWok
- {
- IsRun = k2 == 0 ? IsRun.运行 : IsRun.停止,
- WorkStatus_1 = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机,
- WorkStatus_2 = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机,
- RobotStatu = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机,
- // Alarm = new List<AlarmModel> {
- // new AlarmModel { AlarmTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "XXXX机构出现故障!!!!" },
- // new AlarmModel { AlarmTime = DateTime.Now.AddSeconds(1).ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "XXXX机构出现故障!!!!" },
- // new AlarmModel { AlarmTime = DateTime.Now.AddSeconds(2).ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "XXXX机构出现故障!!!!" },
- //},
- FailuresCount = 0,
- StatsCount = new List<StatsModel> {
- new StatsModel{Name= name_s[0],Count=new Random().Next(0, 100)},
- new StatsModel{Name= name_s[1],Count=new Random().Next(0, 100)},
- new StatsModel{Name= name_s[2],Count=new Random().Next(0, 100)},
- new StatsModel{Name= name_s[3],Count=new Random().Next(0, 100)},
- new StatsModel{Name= name_s[4],Count=new Random().Next(0, 100)},
- },
- MaxWok_Dishes_1 = "回锅肉",
- MaxWok_Task_1 = "炒菜中",
- MaxWok_Process_1 = new List<ProcessModel> {
- new ProcessModel{ Id=0,Name= "清洗", Status=(M==0) ? ProcessStatus.正在执行:((M>0)?ProcessStatus.执行完成:ProcessStatus.未执行)},
- new ProcessModel{ Id=1,Name= "到菜", Status=(M==1) ? ProcessStatus.正在执行:((M>1)?ProcessStatus.执行完成:ProcessStatus.未执行)},
- new ProcessModel{ Id=2,Name= "翻炒", Status=(M==2) ? ProcessStatus.正在执行:((M>2)?ProcessStatus.执行完成:ProcessStatus.未执行)},
- new ProcessModel{ Id=3,Name= "调料", Status=(M==3) ? ProcessStatus.正在执行:((M>3)?ProcessStatus.执行完成:ProcessStatus.未执行)},
- new ProcessModel{ Id=4,Name= "完成", Status=(M==4) ? ProcessStatus.正在执行:((M>4)?ProcessStatus.执行完成:ProcessStatus.未执行)},
- },
- MaxWok_HeatGear_1 = "1",
- MaxWok_StirGear_1 = "2",
- MaxWok_FlipSpeed_1 = "30",
- MaxWok_Temp_1 = "102",
- MaxWok_OrderCount_1 = new Random().Next(0, 100),
- MaxWok_ErrorOrderCount_1 = new Random().Next(0, 100),
-
- MaxWok_Dishes_2 = "烂肉豇豆",
- MaxWok_Task_2 = "炒菜中",
- MaxWok_Process_2 = new List<ProcessModel> {
- new ProcessModel{ Id=0,Name= "清洗", Status=(k==0) ? ProcessStatus.正在执行:((k>0)?ProcessStatus.执行完成:ProcessStatus.未执行)},
- new ProcessModel{ Id=1,Name= "到菜", Status=(k==1) ? ProcessStatus.正在执行:((k>1)?ProcessStatus.执行完成:ProcessStatus.未执行)},
- new ProcessModel{ Id=2,Name= "翻炒", Status=(k==2) ? ProcessStatus.正在执行:((k>2)?ProcessStatus.执行完成:ProcessStatus.未执行)},
- new ProcessModel{ Id=3,Name= "调料", Status=(k==3) ? ProcessStatus.正在执行:((k>3)?ProcessStatus.执行完成:ProcessStatus.未执行)},
- new ProcessModel{ Id=4,Name= "完成", Status=(k==4) ? ProcessStatus.正在执行:((k>4)?ProcessStatus.执行完成:ProcessStatus.未执行)},
- },
- MaxWok_HeatGear_2 = "2",
- MaxWok_StirGear_2 = "3",
- MaxWok_FlipSpeed_2 = "32",
- MaxWok_Temp_2 = "132",
- MaxWok_OrderCount_2 = new Random().Next(0, 100),
- MaxWok_ErrorOrderCount_2 = new Random().Next(0, 100),
- };
- }
- else if (screen == ScreenDeviceType.小炒)
- {
- sendScreenData.Name = screen;
- sendScreenData.Value = new ScreenModelMinWok
- {
- IsRun = k2 == 0 ? IsRun.运行 : IsRun.停止,
- WorkStatus_1 = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机,
- WorkStatus_2 = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机,
- RobotStatu = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机,
- // Alarm = new List<AlarmModel> {
- // new AlarmModel { AlarmTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "XXXX机构出现故障!!!!" },
- // new AlarmModel { AlarmTime = DateTime.Now.AddSeconds(1).ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "XXXX机构出现故障!!!!" },
- // new AlarmModel { AlarmTime = DateTime.Now.AddSeconds(2).ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "XXXX机构出现故障!!!!" },
- //},
- FailuresCount = 0,
- StatsCount = new List<StatsModel> {
- new StatsModel{Name= name_s[0],Count=new Random().Next(0, 100)},
- new StatsModel{Name= name_s[1],Count=new Random().Next(0, 100)},
- new StatsModel{Name= name_s[2],Count=new Random().Next(0, 100)},
- new StatsModel{Name= name_s[3],Count=new Random().Next(0, 100)},
- new StatsModel{Name= name_s[4],Count=new Random().Next(0, 100)},
- },
- MinWok_Dishes_1 = "回锅肉",
- MinWok_Task_1 = "炒菜中",
- MinWok_Process_1 = new List<ProcessModel> {
- new ProcessModel{ Id=0,Name= "清洗", Status=(M==0) ? ProcessStatus.正在执行:((M>0)?ProcessStatus.执行完成:ProcessStatus.未执行)},
- new ProcessModel{ Id=1,Name= "到菜", Status=(M==1) ? ProcessStatus.正在执行:((M>1)?ProcessStatus.执行完成:ProcessStatus.未执行)},
- new ProcessModel{ Id=2,Name= "翻炒", Status=(M==2) ? ProcessStatus.正在执行:((M>2)?ProcessStatus.执行完成:ProcessStatus.未执行)},
- new ProcessModel{ Id=3,Name= "调料", Status=(M==3) ? ProcessStatus.正在执行:((M>3)?ProcessStatus.执行完成:ProcessStatus.未执行)},
- new ProcessModel{ Id=4,Name= "完成", Status=(M==4) ? ProcessStatus.正在执行:((M>4)?ProcessStatus.执行完成:ProcessStatus.未执行)},
- },
- MinWok_HeatGear_1 = "1",
- MinWok_StirGear_1 = "2",
- MinWok_FlipSpeed_1 = "30",
- MinWok_Temp_1 = "102",
- MinWok_OrderCount_1 = new Random().Next(0, 100),
- MinWok_ErrorOrderCount_1 = new Random().Next(0, 100),
-
- MinWok_Dishes_2 = "烂肉豇豆",
- MinWok_Task_2 = "炒菜中",
- MinWok_Process_2 = new List<ProcessModel> {
- new ProcessModel{ Id=0,Name= "清洗", Status=(k==0) ? ProcessStatus.正在执行:((k>0)?ProcessStatus.执行完成:ProcessStatus.未执行)},
- new ProcessModel{ Id=1,Name= "到菜", Status=(k==1) ? ProcessStatus.正在执行:((k>1)?ProcessStatus.执行完成:ProcessStatus.未执行)},
- new ProcessModel{ Id=2,Name= "翻炒", Status=(k==2) ? ProcessStatus.正在执行:((k>2)?ProcessStatus.执行完成:ProcessStatus.未执行)},
- new ProcessModel{ Id=3,Name= "调料", Status=(k==3) ? ProcessStatus.正在执行:((k>3)?ProcessStatus.执行完成:ProcessStatus.未执行)},
- new ProcessModel{ Id=4,Name= "完成", Status=(k==4) ? ProcessStatus.正在执行:((k>4)?ProcessStatus.执行完成:ProcessStatus.未执行)},
- },
- MinWok_HeatGear_2 = "2",
- MinWok_StirGear_2 = "3",
- MinWok_FlipSpeed_2 = "32",
- MinWok_Temp_2 = "132",
- MinWok_OrderCount_2 = new Random().Next(0, 100),
- MinWok_ErrorOrderCount_2 = new Random().Next(0, 100),
- };
- }
- else if (screen == ScreenDeviceType.煮面机)
- {
- sendScreenData.Name = screen;
- sendScreenData.Value = new ScreenModelMorkS
- {
- IsRun = k2 == 0 ? IsRun.运行 : IsRun.停止,
- WorkStatus = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机,
- RobotStatu = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机,
- Alarm = new List<AlarmModel> {
- new AlarmModel { AlarmTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "煮面机警告,水温过低!!!!" },
- //new AlarmModel { AlarmTime = DateTime.Now.AddSeconds(1).ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "XXXX机构出现故障!!!!" },
- //new AlarmModel { AlarmTime = DateTime.Now.AddSeconds(2).ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "XXXX机构出现故障!!!!" },
- },
- FailuresCount = 0,
- StatsCount = new List<StatsModel> {
- new StatsModel { Name = name_s_zm[0], Count = new Random().Next(0, 100) },
- new StatsModel { Name = name_s_zm[1], Count = new Random().Next(0, 100) },
- new StatsModel { Name = name_s_zm[2], Count = new Random().Next(0, 100) },
- new StatsModel { Name = name_s_zm[3], Count = new Random().Next(0, 100) },
- new StatsModel { Name = name_s_zm[4], Count = new Random().Next(0, 100) },
- },
- MorkS_OrderCount = new Random().Next(0, 100),
- MorkS_ErrorOrderCount = new Random().Next(0, 100),
- Morks_NoodleUpOrDown = new bool[] {
- true,true,true,true,false,true
- },
-
- MorkS_Temp = false,// k2 == 0 ? "true" : "false",
- MorkS_BinLocation = new Random().Next(0, 6),
- Morks_SiloMeasUp = k2 == 0 ,
- Morks_SiloMeasDown = k2 == 0,
- MorkS_NoBowMeas1= new Random().Next(0, 2)==1,
- MorkS_NoBowMeas2 = new Random().Next(0, 2) == 1,
-
-
- MakeOrder = new List<OrderMakeModel> {
- new OrderMakeModel { GoodName= name_s_zm[new Random().Next(0, 5)], StartTime=DateTime.Now.ToString("HH:mm:ss"), Status=ORDER_STATUS.WAIT, SortNum="007".ToString()},
- new OrderMakeModel { GoodName= name_s_zm[new Random().Next(0, 5)], StartTime=DateTime.Now.ToString("HH:mm:ss"), Status=ORDER_STATUS.WAIT, SortNum="008".ToString()},
- new OrderMakeModel { GoodName= name_s_zm[new Random().Next(0, 5)], StartTime=DateTime.Now.ToString("HH:mm:ss"), Status=ORDER_STATUS.WAIT, SortNum="009".ToString()},
- new OrderMakeModel { GoodName= name_s_zm[new Random().Next(0, 5)], StartTime=DateTime.Now.ToString("HH:mm:ss"), Status=ORDER_STATUS.WAIT, SortNum="010".ToString()},
- new OrderMakeModel { GoodName= name_s_zm[new Random().Next(0, 5)], StartTime=DateTime.Now.ToString("HH:mm:ss"), Status=ORDER_STATUS.WAIT, SortNum="011".ToString()},
- new OrderMakeModel { GoodName= name_s_zm[new Random().Next(0, 5)], StartTime=DateTime.Now.ToString("HH:mm:ss"), Status=ORDER_STATUS.COMPLETED_COOK, SortNum="006".ToString()},
- new OrderMakeModel { GoodName= name_s_zm[new Random().Next(0, 5)], StartTime=DateTime.Now.ToString("HH:mm:ss"), Status=ORDER_STATUS.COMPLETED_TAKE, SortNum="005".ToString()},
- new OrderMakeModel { GoodName= name_s_zm[new Random().Next(0, 5)], StartTime=DateTime.Now.ToString("HH:mm:ss"), Status=ORDER_STATUS.COMPLETED_TAKE, SortNum="004".ToString()},
- new OrderMakeModel { GoodName= name_s_zm[new Random().Next(0, 5)], StartTime=DateTime.Now.ToString("HH:mm:ss"), Status=ORDER_STATUS.COMPLETED_TAKE, SortNum="003".ToString()},
- new OrderMakeModel { GoodName= name_s_zm[new Random().Next(0, 5)], StartTime=DateTime.Now.ToString("HH:mm:ss"), Status=ORDER_STATUS.COMPLETED_TAKE, SortNum="002".ToString()},
- new OrderMakeModel { GoodName= name_s_zm[new Random().Next(0, 5)], StartTime=DateTime.Now.ToString("HH:mm:ss"), Status=ORDER_STATUS.COMPLETED_TAKE, SortNum="001".ToString()},
- },
-
- };
- }
- else if (screen == ScreenDeviceType.分餐机)
- {
- sendScreenData.Name = screen;
- sendScreenData.Value = new ScreenModelSplitMeals
- {
- IsRun = k2 == 0 ? IsRun.运行 : IsRun.停止,
- WorkStatus = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机,
- WorkStatus_1 = WorkStatus.待机,
- WorkStatus_2 = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机,
- WorkStatus_3 = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机,
- WorkStatus_4 = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机,
- WorkStatus_5 = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机,
- WorkStatus_6 = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机,
- RobotStatu1= k2 == 0 ? WorkStatus.工作 : WorkStatus.待机,
- RobotStatu2 = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机,
-
- RobotStatu = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机,
- //Alarm = new List<AlarmModel> {
- // new AlarmModel { AlarmTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "XXXX机构出现故障!!!!" },
- //new AlarmModel { AlarmTime = DateTime.Now.AddSeconds(1).ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "XXXX机构出现故障!!!!" },
- //new AlarmModel { AlarmTime = DateTime.Now.AddSeconds(2).ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "XXXX机构出现故障!!!!" },
- //},
- FailuresCount = 0,
- StatsCount = new List<StatsModel> {
- new StatsModel { Name = name_s[0], Count = new Random().Next(0, 100) },
- new StatsModel { Name = name_s[1], Count = new Random().Next(0, 100) },
- new StatsModel { Name = name_s[2], Count = new Random().Next(0, 100) },
- new StatsModel { Name = name_s[3], Count = new Random().Next(0, 100) },
- new StatsModel { Name = name_s[4], Count = new Random().Next(0, 100) },
- },
- SplitMeals_CreditCardCount_1 = new Random().Next(0, 100),
- SplitMeals_CreditCardNameBefore_1 = name_XM[new Random().Next(0, 5)],
- SplitMeals_CreditCardName_1 = name_XM[new Random().Next(0, 5)],
- SplitMeals_CookType_1 = new List<string>() { "回锅肉", "烂肉豇豆", "火爆腰花" },
-
- SplitMeals_CreditCardCount_2 = new Random().Next(0, 100),
- SplitMeals_CreditCardNameBefore_2 = name_XM[new Random().Next(0, 5)],
- SplitMeals_CreditCardName_2 = name_XM[new Random().Next(0, 5)],
- SplitMeals_CookType_2 = new List<string>() { "回锅肉", "烂肉豇豆", "火爆腰花" },
-
- SplitMeals_CreditCardCount_3 = new Random().Next(0, 100),
- SplitMeals_CreditCardNameBefore_3 = name_XM[new Random().Next(0, 5)],
- SplitMeals_CreditCardName_3 = name_XM[new Random().Next(0, 5)],
- SplitMeals_CookType_3 = new List<string>() { "回锅肉", "烂肉豇豆", "火爆腰花" },
-
- SplitMeals_CreditCardCount_4 = new Random().Next(0, 100),
- SplitMeals_CreditCardNameBefore_4 = name_XM[new Random().Next(0, 5)],
- SplitMeals_CreditCardName_4 = name_XM[new Random().Next(0, 5)],
- SplitMeals_CookType_4 = new List<string>() { "回锅肉", "烂肉豇豆", "火爆腰花" },
-
- SplitMeals_CreditCardCount_5 = new Random().Next(0, 100),
- SplitMeals_CreditCardNameBefore_5 = name_XM[new Random().Next(0, 5)],
- SplitMeals_CreditCardName_5 = name_XM[new Random().Next(0, 5)],
- SplitMeals_CookType_5 = new List<string>() { "回锅肉", "烂肉豇豆", "火爆腰花" },
-
- SplitMeals_CreditCardCount_6 = new Random().Next(0, 100),
- SplitMeals_CreditCardNameBefore_6 = name_XM[new Random().Next(0, 5)],
- SplitMeals_CreditCardName_6 = name_XM[new Random().Next(0, 5)],
- SplitMeals_CookType_6 = new List<string>() { "回锅肉", "烂肉豇豆", "火爆腰花" },
-
- };
- }
-
- string message = JsonConvert.SerializeObject(sendScreenData);
- mqttHelper.Publish(ScreenTOPIC.GetInstance.GetTopic(screen), message);
-
- System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() =>
- {
-
- if (textwb.Text.Length > 100000)
- {
- textwb.Text = "";
- }
- string text = $"{ScreenTOPIC.GetInstance.GetTopic(screen)} {message}\n";
- textwb.Text += text;
- }));
-
- }
-
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- int i = 0;
- Window1 window1 = new Window1();
- foreach (System.Windows.Forms.Screen scr in System.Windows.Forms.Screen.AllScreens)
- {
- //if (!scr.Primary)
- {
- if (i == 1)
- {
- window1.WindowStartupLocation = WindowStartupLocation.Manual;
-
- window1.Left = scr.WorkingArea.Left;
- window1.Top = scr.WorkingArea.Top;
- window1.Width = scr.Bounds.Width;
- window1.Height = scr.Bounds.Height;
- window1.WindowState = WindowState.Maximized;
- window1.ResizeMode = ResizeMode.NoResize;
- window1.WindowStyle = WindowStyle.None;
- window1.WindowState = WindowState.Normal;
- window1.ShowInTaskbar = false;
- window1.Show();
- }
- else if (i == 2)
- {
- }
- i++;
- }
- }
-
- }
- }
- }
|