@@ -145,7 +145,8 @@ namespace BPASmartClient.MorkCL | |||
#endregion | |||
//这里判定主要是针对压力锅。 | |||
if (!TaskList.ContainsKey(morkCL.cds.ElementAt(0).DeviceType)) | |||
//修改为炒锅和机器人不允许下单情况下,就不下单。 | |||
if (!TaskList.ContainsKey(morkCL.cds.ElementAt(0).DeviceType)&&GetFryPanAndRobotIsAuto(morkCL.cds.ElementAt(0).DeviceType)) | |||
{ | |||
if (morkCL.cds.TryDequeue(out ControlData cd)) | |||
{ | |||
@@ -575,9 +576,25 @@ namespace BPASmartClient.MorkCL | |||
} | |||
break; | |||
case EFunc.添加辅料: | |||
MaterialBase mb = SqliteHelper.GetInstance.GetAccessories().FirstOrDefault(p => p.Id == fm.funcPars.ElementAt(0).Id); | |||
#region 根据配置文件选择每个炒锅的最大最小辅料位置,暂时没使用。 | |||
//var minloc = -1; | |||
//var maxloc = -1; | |||
//if (et == EDeviceType.炒锅1) | |||
//{ | |||
// minloc = Json<ConnectPar>.Data.FryPanAccessoriesMin_1; | |||
// maxloc = Json<ConnectPar>.Data.FryPanAccessoriesMax_1; | |||
//} | |||
//else if (et == EDeviceType.炒锅2) | |||
//{ | |||
// minloc = Json<ConnectPar>.Data.FryPanAccessoriesMin_2; | |||
// maxloc = Json<ConnectPar>.Data.FryPanAccessoriesMax_2; | |||
//} | |||
#endregion | |||
MaterialBase mb = SqliteHelper.GetInstance.GetAccessories().FirstOrDefault(p =>/*p.Loc>=minloc && p.Loc<=maxloc&& */p.Id == fm.funcPars.ElementAt(0).Id); | |||
if (mb != null) | |||
{ | |||
robot.IsIdle.Wait(Cts: TaskList[et].Cts); | |||
//先复位变量。防止上一次是异常结束,设为True时,不会响应。 | |||
device.FryingPanHome = false; | |||
@@ -882,7 +899,14 @@ namespace BPASmartClient.MorkCL | |||
public override void Stop() | |||
{ | |||
} | |||
private bool GetFryPanAndRobotIsAuto(EDeviceType fryPan) | |||
{ | |||
//目前拿不到机器人的远程状态,只能拿到炒锅的。 | |||
var device = (FryingPanServer)devices[fryPan]; | |||
var robot = (RobotServer)devices[EDeviceType.机器人]; | |||
return device.InitComplete && device.StatusMode && device.EStop && robot.RemoteMode; | |||
} | |||
void ManualActionRegiester() | |||
{ | |||
//主料入库委托。 | |||
@@ -908,6 +932,17 @@ namespace BPASmartClient.MorkCL | |||
var index = Array.FindIndex(Json<ItemStorageInfo>.Data.IngredientsStorage, i => i.IsEmploy == false); | |||
if (index >= 0) | |||
{ | |||
if (!MessageNotify.GetInstance.ShowDialog($"请确认库位【{index+1}】上无物品,否则可能会造成碰撞事故!",DialogType.Warning)) | |||
{ | |||
DeviceProcessLogShow($"物料[{ingredients.Name}],ID:[{ingredients.Id}],库位[{index+1}]入库失败,未确认库位无异物。"); | |||
Application.Current.Dispatcher.Invoke(() => | |||
{ | |||
NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "入库失败", $"物料{ingredients.Name}入库失败。"); | |||
}); | |||
return; | |||
} | |||
var item = Json<ItemStorageInfo>.Data.IngredientsStorage[index]; | |||
item.MaterialID = ingredients.Id; | |||
@@ -926,7 +961,7 @@ namespace BPASmartClient.MorkCL | |||
ActionManage.GetInstance.Send("RefreshItemStorage"); | |||
DeviceProcessLogShow($"物料[{ingredients.Name}],ID:[{ingredients.Id}]入库成功。"); | |||
DeviceProcessLogShow($"物料[{ingredients.Name}],ID:[{ingredients.Id}],库位[{index + 1}]入库成功。"); | |||
Application.Current.Dispatcher.Invoke(() => | |||
{ | |||
NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "入库成功", $"物料{ingredients.Name}入库成功。"); | |||
@@ -961,7 +996,7 @@ namespace BPASmartClient.MorkCL | |||
{ | |||
var robot = (RobotServer)devices[EDeviceType.机器人]; | |||
//Thread.Sleep(5000); | |||
robot.WarehousingControl(loc); | |||
robot.WarehousingControl(loc,null); | |||
//会卡死。 | |||
robot.WarehousingComplete[(Convert.ToInt32(loc) - 1)].Wait(); | |||
} | |||
@@ -1010,12 +1045,41 @@ namespace BPASmartClient.MorkCL | |||
ActionManage.GetInstance.Register(() => | |||
{ | |||
//电子秤去皮 | |||
var weghier = (OtherServer)devices[EDeviceType.外部设备]; | |||
if (weghier.WeigherTare()) | |||
{ | |||
NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "去皮成功", $"电子秤除皮操作成功。"); | |||
DeviceProcessLogShow($"电子秤除皮操作成功。"); | |||
} | |||
else | |||
{ | |||
NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "去皮失败", $"电子秤除皮操作失败。"); | |||
DeviceProcessLogShow($"电子秤除皮操作失败。"); | |||
} | |||
},"WeighrTare",true); | |||
ActionManage.GetInstance.Register(() => | |||
{ | |||
//电子秤置零 | |||
var weghier = (OtherServer)devices[EDeviceType.外部设备]; | |||
if (weghier.WeigherZero()) | |||
{ | |||
Application.Current.Dispatcher.Invoke(() => | |||
{ | |||
NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "置零成功", $"电子秤置零操作成功。"); | |||
}); | |||
DeviceProcessLogShow($"电子秤置零操作成功。"); | |||
} | |||
else | |||
{ | |||
Application.Current.Dispatcher.Invoke(() => | |||
{ | |||
NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "置零失败", $"电子秤置零操作失败。"); | |||
}); | |||
DeviceProcessLogShow($"电子秤置零操作失败。"); | |||
} | |||
}, "WeighrZero", true); | |||
@@ -1059,6 +1123,20 @@ namespace BPASmartClient.MorkCL | |||
ActionManage.GetInstance.Register(frypanIsIdle, "GetDeviceIsIdle", true); | |||
ActionManage.GetInstance.Register(() => | |||
{ | |||
var robot = (RobotServer)devices[EDeviceType.机器人]; | |||
if (robot.InitVariable()) | |||
{ | |||
Application.Current.Dispatcher.Invoke(() => { NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "成功", $"复位所有由上位机下发至机器人的变量成功。"); }); | |||
DeviceProcessLogShow($"复位所有由上位机下发至机器人的变量成功。"); | |||
} | |||
else | |||
{ | |||
Application.Current.Dispatcher.Invoke(() => { NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "失败", $"复位所有由上位机下发至机器人的变量失败。"); }); | |||
DeviceProcessLogShow($"复位所有由上位机下发至机器人的变量失败。"); | |||
} | |||
}, "InitRobotAllVar", true); | |||
} | |||
Func<object, object> frypanIsIdle => (o) => | |||
@@ -359,7 +359,7 @@ namespace BPASmartClient.MorkCL | |||
/// <summary> | |||
/// 机器人远程模式 | |||
/// </summary> | |||
[VariableMonitor("机器人-机器人远程模式", "LW22")] | |||
[VariableMonitor("机器人-机器人远程模式,为True时,代表可下单", "GM130")] | |||
public bool RemoteMode { get; set; } | |||
/// <summary> | |||
@@ -42,7 +42,7 @@ namespace BPASmartClient.MorkCL.Model.Control | |||
public bool EnableState { get; set; } | |||
/// <summary> | |||
/// 机器人远程模式 | |||
/// 机器人远程模式,为True时,可下单。 | |||
/// </summary> | |||
public bool RemoteMode { get; set; } | |||
@@ -61,5 +61,21 @@ namespace BPASmartClient.MorkCL.Model.Json | |||
/// 外设端口号 | |||
/// </summary> | |||
public string PPortName { get; set; } = "COM2"; | |||
/// <summary> | |||
/// 炒锅1辅料最小位置。 | |||
/// </summary> | |||
public int FryPanAccessoriesMin_1 { get; set; } = 1; | |||
/// <summary> | |||
/// 炒锅1辅料最大位置。 | |||
/// </summary> | |||
public int FryPanAccessoriesMax_1 { get; set; } = 4; | |||
/// <summary> | |||
/// 炒锅2辅料最小位置。 | |||
/// </summary> | |||
public int FryPanAccessoriesMin_2 { get; set; } = 5; | |||
/// <summary> | |||
/// 炒锅2辅料最大位置。 | |||
/// </summary> | |||
public int FryPanAccessoriesMax_2 { get; set; } = 8; | |||
} | |||
} |
@@ -52,5 +52,35 @@ namespace BPASmartClient.MorkCL.Server | |||
{ | |||
throw new NotImplementedException(); | |||
} | |||
/// <summary> | |||
/// 除皮 | |||
/// </summary> | |||
/// <returns></returns> | |||
public bool WeigherTare() | |||
{ | |||
if (MyModbus is not null && MyModbus.IsConnected()) | |||
{ | |||
ModbusRtu weigher = (ModbusRtu)MyModbus; | |||
weigher.SlaveAddress = 2; | |||
return weigher.Write<bool>("LB4", false).IsSuccess; | |||
} | |||
else | |||
return false; | |||
} | |||
/// <summary> | |||
/// 置零 | |||
/// </summary> | |||
/// <returns></returns> | |||
public bool WeigherZero() | |||
{ | |||
if (MyModbus is not null && MyModbus.IsConnected()) | |||
{ | |||
ModbusRtu weigher = (ModbusRtu)MyModbus; | |||
weigher.SlaveAddress = 2; | |||
return weigher.Write<bool>("LB3", false).IsSuccess; | |||
} | |||
else | |||
return false; | |||
} | |||
} | |||
} |
@@ -32,17 +32,24 @@ namespace BPASmartClient.MorkCL.Server | |||
} | |||
}); | |||
Thread.Sleep(20); | |||
MyModbus.Read<bool>("GM620".ToModbusAdd()).OnSuccess((b)=> { Home = b; }); | |||
Thread.Sleep(20); | |||
MyModbus.Read<bool[]>("GM630".ToModbusAdd(), 12).OnSuccess(s => | |||
{ | |||
for (byte i = 0; i < s.Length; i++) WarehousingComplete[i] = s[i]; | |||
}); | |||
Thread.Sleep(20); | |||
MyModbus.Read<ushort>("GI5".ToModbusAdd(), 1).OnSuccess(s => { TaskFeedback = (RobotMainTask)s; }); | |||
IsIdle = (TaskFeedback == RobotMainTask.无任务 && Home); | |||
Thread.Sleep(20); | |||
MyModbus.Read<bool>("GM130".ToModbusAdd(), 1).OnSuccess((b) => { RemoteMode = b; }); | |||
Thread.Sleep(20); | |||
}), $"机器人服务-{IP}", true); | |||
}); | |||
} | |||
@@ -86,5 +93,30 @@ namespace BPASmartClient.MorkCL.Server | |||
Thread.Sleep(1000); | |||
} | |||
} | |||
public bool InitVariable() | |||
{ | |||
if (MyModbus is not null && MyModbus.IsConnected()) | |||
{ | |||
try | |||
{ | |||
MyModbus.Write<ushort>("GI0".ToModbusAdd(), 0); | |||
MyModbus.Write<ushort>("GI1".ToModbusAdd(), 0); | |||
for (int i = 0; i <= 8; i++) | |||
{ | |||
MyModbus.Write<bool>(("GM" + (500 + i).ToString()).ToModbusAdd(), false); | |||
} | |||
return true; | |||
} | |||
catch (Exception) | |||
{ | |||
return false; | |||
} | |||
} | |||
else | |||
return false; | |||
} | |||
} | |||
} |
@@ -55,11 +55,11 @@ | |||
Margin="10,0" | |||
Command="{Binding InitalDeviceCommand}" | |||
Content="初始化设备" /> | |||
<Button | |||
<!--<Button | |||
Width="100" | |||
Margin="10,0" | |||
Command="{Binding ResetDeviceCommand}" | |||
Content="复位" /> | |||
Content="复位" />--> | |||
<Button | |||
Width="100" | |||
Margin="10,0" | |||
@@ -179,7 +179,15 @@ | |||
<StackPanel | |||
Grid.Row="1" | |||
Margin="15" | |||
Orientation="Vertical" /> | |||
Orientation="Vertical"> | |||
<Button | |||
Width="200" | |||
Height="50" | |||
Margin="5" | |||
HorizontalAlignment="Left" | |||
Command="{Binding InitRobotVarCommand}" | |||
Content="复位机器人所有变量" /> | |||
</StackPanel> | |||
<!--#endregion--> | |||
<!--#region 系统任务控制--> | |||
@@ -206,7 +214,7 @@ | |||
</StackPanel> | |||
<StackPanel Orientation="Horizontal"> | |||
<!--<StackPanel Orientation="Horizontal"> | |||
<Button | |||
Width="150" | |||
Height="35" | |||
@@ -222,7 +230,7 @@ | |||
Content="清空2#炒锅任务" | |||
Visibility="Collapsed" /> | |||
</StackPanel> | |||
</StackPanel>--> | |||
</StackPanel> | |||
<!--#endregion--> | |||
@@ -62,7 +62,14 @@ | |||
Command="{Binding InStorageCommand}" | |||
CommandParameter="{Binding ElementName=cmbSelectName, Path=SelectedItem}" | |||
Content="入库" /> | |||
<Button | |||
Margin="0,30,0,10" | |||
Command="{Binding WeigherTareCommand}" | |||
Content="电子秤除皮" /> | |||
<Button | |||
Margin="0,10" | |||
Command="{Binding WeigherZeroCommand}" | |||
Content="电子秤置零" /> | |||
</StackPanel> | |||
<!--#endregion--> | |||
<!--#region 辅料仓不需要显示,整体注释。--> | |||
@@ -132,17 +139,18 @@ | |||
<pry:ImageBorder | |||
Grid.Row="0" | |||
Grid.RowSpan="2" | |||
Grid.Column="1" | |||
Margin="15" /> | |||
<ItemsControl | |||
Grid.Column="1" /> | |||
<ListView | |||
Grid.Row="0" | |||
Grid.RowSpan="2" | |||
Grid.Column="1" | |||
Margin="3" | |||
Background="Transparent" | |||
ItemsSource="{Binding IngredientsItorage}" | |||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"> | |||
<ItemsControl.ItemsPanel> | |||
ScrollViewer.HorizontalScrollBarVisibility="Disabled" | |||
ScrollViewer.VerticalScrollBarVisibility="Disabled" | |||
SelectionMode="Single"> | |||
<ListView.ItemsPanel> | |||
<ItemsPanelTemplate> | |||
<UniformGrid | |||
HorizontalAlignment="Center" | |||
@@ -157,9 +165,9 @@ | |||
</UniformGrid.LayoutTransform> | |||
</UniformGrid> | |||
</ItemsPanelTemplate> | |||
</ItemsControl.ItemsPanel> | |||
</ListView.ItemsPanel> | |||
<ItemsControl.ItemTemplate> | |||
<ListView.ItemTemplate> | |||
<DataTemplate> | |||
<Border Margin="5" Background="Transparent"> | |||
<Grid> | |||
@@ -207,8 +215,8 @@ | |||
</Grid> | |||
</Border> | |||
</DataTemplate> | |||
</ItemsControl.ItemTemplate> | |||
</ItemsControl> | |||
</ListView.ItemTemplate> | |||
</ListView> | |||
<!--#endregion--> | |||
</Grid> |
@@ -0,0 +1,37 @@ | |||
<Window | |||
x:Class="BPASmartClient.MorkCL.View.ManualSetItemStorageView" | |||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |||
xmlns:Behavior="http://schemas.microsoft.com/xaml/behaviors" | |||
xmlns:converter="clr-namespace:BPASmartClient.MorkCL.Converter" | |||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |||
xmlns:vm="clr-namespace:BPASmartClient.MorkCL.ViewModel" | |||
Title="EditFunctionView" | |||
Width="450" | |||
Height="350" | |||
AllowsTransparency="True" | |||
Background="{x:Null}" | |||
Topmost="True" | |||
WindowStartupLocation="CenterScreen" | |||
WindowStyle="None" | |||
mc:Ignorable="d"> | |||
<Window.DataContext> | |||
<vm:ManualSetItemStorageViewModel/> | |||
</Window.DataContext> | |||
<Window.Resources> | |||
<ResourceDictionary> | |||
<ResourceDictionary.MergedDictionaries> | |||
<ResourceDictionary Source="/BPASmartClient.MorkCL;component/CustomStyle/CustomStyle.xaml" /> | |||
</ResourceDictionary.MergedDictionaries> | |||
</ResourceDictionary> | |||
</Window.Resources> | |||
<Border | |||
Name="br" | |||
BorderBrush="#0CADF5" | |||
BorderThickness="0"> | |||
<Border.Background> | |||
<ImageBrush ImageSource="/BPASmartClient.CustomResource;component/Image/弹框/biankuang_.png" /> | |||
</Border.Background> | |||
</Border> | |||
</Window> |
@@ -0,0 +1,29 @@ | |||
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.Shapes; | |||
namespace BPASmartClient.MorkCL.View | |||
{ | |||
/// <summary> | |||
/// ManualSetItemStorageView.xaml 的交互逻辑 | |||
/// </summary> | |||
public partial class ManualSetItemStorageView : Window | |||
{ | |||
public ManualSetItemStorageView() | |||
{ | |||
InitializeComponent(); | |||
this.br.MouseLeftButtonDown += (o, e) => { if (e.LeftButton == MouseButtonState.Pressed) this.DragMove(); }; | |||
} | |||
} | |||
} |
@@ -170,6 +170,8 @@ namespace BPASmartClient.MorkCL.ViewModel | |||
{ | |||
return; | |||
} | |||
//复位所有变量。 | |||
ResetFryPanVariable(FryingPanSelect); | |||
await SendWriteRequest("LB21"); | |||
ShowNotify($"设置设备初始化成功。"); | |||
}); | |||
@@ -183,13 +185,14 @@ namespace BPASmartClient.MorkCL.ViewModel | |||
await SendWriteRequest("LB22"); | |||
ShowNotify($"设置设备停止成功。"); | |||
}); | |||
//炒锅那边复位变量没有使用。 | |||
ResetDeviceCommand = new(async () => | |||
{ | |||
if (!GetDeviceIsIdle(FryingPanSelect)) | |||
{ | |||
return; | |||
} | |||
await SendWriteRequest("LB23"); | |||
ShowNotify($"设置设备复位成功。"); | |||
}); | |||
@@ -208,6 +211,14 @@ namespace BPASmartClient.MorkCL.ViewModel | |||
ClearFryPanTaskCommand_2 = new(() => | |||
{ | |||
}); | |||
InitRobotVarCommand = new(() => | |||
{ | |||
Task.Run(() => | |||
{ | |||
ActionManage.GetInstance.Send("InitRobotAllVar"); | |||
}); | |||
}); | |||
} | |||
#region 私有方法 | |||
@@ -241,7 +252,23 @@ namespace BPASmartClient.MorkCL.ViewModel | |||
} | |||
return false; | |||
} | |||
/// <summary> | |||
/// 复位指定炒锅的所有变量。 | |||
/// </summary> | |||
/// <param name="deviceType"></param> | |||
private void ResetFryPanVariable(EDeviceType deviceType) | |||
{ | |||
ActionManage.GetInstance.Send("WriteBool", new WriteModel<bool>(deviceType, "LB0", false)); | |||
ActionManage.GetInstance.Send("WriteBool", new WriteModel<bool>(deviceType, "LB3", false)); | |||
for (int i = 6; i <= 19; i++) | |||
{ | |||
ActionManage.GetInstance.Send("WriteBool", new WriteModel<bool>(deviceType, "LB" + i, false)); | |||
} | |||
for (int i = 0; i <= 5; i++) | |||
{ | |||
ActionManage.GetInstance.Send("WriteUshort", new WriteModel<ushort>(deviceType, "LW" + i, 0)); | |||
} | |||
} | |||
#endregion 私有方法 | |||
#region 属性 | |||
@@ -385,6 +412,10 @@ namespace BPASmartClient.MorkCL.ViewModel | |||
/// 清空2#炒锅所有任务。 | |||
/// </summary> | |||
public BPARelayCommand ClearFryPanTaskCommand_2 { get; set; } | |||
/// <summary> | |||
/// 复位机器人所有由上位机下发的变量。 | |||
/// </summary> | |||
public BPARelayCommand InitRobotVarCommand { get; set; } | |||
#endregion 命令 | |||
} |
@@ -113,6 +113,14 @@ namespace BPASmartClient.MorkCL.ViewModel | |||
NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "成功", "清空仓位信息成功。"); | |||
} | |||
}); | |||
WeigherTareCommand = new(() => | |||
{ | |||
ActionManage.GetInstance.Send("WeighrTare"); | |||
}); | |||
WeigherZeroCommand = new(() => | |||
{ | |||
ActionManage.GetInstance.Send("WeighrZero"); | |||
}); | |||
} | |||
private void AddTestData() | |||
@@ -132,6 +140,18 @@ namespace BPASmartClient.MorkCL.ViewModel | |||
} | |||
public BPARelayCommand<object> InStorageCommand { get; set; } | |||
/// <summary> | |||
/// 初始化库位。 | |||
/// </summary> | |||
public BPARelayCommand InitialStorageCommand { get; set; } | |||
/// <summary> | |||
/// 电子秤除皮。 | |||
/// </summary> | |||
public BPARelayCommand WeigherTareCommand { get; set; } | |||
/// <summary> | |||
/// 电子秤置零。 | |||
/// </summary> | |||
public BPARelayCommand WeigherZeroCommand { get; set; } | |||
private float _ScaleCurrentWeight; | |||
@@ -181,9 +201,5 @@ namespace BPASmartClient.MorkCL.ViewModel | |||
get { return _CanItemStorage; } | |||
set { _CanItemStorage = value; OnPropertyChanged(); } | |||
} | |||
/// <summary> | |||
/// 初始化库位。 | |||
/// </summary> | |||
public BPARelayCommand InitialStorageCommand { get; set; } | |||
} | |||
} |
@@ -0,0 +1,13 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPASmartClient.MorkCL.ViewModel | |||
{ | |||
public class ManualSetItemStorageViewModel:NotifyBase | |||
{ | |||
} | |||
} |