Browse Source

配料系统调试

JXJAgvReake
pry 1 year ago
parent
commit
3fe73c2ca0
16 changed files with 363 additions and 196 deletions
  1. +1
    -1
      BPASmartClient.CustomResource/BPASmartClient.CustomResource.csproj
  2. +1
    -1
      BPASmartClient.CustomResource/Pages/Model/AlarmHelper.cs
  3. +1
    -1
      BPASmartClient.JakaRobot/BPASmartClient.JakaRobot.csproj
  4. +1
    -1
      BPASmartClient.Modbus/BPASmartClient.Modbus.csproj
  5. +1
    -1
      BPASmartClient.Model/BPASmartClient.Model.csproj
  6. +1
    -1
      BPASmartClient.Nfc/BPASmartClient.Nfc.csproj
  7. +1
    -1
      BPASmartClient.S7Net/BPASmartClient.S7Net.csproj
  8. +1
    -1
      BPASmartClient.Update/BPASmartClient.Update.csproj
  9. +1
    -3
      DosingSystem/BPASmartClient.DosingSystem.csproj
  10. +67
    -54
      DosingSystem/Model/DeviceInquire.cs
  11. +146
    -0
      DosingSystem/Model/Expand.cs
  12. +19
    -29
      DosingSystem/Service/SiemensDevice.cs
  13. +7
    -7
      DosingSystem/ViewModel/ManualControlViewModel.cs
  14. +107
    -89
      DosingSystem/ViewModel/RecipeControlViewModel.cs
  15. +7
    -5
      DosingSystem/ViewModel/TempManageControlViewModel.cs
  16. +1
    -1
      WpfTest/WpfTest.csproj

+ 1
- 1
BPASmartClient.CustomResource/BPASmartClient.CustomResource.csproj View File

@@ -463,7 +463,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="BPA.Helper" Version="1.0.74" />
<PackageReference Include="BPA.Helper" Version="1.0.75" />
<PackageReference Include="BPA.Message" Version="1.0.86" />
<PackageReference Include="MahApps.Metro.IconPacks.FontAwesome" Version="4.11.0" />
</ItemGroup>


+ 1
- 1
BPASmartClient.CustomResource/Pages/Model/AlarmHelper.cs View File

@@ -108,7 +108,7 @@ namespace BPASmartClient.CustomResource.Pages.Model
};

var res = Sqlite<BPASmartClient.Model.Alarm>.GetInstance.Base.Add(tempAlarm);
//Sqlite<BPASmartClient.Model.Alarm>.GetInstance.Save();
Sqlite<BPASmartClient.Model.Alarm>.GetInstance.Save();

if (Alarms.FirstOrDefault(p => p.Info == AlarmInfo) == null)
{


+ 1
- 1
BPASmartClient.JakaRobot/BPASmartClient.JakaRobot.csproj View File

@@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BPA.Helper" Version="1.0.74" />
<PackageReference Include="BPA.Helper" Version="1.0.75" />
</ItemGroup>

</Project>

+ 1
- 1
BPASmartClient.Modbus/BPASmartClient.Modbus.csproj View File

@@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BPA.Helper" Version="1.0.74" />
<PackageReference Include="BPA.Helper" Version="1.0.75" />
<PackageReference Include="NModbus" Version="3.0.72" />
<PackageReference Include="System.IO.Ports" Version="6.0.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="6.0.0" />


+ 1
- 1
BPASmartClient.Model/BPASmartClient.Model.csproj View File

@@ -16,7 +16,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="BPA.Helper" Version="1.0.74" />
<PackageReference Include="BPA.Helper" Version="1.0.75" />
<PackageReference Include="BPA.Message" Version="1.0.86" />
<PackageReference Include="log4net" Version="2.0.15" />
</ItemGroup>


+ 1
- 1
BPASmartClient.Nfc/BPASmartClient.Nfc.csproj View File

@@ -21,7 +21,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="BPA.Helper" Version="1.0.74" />
<PackageReference Include="BPA.Helper" Version="1.0.75" />
</ItemGroup>

</Project>

+ 1
- 1
BPASmartClient.S7Net/BPASmartClient.S7Net.csproj View File

@@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BPA.Helper" Version="1.0.74" />
<PackageReference Include="BPA.Helper" Version="1.0.75" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="S7netplus" Version="0.14.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="6.0.0" />


+ 1
- 1
BPASmartClient.Update/BPASmartClient.Update.csproj View File

@@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BPA.Helper" Version="1.0.74" />
<PackageReference Include="BPA.Helper" Version="1.0.75" />
</ItemGroup>

</Project>

+ 1
- 3
DosingSystem/BPASmartClient.DosingSystem.csproj View File

@@ -21,15 +21,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="BPA.Helper" Version="1.0.75" />
<PackageReference Include="BPA.Communication" Version="1.0.113" />
<PackageReference Include="BPA.Message" Version="1.0.86" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BPASmartClient.CustomResource\BPASmartClient.CustomResource.csproj" />
<ProjectReference Include="..\BPASmartClient.Modbus\BPASmartClient.Modbus.csproj" />
<ProjectReference Include="..\BPASmartClient.S7Net\BPASmartClient.S7Net.csproj" />
<ProjectReference Include="..\BPASmartClient.Update\BPASmartClient.Update.csproj" />
</ItemGroup>



+ 67
- 54
DosingSystem/Model/DeviceInquire.cs View File

@@ -1,6 +1,6 @@
using BPASmartClient.CustomResource.Pages.Model;
using BPASmartClient.DosingSystem.ViewModel;
using BPASmartClient.Modbus;
//using BPASmartClient.Modbus;
using BPASmartClient.Model;
using System;
using System.Collections.Concurrent;
@@ -12,6 +12,8 @@ using System.Threading;
using System.Threading.Tasks;
using BPA.Helper;
using System.Text.RegularExpressions;
using BPA.Communication;
using BPASmartClient.DosingSystem.Model;

namespace BPASmartClient.DosingSystem
{
@@ -197,7 +199,7 @@ namespace BPASmartClient.DosingSystem
}
}
}*/
for (int i = 0; i < 15; i++)
for (int i = 0; i < 6; i++)
{
IPLists.Add($"{IPSegment}{(i + 1) * 10}");
}
@@ -221,9 +223,10 @@ namespace BPASmartClient.DosingSystem
DeviceStatus DS = new DeviceStatus();
DS.modbusTcp.IsReconnect = false;

DS.modbusTcp.ConnectOk = new Action(() =>
DS.modbusTcp.Connected = new Action(() =>
{
string DeviceName = DS.modbusTcp.GetString(DeviceAddress.DeviceName, 20).Trim()?.Replace(" ", "");//读取设备名称
var tt = DS.modbusTcp.Read<string>(DeviceAddress.DeviceName.ToAdd(), 20);
string DeviceName = DS.modbusTcp.Read<string>(DeviceAddress.DeviceName.ToAdd(), 20).Content?.Trim()?.Replace(" ", "");//读取设备名称
if (DeviceName.Length > 0)
{
DeviceLists.TryAdd(ip, DS);
@@ -303,7 +306,7 @@ namespace BPASmartClient.DosingSystem

Task.Run(new Action(() =>
{
DS.modbusTcp.ModbusTcpConnect(ip, 502);//PLC连接
DS.modbusTcp.Connect(new BPA.Communication.Base.ConfigurationOptions() { IpAddress = ip, Port = 502 });//PLC连接
IPQueues.Enqueue(e.Reply.Address.ToString());
}));
}
@@ -322,7 +325,7 @@ namespace BPASmartClient.DosingSystem

#region 对象属性声明
public string DeviceName = String.Empty;
public string IpAddress => modbusTcp.IPAdress;
public string IpAddress => modbusTcp.GetConfigPar().IpAddress;

/// <summary>
/// 设备状态
@@ -331,25 +334,25 @@ namespace BPASmartClient.DosingSystem

public ModbusTcp modbusTcp = new ModbusTcp();

public bool IsConnected => modbusTcp.Connected;
public bool IsConnected => modbusTcp.IsConnected();
#endregion

public void Init(string DeviceName)
{
modbusTcp.Show = new Action<string>((s) => { MessageNotify.GetInstance.ShowRunLog(s); });
modbusTcp.ShowEx = new Action<string>((s) => { MessageNotify.GetInstance.ShowRunLog(s); });
//modbusTcp.Show = new Action<string>((s) => { MessageNotify.GetInstance.ShowRunLog(s); });
//modbusTcp.ShowEx = new Action<string>((s) => { MessageNotify.GetInstance.ShowRunLog(s); });
this.DeviceName = DeviceName;
AlarmHelper<AlarmInfo>.Init();
if (modbusTcp.Connected)
if (IsConnected)
{
TaskManage.GetInstance.StartLong(new Action(() =>
{
this.DeviceName = modbusTcp.GetString(DeviceAddress.DeviceName, 20)?.Trim()?.Replace(" ", "");
deviceStatus.RunStatus = (ushort)this.modbusTcp.ReadShort(DeviceAddress.RunStatus); //获取设备运行状态
deviceStatus.WeightFeedback = (float)this.modbusTcp.GetUint(DeviceAddress.WeightFeedback);//获取设备料仓剩余重量
deviceStatus.NowWeightFeedback = this.modbusTcp.GetReal(DeviceAddress.CutWeightFeedback);//获取下料重量
deviceStatus.DeviceNum = (ushort)this.modbusTcp.ReadShort(DeviceAddress.DeviceNum);//获取设备编号
deviceStatus.DeviceAlarmCode = (ushort)this.modbusTcp.ReadShort(DeviceAddress.DeviceAlarmCode);//获取设备故障编码
this.DeviceName = modbusTcp.Read<string>(DeviceAddress.DeviceName.ToAdd(), 20).Content.Trim().Replace(" ", "");
deviceStatus.RunStatus = (ushort)this.modbusTcp.Read<ushort>(DeviceAddress.RunStatus.ToAdd()).Content; //获取设备运行状态
deviceStatus.WeightFeedback = (float)this.modbusTcp.Read<uint>(DeviceAddress.WeightFeedback.ToAdd()).Content;//获取设备料仓剩余重量
deviceStatus.NowWeightFeedback = this.modbusTcp.Read<float>(DeviceAddress.CutWeightFeedback.ToAdd()).Content;//获取下料重量
deviceStatus.DeviceNum = (ushort)this.modbusTcp.Read<ushort>(DeviceAddress.DeviceNum.ToAdd()).Content;//获取设备编号
deviceStatus.DeviceAlarmCode = (ushort)this.modbusTcp.Read<ushort>(DeviceAddress.DeviceAlarmCode.ToAdd()).Content;//获取设备故障编码

AlarmHelper<AlarmInfo>.GetInstance(DeviceName).EStop1 = deviceStatus.DeviceAlarmCode.GetBitValue(1);
AlarmHelper<AlarmInfo>.GetInstance(DeviceName).Servo = deviceStatus.DeviceAlarmCode.GetBitValue(2);
@@ -364,13 +367,13 @@ namespace BPASmartClient.DosingSystem

public void SetDeviceName(string name)
{
this.modbusTcp.Write(DeviceAddress.DeviceName, new ushort[20]);
this.modbusTcp.SetString(DeviceAddress.DeviceName, name);
this.modbusTcp.Write(DeviceAddress.DeviceName.ToAdd(), new ushort[20]);
this.modbusTcp.Write(DeviceAddress.DeviceName.ToAdd(), name);
}

public void StatusReset()
{
this.modbusTcp.Write(DeviceAddress.FinfishStatus, (ushort)1);
this.modbusTcp.Write(DeviceAddress.FinfishStatus.ToAdd(), (ushort)1);
//var res = modbusTcp.Read(DeviceAddress.RunStatus);
}

@@ -381,43 +384,53 @@ namespace BPASmartClient.DosingSystem

public void Start(float Value)
{
if (modbusTcp.Connected)
if (modbusTcp.IsConnected())
{
var res = Json<DevicePar>.Data.deviceParModels.FirstOrDefault(p => p.MaterialName == DeviceName);
if (res != null)
{
prop1:
modbusTcp.SetReal(DeviceAddress.SlowlyAddWeight, res.SlowlyAddWeight);
var Value1 = (float)this.modbusTcp.GetReal(DeviceAddress.SlowlyAddWeight);
if (Value1 != null && Value1.ToString() != res.SlowlyAddWeight.ToString()) goto prop1;
prop2:
modbusTcp.SetReal(DeviceAddress.PreCloseValveWeight, res.PreCloseValveWeight);
var Value2 = (float)this.modbusTcp.GetReal(DeviceAddress.PreCloseValveWeight);
if (Value2 != null && Value2.ToString() != res.PreCloseValveWeight.ToString()) goto prop2;
prop3:
modbusTcp.SetUint(DeviceAddress.RapidAcceleration, (uint)res.RapidAcceleration);
var Value3 = this.modbusTcp.GetUint(DeviceAddress.RapidAcceleration);
if (Value3 != null && Value3.ToString() != res.RapidAcceleration.ToString()) goto prop3;
prop4:
modbusTcp.SetUint(DeviceAddress.SlowAcceleration, (uint)res.SlowAcceleration);
var Value4 = this.modbusTcp.GetUint(DeviceAddress.SlowAcceleration);
if (Value4 != null && Value4.ToString() != res.SlowAcceleration.ToString()) goto prop4;
prop5:
modbusTcp.SetUint(DeviceAddress.ServoManualSpeed, (uint)res.ServoManualSpeed);
var Value5 = this.modbusTcp.GetUint(DeviceAddress.ServoManualSpeed);
if (Value5 != null && Value5.ToString() != res.ServoManualSpeed.ToString()) goto prop5;
prop6:
modbusTcp.SetUint(DeviceAddress.SiloUpperLimitWeight, (uint)res.SiloUpperLimitWeight);
var Value6 = this.modbusTcp.GetUint(DeviceAddress.SiloUpperLimitWeight);
if (Value6 != null && Value6.ToString() != res.SiloUpperLimitWeight.ToString()) goto prop6;
prop7:
modbusTcp.SetUint(DeviceAddress.LowerLimitWeightOfSilo, (uint)res.LowerLimitWeightOfSilo);
var Value7 = this.modbusTcp.GetUint(DeviceAddress.LowerLimitWeightOfSilo);
if (Value7 != null && Value7.ToString() != res.LowerLimitWeightOfSilo.ToString()) goto prop7;
prop8:
modbusTcp.SetUint(DeviceAddress.StirringSpeed, (uint)res.StirringSpeed);
var Value8 = this.modbusTcp.GetUint(DeviceAddress.StirringSpeed);
if (Value8 != null && Value8.ToString() != res.StirringSpeed.ToString()) goto prop8;
//prop1:
//modbusTcp.SetReal(DeviceAddress.SlowlyAddWeight, res.SlowlyAddWeight);
//var Value1 = (float)this.modbusTcp.GetReal(DeviceAddress.SlowlyAddWeight);
//if (Value1 != null && Value1.ToString() != res.SlowlyAddWeight.ToString()) goto prop1;
//prop2:
//modbusTcp.SetReal(DeviceAddress.PreCloseValveWeight, res.PreCloseValveWeight);
//var Value2 = (float)this.modbusTcp.GetReal(DeviceAddress.PreCloseValveWeight);
//if (Value2 != null && Value2.ToString() != res.PreCloseValveWeight.ToString()) goto prop2;
//prop3:
//modbusTcp.SetUint(DeviceAddress.RapidAcceleration, (uint)res.RapidAcceleration);
//var Value3 = this.modbusTcp.GetUint(DeviceAddress.RapidAcceleration);
//if (Value3 != null && Value3.ToString() != res.RapidAcceleration.ToString()) goto prop3;
//prop4:
//modbusTcp.SetUint(DeviceAddress.SlowAcceleration, (uint)res.SlowAcceleration);
//var Value4 = this.modbusTcp.GetUint(DeviceAddress.SlowAcceleration);
//if (Value4 != null && Value4.ToString() != res.SlowAcceleration.ToString()) goto prop4;
//prop5:
//modbusTcp.SetUint(DeviceAddress.ServoManualSpeed, (uint)res.ServoManualSpeed);
//var Value5 = this.modbusTcp.GetUint(DeviceAddress.ServoManualSpeed);
//if (Value5 != null && Value5.ToString() != res.ServoManualSpeed.ToString()) goto prop5;
//prop6:
//modbusTcp.SetUint(DeviceAddress.SiloUpperLimitWeight, (uint)res.SiloUpperLimitWeight);
//var Value6 = this.modbusTcp.GetUint(DeviceAddress.SiloUpperLimitWeight);
//if (Value6 != null && Value6.ToString() != res.SiloUpperLimitWeight.ToString()) goto prop6;
//prop7:
//modbusTcp.SetUint(DeviceAddress.LowerLimitWeightOfSilo, (uint)res.LowerLimitWeightOfSilo);
//var Value7 = this.modbusTcp.GetUint(DeviceAddress.LowerLimitWeightOfSilo);
//if (Value7 != null && Value7.ToString() != res.LowerLimitWeightOfSilo.ToString()) goto prop7;
//prop8:
//modbusTcp.SetUint(DeviceAddress.StirringSpeed, (uint)res.StirringSpeed);
//var Value8 = this.modbusTcp.GetUint(DeviceAddress.StirringSpeed);
//if (Value8 != null && Value8.ToString() != res.StirringSpeed.ToString()) goto prop8;
//MessageNotify.GetInstance.ShowRunLog($"{res.MaterialName},配料参数下发完成");

modbusTcp.Write(DeviceAddress.SlowlyAddWeight.ToAdd(), res.SlowlyAddWeight);
modbusTcp.Write(DeviceAddress.PreCloseValveWeight.ToAdd(), res.PreCloseValveWeight);
modbusTcp.Write(DeviceAddress.RapidAcceleration.ToAdd(), (uint)res.RapidAcceleration);
modbusTcp.Write(DeviceAddress.SlowAcceleration.ToAdd(), (uint)res.SlowAcceleration);
modbusTcp.Write(DeviceAddress.ServoManualSpeed.ToAdd(), (uint)res.ServoManualSpeed);
modbusTcp.Write(DeviceAddress.SiloUpperLimitWeight.ToAdd(), (uint)res.SiloUpperLimitWeight);
modbusTcp.Write(DeviceAddress.LowerLimitWeightOfSilo.ToAdd(), (uint)res.LowerLimitWeightOfSilo);
modbusTcp.Write(DeviceAddress.StirringSpeed.ToAdd(), (uint)res.StirringSpeed);
MessageNotify.GetInstance.ShowRunLog($"{res.MaterialName},配料参数下发完成");
}
//prop9:
@@ -428,8 +441,8 @@ namespace BPASmartClient.DosingSystem
// modbusTcp.Write(DeviceAddress.Start, (ushort)1);//设备启动写入
// var Value10 = (short[])this.modbusTcp.Read(DeviceAddress.Start);
// if (Value10 != null && Value10[0] != 1) goto prop10;
modbusTcp.SetReal(DeviceAddress.WeightSet, Value);//写入配方重量
modbusTcp.Write(DeviceAddress.Start, (ushort)1);//设备启动写入
modbusTcp.Write(DeviceAddress.WeightSet.ToAdd(), Value);//写入配方重量
modbusTcp.Write(DeviceAddress.Start.ToAdd(), (ushort)1);//设备启动写入
MessageNotify.GetInstance.ShowRunLog($"{DeviceName},设置重量:{Value},味魔方启动配料");
}
}


+ 146
- 0
DosingSystem/Model/Expand.cs View File

@@ -0,0 +1,146 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmartClient.DosingSystem.Model
{
public static class Expand
{
/// <summary>
/// 获取 M 区 和 VW 区的Modbus的地址
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
public static string ToAdd(this string address)
{
if (address == null) return "";
if (address.Length > 0)
{
address = address.Trim();
if (address.ToUpper().Contains("GM") && address.Length >= 3)
{
var res = address.Remove(0, 2);
if (res != null && res.Length > 0)
{
return (int.Parse(res) + 4096).ToString();
}
}
else if (address.ToUpper().Contains("M") && address.Length >= 4)
{
var res = address.Substring(1).Split('.');
if (res != null && res.Length == 2)
{
if (int.TryParse(res[0], out int firstAddress) && int.TryParse(res[1], out int ExitAddress))
{
if (ExitAddress >= 0 && ExitAddress <= 7)
{
return ((firstAddress * 8) + 320 + ExitAddress).ToString();
}
}
}
}

else if (address.ToUpper().Contains("I") && address.Length >= 2)
{
var res = address.Substring(1).Split('.');
if (res != null && res.Length == 2)
{
if (int.TryParse(res[0], out int firstAddress) && int.TryParse(res[1], out int ExitAddress))
{
if (ExitAddress >= 0 && ExitAddress <= 7)
{
return ((firstAddress * 8) + ExitAddress).ToString();
}
}
}
}
else if (address.ToUpper().Contains("GI") && address.Length >= 3)
{
var res = address.Remove(0, 2);
if (res != null && res.Length > 0)
{
return (int.Parse(res)).ToString();
}
}
else if (address.ToUpper().Contains("LB") && address.Length >= 3)
{
var res = address.Substring(2);
if (res != null && res.Length > 0)
{
if (int.TryParse(res, out int firstAddress))
{
return firstAddress.ToString();
}
}
}

else if ((address.ToUpper().Contains("VW") || address.ToUpper().Contains("VD")) && address.Length >= 3)
{
var res = address.Substring(2);
if (res != null && int.TryParse(res, out int tempAddress))
{
return ((tempAddress / 2) + 100).ToString();
}
}
else if (address.ToUpper().Contains("LW") && address.Length >= 3)
{
var res = address.Substring(2);
if (res != null && int.TryParse(res, out int LwAddress))
{
return LwAddress.ToString();
}
}
else if (address.ToUpper().Contains("D") && address.Length == 5)
{
try
{
//D1001
string head = (Convert.ToInt32(address.Substring(1, 1))).ToString();
int num = Convert.ToInt32(address.Substring(2, 3));
int len = num.ToString().Length;
string tail = string.Empty;
switch (len)
{

case 1:
if ((Convert.ToInt32(address.Substring(4, 1))).ToString().Length > 1)
{
tail = "0" + (Convert.ToInt32(address.Substring(4, 1))).ToString();
}
else
{
tail = "00" + (Convert.ToInt32(address.Substring(4, 1))).ToString();
}
break;
case 2:
if ((Convert.ToInt32(address.Substring(3, 2))).ToString().Length > 2)
{
tail = (Convert.ToInt32(address.Substring(3, 2))).ToString();
}
else
{
tail = "0" + (Convert.ToInt32(address.Substring(3, 2))).ToString();
}
break;
case 3:
tail = (Convert.ToInt32(address.Substring(2, 3))).ToString();
break;
}

address = head + tail;
return address;
}
catch (Exception)
{
//打印日志

}

}
}
return "";
}
}
}

+ 19
- 29
DosingSystem/Service/SiemensDevice.cs View File

@@ -4,10 +4,10 @@ using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using BPASmartClient.S7Net;
using BPA.Helper;
using S7.Net;
using BPASmartClient.CustomResource.Pages.Model;
using BPA.Communication;

namespace BPASmartClient.DosingSystem
{
@@ -17,50 +17,40 @@ namespace BPASmartClient.DosingSystem
public static SiemensDevice GetInstance => _Instance ?? (_Instance = new SiemensDevice());
private SiemensDevice() { }

public SiemensHelper MySiemens { get; set; } = new SiemensHelper();
public Siemens MySiemens { get; set; } = new Siemens();

private bool IsConnect { get; set; }
public bool tempValue = false;
public void Connect(string ip)
{
TaskManage.GetInstance.StartLong(new Action(() =>
MySiemens.Connected = () =>
{
if (IsConnect)
TaskManage.GetInstance.StartLong(new Action(() =>
{
MySiemens.Write("DB4.DBX0.0", tempValue);//设备心跳
tempValue = !tempValue;
}
Thread.Sleep(200);
}), "设备心跳", true);
TaskManage.GetInstance.StartLong(new Action(() =>
{
try
{
while (!MySiemens.IsConnected)
if (IsConnect)
{
MySiemens.Connect(S7.Net.CpuType.S71200, ip);
Thread.Sleep(2000);
MySiemens.Write("DB4.DBX0.0", tempValue);//设备心跳
tempValue = !tempValue;
}
}
catch (Exception ex)
{
Thread.Sleep(200);
}), "设备心跳", true);

}
IsConnect = MySiemens.IsConnected;
if (IsConnect)
TaskManage.GetInstance.StartLong(new Action(() =>
{
GlobalDevice.PlcData = MySiemens.ReadClass<PlcToComputer>(3);//获取PLC到上位机的数据
var res = MySiemens.Read(DataType.DataBlock, 4, 134, VarType.Word, 32);
GlobalDevice.PlcData = MySiemens.Read<PlcToComputer>(3).Content;//获取PLC到上位机的数据
//var tt = MySiemens.Read<PlcToComputer>(3);//获取PLC到上位机的数据
var res = MySiemens.Read<ushort[]>("DB4.DBW134", 32).Content;
if (res != null && res is ushort[] ushorts && ushorts.Length == 32)
{
GlobalDevice.MotorSpeed = ushorts;
}
uint data = MySiemens.Read<uint>("DB5.DBD6");//获取输送带控制信号
//GlobalDevice.MotorControlFeedback = MySiemens.Read<uint>("DB3.DBD0");//获取当前输送带运行状态
uint data = MySiemens.Read<uint>("DB5.DBD6").Content;//获取输送带控制信号
//GlobalDevice.MotorControlFeedback = MySiemens.Read<uint>("DB3.DBD0");//获取当前输送带运行状态
GlobalDevice.MotorControl = (uint)(data.ToBytes(BPA.Helper.DataFormat.ABCD)).ToInt();
}
Thread.Sleep(50);
}), "读取输送线设备数据", true);
Thread.Sleep(50);
}), "读取输送线设备数据", true);
};
MySiemens.Connect(new BPA.Communication.Base.ConfigurationOptions() { IpAddress = "192.168.0.100", cpuType = BPA.Communication.CpuType.S71200, Port = 102 });
}

/// <summary>


+ 7
- 7
DosingSystem/ViewModel/ManualControlViewModel.cs View File

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
using BPA.Helper;
using System.Collections.ObjectModel;
using System.Threading;
using BPASmartClient.S7Net;
//using BPASmartClient.S7Net;

namespace BPASmartClient.DosingSystem.ViewModel
{
@@ -104,14 +104,14 @@ namespace BPASmartClient.DosingSystem.ViewModel
{
SiemensDevice.GetInstance.MySiemens.Write("M10.0", SystemControlText == "停止" ? false : true);
Thread.Sleep(100);
var res = SiemensDevice.GetInstance.MySiemens.Read<bool>("M10.0");
var res = SiemensDevice.GetInstance.MySiemens.Read<bool>("M10.0").Content;
SystemControlText = res ? "停止" : "启动";
});
ModelSwitch = new BPARelayCommand(() =>
{
SiemensDevice.GetInstance.MySiemens.Write("M10.1", ModelSwitchText == "手动" ? true : false);
Thread.Sleep(100);
var res = SiemensDevice.GetInstance.MySiemens.Read<bool>("M10.1");
var res = SiemensDevice.GetInstance.MySiemens.Read<bool>("M10.1").Content;
ModelSwitchText = res ? "自动" : "手动";
});

@@ -132,20 +132,20 @@ namespace BPASmartClient.DosingSystem.ViewModel
OtherHandCylinders.ElementAt(1).RightTog = GlobalDevice.PlcData.UnderCylinderDetection.HomeSignal;
OtherHandCylinders.ElementAt(1).LeftTog = GlobalDevice.PlcData.UnderCylinderDetection.InPlaceSignal;

SystemStatus = GlobalDevice.PlcData.SystemStartOrStop ? "启动" : "停止";
SystemStatus = GlobalDevice.PlcData.SystemStartOrStop ? "启动" : "停止";
SystemMode = GlobalDevice.PlcData.HandOrAuto ? "自动" : "手动";

Thread.Sleep(100);
}), "手动气缸状态监控",true);
}), "手动气缸状态监控", true);
}

private void Init()
{
var res = SiemensDevice.GetInstance.MySiemens.Read<bool>("M10.0");
var res = SiemensDevice.GetInstance.MySiemens.Read<bool>("M10.0").Content;
SystemControlText = res ? "停止" : "启动";
SystemStatus = res ? "停止" : "启动";

var res1 = SiemensDevice.GetInstance.MySiemens.Read<bool>("M10.1");
var res1 = SiemensDevice.GetInstance.MySiemens.Read<bool>("M10.1").Content;
ModelSwitchText = res1 ? "自动" : "手动";
SystemStatus = res ? "自动" : "手动";
}


+ 107
- 89
DosingSystem/ViewModel/RecipeControlViewModel.cs View File

@@ -145,10 +145,14 @@ namespace BPASmartClient.DosingSystem.ViewModel
if (tempDevice.DeviceNum > 0)
{
int a = data.SetBitValue((byte)tInfo.ElementAt(i).ElementAt(m).Loc, true);
byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.ABCD);
byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.BADC);
int item = test1.ToInt();
SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4}", item, 5);
MessageNotify.GetInstance.ShowRunLog($"下发配方DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4} :{item}-{item.ToBinString()}");
var RE = SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4}", item);
//var RE = SiemensDevice.GetInstance.MySiemens.Write($"DB4.DBX2.0", true);
if (RE.IsSuccess)
MessageNotify.GetInstance.ShowRunLog($"下发配方DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4} :{(byte)tInfo.ElementAt(i).ElementAt(m).Loc}-{item}-{item.ToBinString()}");
else
MessageNotify.GetInstance.ShowRunLog($"下发配方DB4.DBD{2 + (tempDevice.DeviceNum - 1) * 4} 失败");
}
}
if (tInfo.ElementAt(i).ElementAt(m).Loc > 0)
@@ -164,7 +168,7 @@ namespace BPASmartClient.DosingSystem.ViewModel
}
}
}
SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD198", BarrelNum.Count, 5);//配方使用桶数写入
SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD198", BarrelNum.Count);//配方使用桶数写入
/*if (recipeData.Count <= 0)
{
MessageNotify.GetInstance.ShowRunLog("配方数据解析失败");
@@ -325,83 +329,97 @@ namespace BPASmartClient.DosingSystem.ViewModel
}
else
{
switch (cnt)
if (cnt >= 1 && cnt <= 6)
{
case 1:
int a1 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == 1);
int b1 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == 2);
if (a1 >= 0)
{
Location1 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(a1).DeviceName && p.Loc == barrel);
}
if (b1 >= 0)
{
Location2 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(b1).DeviceName && p.Loc == barrel);
}
break;
case 2:
int a2 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == 3);
int b2 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == 4);
if (a2 >= 0)
{
Location1 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(a2).DeviceName && p.Loc == barrel);
}
if (b2 >= 0)
{
Location2 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(b2).DeviceName && p.Loc == barrel);
}
break;
case 3:
int a3 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == 5);
int b3 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == 6);
if (a3 >= 0)
{
Location1 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(a3).DeviceName && p.Loc == barrel);
}
if (b3 >= 0)
{
Location2 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(b3).DeviceName && p.Loc == barrel);
}
break;
case 4:
int a4 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == 7);
int b4 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == 8);
if (a4 >= 0)
{
Location1 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(a4).DeviceName && p.Loc == barrel);
}
if (b4 >= 0)
{
Location2 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(b4).DeviceName && p.Loc == barrel);
}
break;
case 5:
int a5 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == 9);
int b5 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == 10);
if (a5 >= 0)
{
Location1 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(a5).DeviceName && p.Loc == barrel);
}
if (b5 >= 0)
{
Location2 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(b5).DeviceName && p.Loc == barrel);
}
break;
case 6:
int a6 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == 11);
int b6 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == 12);
if (a6 >= 0)
{
Location1 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(a6).DeviceName && p.Loc == barrel);
}
if (b6 >= 0)
{
Location2 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(b6).DeviceName && p.Loc == barrel);
}
break;
default:
break;
int a1 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == cnt * 2 - 1);
int b1 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == cnt * 2);
if (a1 >= 0)
{
Location1 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(a1).DeviceName && p.Loc == barrel);
}
if (b1 >= 0)
{
Location2 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(b1).DeviceName && p.Loc == barrel);
}
}

//switch (cnt)
//{
// case 1:
// int a1 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == 1);
// int b1 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == 2);
// if (a1 >= 0)
// {
// Location1 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(a1).DeviceName && p.Loc == barrel);
// }
// if (b1 >= 0)
// {
// Location2 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(b1).DeviceName && p.Loc == barrel);
// }
// break;
// case 2:
// int a2 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == 3);
// int b2 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == 4);
// if (a2 >= 0)
// {
// Location1 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(a2).DeviceName && p.Loc == barrel);
// }
// if (b2 >= 0)
// {
// Location2 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(b2).DeviceName && p.Loc == barrel);
// }
// break;
// case 3:
// int a3 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == 5);
// int b3 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == 6);
// if (a3 >= 0)
// {
// Location1 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(a3).DeviceName && p.Loc == barrel);
// }
// if (b3 >= 0)
// {
// Location2 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(b3).DeviceName && p.Loc == barrel);
// }
// break;
// case 4:
// int a4 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == 7);
// int b4 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == 8);
// if (a4 >= 0)
// {
// Location1 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(a4).DeviceName && p.Loc == barrel);
// }
// if (b4 >= 0)
// {
// Location2 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(b4).DeviceName && p.Loc == barrel);
// }
// break;
// case 5:
// int a5 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == 9);
// int b5 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == 10);
// if (a5 >= 0)
// {
// Location1 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(a5).DeviceName && p.Loc == barrel);
// }
// if (b5 >= 0)
// {
// Location2 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(b5).DeviceName && p.Loc == barrel);
// }
// break;
// case 6:
// int a6 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == 11);
// int b6 = Array.FindIndex(DeviceInquire.GetInstance.devices.ToArray(), p => p.DeviceNum == 12);
// if (a6 >= 0)
// {
// Location1 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(a6).DeviceName && p.Loc == barrel);
// }
// if (b6 >= 0)
// {
// Location2 = Array.FindIndex(Recipes.ElementAt(i).RawMaterials.ToArray(), p => p.RawMaterialName == DeviceInquire.GetInstance.devices.ElementAt(b6).DeviceName && p.Loc == barrel);
// }
// break;
// default:
// break;
//}
}
if (Location1 >= 0)
{
@@ -439,10 +457,10 @@ namespace BPASmartClient.DosingSystem.ViewModel
StockStatus.ElementAt(St_index).IssueStatus = 2;
DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).StatusReset();
int a = 0.SetBitValue((byte)(DeviceNum), true);
byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.ABCD);
byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.BADC);
int item = test1.ToInt();
string res = SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD130", item, 2);
MessageNotify.GetInstance.ShowRunLog($"{res}");
SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD130", item);
//MessageNotify.GetInstance.ShowRunLog($"{res}");
MessageNotify.GetInstance.ShowRunLog($"DB4.DBD130:{item.ToBinString()}");
MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},出料完成,状态复位");
}
@@ -491,10 +509,10 @@ namespace BPASmartClient.DosingSystem.ViewModel
StockStatus.ElementAt(St_index).IssueStatus = 2;
DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).StatusReset();
int a = 0.SetBitValue((byte)(DeviceNum), true);
byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.ABCD);
byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.BADC);
int item = test1.ToInt();
string res = SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD130", item, 5);
MessageNotify.GetInstance.ShowRunLog($"{res}");
SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD130", item);
//MessageNotify.GetInstance.ShowRunLog($"{res}");
//MessageNotify.GetInstance.ShowRunLog($"DB4.DBD130:{item.ToBinString()}");
MessageNotify.GetInstance.ShowRunLog($"DB4.DBD130:{item}");
MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},出料完成,状态复位");
@@ -542,11 +560,11 @@ namespace BPASmartClient.DosingSystem.ViewModel
StockStatus.ElementAt(St_index).IssueStatus = 2;
DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).StatusReset();
int a = 0.SetBitValue((byte)(DeviceNum), true);
byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.ABCD);
byte[] test1 = a.ToBytes(BPA.Helper.DataFormat.BADC);
int item = test1.ToInt();
string res = SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD130", item, 5);
SiemensDevice.GetInstance.MySiemens.Write("DB4.DBD130", item);
recipeProcesses.ElementAt(recIndex).RawMaterials.ElementAt(loc).UpLimtWeightFeedback = DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp).deviceStatus.NowWeightFeedback;
MessageNotify.GetInstance.ShowRunLog($"{res}");
//MessageNotify.GetInstance.ShowRunLog($"{res}");
MessageNotify.GetInstance.ShowRunLog($"DB4.DBD130:{item.ToBinString()}");
MessageNotify.GetInstance.ShowRunLog($"柔性味魔方{Recipes.ElementAt(i).RawMaterials.ElementAt(loc).DeviceIp},出料完成,状态复位");
}
@@ -649,7 +667,7 @@ namespace BPASmartClient.DosingSystem.ViewModel
{
MessageNotify.GetInstance.ShowUserLog($"原料:{item.RawMaterialName},桶号:{item.Loc},设定配料重量{item.RawMaterialWeight}g,实际配料重量{item.UpLimtWeightFeedback}g");
}
SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX202.1", true);//配料完成
SiemensDevice.GetInstance.MySiemens.Write("DB4.DBX202.0", true);//配料完成
MessageNotify.GetInstance.ShowRunLog($"配方:{CurrentRecipeName},配料完成");
int recipIndex = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == CurrentRecipeName);
App.Current.Dispatcher.Invoke(new Action(() => { recipeProcesses.Clear(); }));


+ 7
- 5
DosingSystem/ViewModel/TempManageControlViewModel.cs View File

@@ -1,5 +1,6 @@
using BPA.Helper;
using BPASmartClient.S7Net;
using BPA.Communication;
using BPA.Helper;
//using BPASmartClient.S7Net;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -94,15 +95,16 @@ namespace BPASmartClient.DosingSystem.ViewModel
public static SiemensTest GetInstance => _Instance ?? (_Instance = new SiemensTest());
private SiemensTest() { }

public SiemensHelper sh { get; set; } = new SiemensHelper();
public Siemens sh { get; set; } = new Siemens();

public void Init()
{
Task.Run(() =>
{
//sh.Connect(S7.Net.CpuType.S71500, "192.168.1.12");
sh.Connect(S7.Net.CpuType.S71200, "192.168.0.15");
if (sh.IsConnected)
//S7.Net.CpuType.S71200, "192.168.0.15"
sh.Connect(new BPA.Communication.Base.ConfigurationOptions() { cpuType = CpuType.S71200, IpAddress = "192.168.0.15" });
if (sh.IsConnected())
MessageLog.GetInstance.Show("西门子PLC连接成功");
else
MessageLog.GetInstance.Show("西门子PLC连接失败");


+ 1
- 1
WpfTest/WpfTest.csproj View File

@@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Include="BPA.CustomResource" Version="1.0.16" />
<PackageReference Include="BPA.Helper" Version="1.0.74" />
<PackageReference Include="BPA.Helper" Version="1.0.75" />
</ItemGroup>

</Project>

Loading…
Cancel
Save