diff --git a/CapMachine.Wpf/CanDrive/ToomossCan.cs b/CapMachine.Wpf/CanDrive/ToomossCan.cs
index bda0124..c908574 100644
--- a/CapMachine.Wpf/CanDrive/ToomossCan.cs
+++ b/CapMachine.Wpf/CanDrive/ToomossCan.cs
@@ -1,6 +1,7 @@
using CapMachine.Wpf.Models.Tag;
using CapMachine.Wpf.Services;
using HslCommunication;
+using ImTools;
using NPOI.OpenXmlFormats.Wordprocessing;
using Prism.Ioc;
using Prism.Mvvm;
@@ -21,6 +22,8 @@ namespace CapMachine.Wpf.CanDrive
{
///
/// Toomoss CAN
+ /// 如果精度达不到的话则使用CAN通信调度表模式实现方案
+ /// 目前有0-1ms的抖动
///
public class ToomossCan : BindableBase
{
@@ -33,6 +36,7 @@ namespace CapMachine.Wpf.CanDrive
{
ContainerProvider = containerProvider;
HighSpeedDataService = ContainerProvider.Resolve();
+ HightDriveMsgService = ContainerProvider.Resolve();
//Stopwatch.Frequency表示高精度计时器每秒的计数次数(ticks/秒)每毫秒的ticks数 = 每秒的ticks数 ÷ 1000
TicksPerMs = Stopwatch.Frequency / 1000.0;
@@ -478,8 +482,6 @@ namespace CapMachine.Wpf.CanDrive
RaisePropertyChanged();
_IsSendOk = value;
}
-
-
}
}
@@ -604,7 +606,6 @@ namespace CapMachine.Wpf.CanDrive
CycleSendCts = cancellationTokenSource;//将取消标记源保存到类的成员变量CycleSendCts,这样在外部调用停止方法时可以访问它
NextExecutionTime = 0;//初始化NextExecutionTime为0,这个变量用于记录下一次执行的目标时间点
-
CycleSendTask = Task.Factory.StartNew(async () =>
{
try
@@ -667,6 +668,7 @@ namespace CapMachine.Wpf.CanDrive
lastTicks = Stopwatcher.ElapsedTicks;
//Console.WriteLine($"--当前时间(毫秒): {DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}");
+
// 执行发送CAN逻辑
{
@@ -697,13 +699,13 @@ namespace CapMachine.Wpf.CanDrive
//释放申请的临时缓冲区
Marshal.FreeHGlobal(msgPtSend);
-
+
//发送CAN数据
int SendedNum = USB2CAN.CAN_SendMsg(DevHandle, WriteCANIndex, CanMsg, (uint)CanMsg.Length);
if (SendedNum >= 0)
{
//Console.WriteLine("Success send frames:{0}", SendedNum);
- IsSendOk=true;
+ IsSendOk = true;
}
else
{
@@ -796,7 +798,7 @@ namespace CapMachine.Wpf.CanDrive
Category = "CAN",
MsgInfo = "0x" + CanMsgBuffer[i].ID.ToString("X8"),
MsgData = BitConverter.ToString(CanMsgBuffer[i].Data),
- Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
+ Time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
});
//报文给高速报文处理服务
@@ -805,7 +807,7 @@ namespace CapMachine.Wpf.CanDrive
Category = "CAN",
MsgInfo = "0x" + CanMsgBuffer[i].ID.ToString("X8"),
MsgData = BitConverter.ToString(CanMsgBuffer[i].Data),
- Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
+ Time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
});
}
}
diff --git a/CapMachine.Wpf/Models/HighSpeed/CommMsg.cs b/CapMachine.Wpf/Models/HighSpeed/CommMsg.cs
index 11779ad..cf9273a 100644
--- a/CapMachine.Wpf/Models/HighSpeed/CommMsg.cs
+++ b/CapMachine.Wpf/Models/HighSpeed/CommMsg.cs
@@ -12,9 +12,9 @@ namespace CapMachine.Wpf.Models.HighSpeed
public class CommMsg
{
///
- /// 时间
+ /// 整数时间戳(毫秒)
///
- public string? Time { get; set; }
+ public long Time { get; set; }
///
/// 分类
diff --git a/CapMachine.Wpf/Services/CanDriveService.cs b/CapMachine.Wpf/Services/CanDriveService.cs
index 751fca9..2089729 100644
--- a/CapMachine.Wpf/Services/CanDriveService.cs
+++ b/CapMachine.Wpf/Services/CanDriveService.cs
@@ -86,6 +86,45 @@ namespace CapMachine.Wpf.Services
#region 程序驱动CAN
+
+ private bool _CanAutoHand;
+ ///
+ /// CAN 手自动 模式,自动代表接受程序步骤的数据,手动代表接受手动输入的数据
+ /// True代表自动,False代表手动
+ ///
+ public bool CanAutoHand
+ {
+ get { return _CanAutoHand; }
+ set
+ {
+ if (_CanAutoHand != value)
+ {
+ RaisePropertyChanged();
+ _CanAutoHand = value;
+ }
+ }
+ }
+
+
+ private bool _CanHandEnable;
+ ///
+ /// CAN 手动 模式,是否使能,用于报文的使能和非使能的数据
+ /// True代表使能,False代表禁用
+ ///
+ public bool CanHandEnable
+ {
+ get { return _CanHandEnable; }
+ set
+ {
+ if (_CanHandEnable != value)
+ {
+ RaisePropertyChanged();
+ _CanHandEnable = value;
+ }
+ }
+ }
+
+
private int _AutoSpeedSv;
///
/// 转速SV
@@ -93,7 +132,15 @@ namespace CapMachine.Wpf.Services
public int AutoSpeedSv
{
get { return _AutoSpeedSv; }
- set { _AutoSpeedSv = value; RaisePropertyChanged(); }
+ set
+ {
+ if (value!= _AutoSpeedSv)
+ {
+ _AutoSpeedSv = value;
+ RaisePropertyChanged();
+ }
+
+ }
}
@@ -167,7 +214,7 @@ namespace CapMachine.Wpf.Services
{
//LogicRuleService.ApplyExpressionFast(SpeedData, SpeedCanCmdData.LogicRuleDto);
SpeedCanCmdData.SignalCmdValue = LogicRuleService.ApplyExpressionFast(SpeedData, SpeedCanCmdData.LogicRuleDto);
- Console.WriteLine($"实时转换后转速值:{SpeedCanCmdData.SignalCmdValue}-SV值:{SpeedData}");
+ //Console.WriteLine($"实时转换后转速值:{SpeedCanCmdData.SignalCmdValue}-SV值:{SpeedData}");
}
}
@@ -184,7 +231,7 @@ namespace CapMachine.Wpf.Services
public void UpdateCapEnableCmdData(bool IsEnable)
{
if (!ToomossCanDrive.IsCycleSend) return;
-
+ if (!CanAutoHand) return;
if (EnableCanCmdData != null)
{
EnableCanCmdData.SignalCmdValue = IsEnable ? 1 : 0;
@@ -194,6 +241,7 @@ namespace CapMachine.Wpf.Services
///
/// 发送消息给CAN 驱动
+ /// 手动发送时使用
///
public void SendMsgToCanDrive(double SpeedData)
{
diff --git a/CapMachine.Wpf/Services/MachineRtDataService.cs b/CapMachine.Wpf/Services/MachineRtDataService.cs
index d82cd8f..1c4c978 100644
--- a/CapMachine.Wpf/Services/MachineRtDataService.cs
+++ b/CapMachine.Wpf/Services/MachineRtDataService.cs
@@ -2747,7 +2747,7 @@ namespace CapMachine.Wpf.Services
switch (ConfigService.CanLinRunStateModel.CurSysSelectedCanLin)
{
case CanLinEnum.Can:
- //获取PLC的使能状态,更新到CAN的使能状态
+ //获取PLC的使能状态,更新到CAN的使能状态
CanDriveService.UpdateCapEnableCmdData(item.State);
//itemTag.Value.EngPvValue = 0;
break;
@@ -3068,10 +3068,12 @@ namespace CapMachine.Wpf.Services
switch (itemStepExd.ValueType)
{
case ExdValueType.Bool:
- SiemensDrive.Write(DataAdrees.Address, (bool)itemStepExd.Value == true ? 1 : 0);
+ var ResultBool = SiemensDrive.Write(DataAdrees.Address, (bool)itemStepExd.Value == true ? 1 : 0);
+ if (!ResultBool.IsSuccess) Console.WriteLine($"{ProRunChannelData.MeterName}:{itemStepExd.Name}写入失败");
break;
case ExdValueType.Short:
- SiemensDrive.Write(DataAdrees.Address, (short)itemStepExd.Value);
+ var ResultShort = SiemensDrive.Write(DataAdrees.Address, (short)itemStepExd.Value);
+ if (!ResultShort.IsSuccess) Console.WriteLine($"{ProRunChannelData.MeterName}:{itemStepExd.Name}写入失败");
break;
case ExdValueType.Double:
break;
@@ -3117,6 +3119,7 @@ namespace CapMachine.Wpf.Services
///
/// 发送速度SV到压缩机
+ /// 自动步骤数据发送
///
private void SendSpeedSvToCap(int SpeedSv)
{
@@ -3124,7 +3127,11 @@ namespace CapMachine.Wpf.Services
{
case CanLinEnum.Can:
//获取PLC的SV数据 更新SV的速度值到压缩机
- CanDriveService.UpdateSpeedCmdData(SpeedSv);
+ if (CanDriveService.CanAutoHand)//自动时步骤的数据可以赋值数据
+ {
+ CanDriveService.UpdateSpeedCmdData(SpeedSv);
+ }
+
//itemTag.Value.EngPvValue = 0;
break;
case CanLinEnum.Lin:
diff --git a/CapMachine.Wpf/ViewModels/CANConfigViewModel.cs b/CapMachine.Wpf/ViewModels/CANConfigViewModel.cs
index fbc92dd..8dfff35 100644
--- a/CapMachine.Wpf/ViewModels/CANConfigViewModel.cs
+++ b/CapMachine.Wpf/ViewModels/CANConfigViewModel.cs
@@ -25,6 +25,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
+using System.Windows.Controls.Primitives;
using System.Windows.Documents;
using static CapMachine.Wpf.Models.ComEnum;
@@ -38,7 +39,7 @@ namespace CapMachine.Wpf.ViewModels
public CANConfigViewModel(IDialogService dialogService, IFreeSql freeSql,
IEventAggregator eventAggregator, IRegionManager regionManager, SysRunService sysRunService,
ComActionService actionService, LogicRuleService logicRuleService,
- ConfigService configService, CanDriveService canDriveService,HightDriveMsgService hightDriveMsgService,
+ ConfigService configService, CanDriveService canDriveService, HightDriveMsgService hightDriveMsgService,
IMapper mapper, MachineRtDataService machineRtDataService)
{
//LogService = logService;
@@ -96,7 +97,7 @@ namespace CapMachine.Wpf.ViewModels
public ComActionService ComActionService { get; }
public LogicRuleService LogicRuleService { get; }
public ConfigService ConfigService { get; }
- public CanDriveService CanDriveService { get; }
+ public CanDriveService CanDriveService { get; set; }
public HightDriveMsgService HightDriveMsgService { get; }
public IMapper Mapper { get; }
private MachineRtDataService MachineRtDataService { get; }
@@ -991,7 +992,7 @@ namespace CapMachine.Wpf.ViewModels
case "CycleRecive":
CanDriveService.CycleReciveMsg();
- //Listen
+ //Listen
break;
default:
break;
@@ -999,6 +1000,87 @@ namespace CapMachine.Wpf.ViewModels
}
+ private DelegateCommand