Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Monika1313 committed Mar 12, 2023
1 parent dd2d0c0 commit e7086a0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Wu.CommTool/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
<Setter Property="Foreground" Value="{StaticResource Purple_Foreground}" />
</DataTrigger>
<DataTrigger Binding="{Binding Type}" Value="7">
<Setter Property="Foreground" Value="{StaticResource Cyan_Foreground}" />
<Setter Property="Foreground" Value="{StaticResource Red_Foreground}" />
</DataTrigger>
<DataTrigger Binding="{Binding Type}" Value="10">
<Setter Property="Foreground" Value="{StaticResource Red_Foreground}" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"Name":"数据采集测试","Priority":0,"MateTemplate":"01030BCE0002A7D0","ResponseTemplate":"0103044005F16CBA4F"},{"Name":"数据写入测试","Priority":0,"MateTemplate":"031000000002043F8CCCCDA17D","ResponseTemplate":"0310 0000 0002 402A"},{"Name":"","Priority":0,"MateTemplate":"","ResponseTemplate":""},{"Name":"","Priority":0,"MateTemplate":"","ResponseTemplate":""},{"Name":"","Priority":0,"MateTemplate":"","ResponseTemplate":""},{"Name":"","Priority":0,"MateTemplate":"","ResponseTemplate":""},{"Name":"","Priority":0,"MateTemplate":"","ResponseTemplate":""},{"Name":"","Priority":0,"MateTemplate":"","ResponseTemplate":""},{"Name":"","Priority":0,"MateTemplate":"","ResponseTemplate":""},{"Name":"","Priority":0,"MateTemplate":"","ResponseTemplate":""},{"Name":"","Priority":0,"MateTemplate":"","ResponseTemplate":""},{"Name":"","Priority":0,"MateTemplate":"","ResponseTemplate":""},{"Name":"","Priority":0,"MateTemplate":"","ResponseTemplate":""}]
41 changes: 17 additions & 24 deletions Wu.CommTool/Models/ModbusRtuFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,27 +142,15 @@ public static bool IsModbusCrcPassed(byte[] frame)
return true;
}

//private Brush SlaveIdBrush = Brushes.RoyalBlue;
//private static Brush FunctionBrush = Brushes.OrangeRed;
//private static Brush StartAddrBrush = Brushes.Purple;
//private static Brush BytesNumBursh = Brushes.DeepPink;
//private static Brush RegisterNumBursh = Brushes.Chocolate;
//private static Brush RegisterValuesBursh = Brushes.LimeGreen;
//private static Brush ErrCodeBursh = Brushes.Red;
//private static Brush CrcCodeBrush = Brushes.BlueViolet;

//private Brush _SlaceIdBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFFF1F0"));
private Brush SlaveIdBrush = Brushes.RoyalBlue;
private static Brush FunctionBrush = Brushes.OrangeRed;
private static Brush StartAddrBrush = Brushes.Purple;
private static Brush BytesNumBursh = Brushes.DeepPink;
private static Brush RegisterNumBursh = Brushes.Chocolate;
private static Brush RegisterValuesBursh = Brushes.LimeGreen;
private static Brush ErrCodeBursh = Brushes.Red;
private static Brush CrcCodeBrush = Brushes.BlueViolet;



//private Brush SlaceIdBrush = Brushes.Blue;
//private Brush FunctionBrush = Brushes.Magenta;
//private Brush StartAddrBrush = Brushes.DarkTurquoise;
//private Brush BytesNumBursh = Brushes.SteelBlue;
//private Brush RegisterNumBursh = Brushes.Peru;
//private Brush RegisterValuesBursh = Brushes.LimeGreen;
//private Brush ErrCodeBursh = Brushes.Red;
//private Brush CrcCodeBrush = Brushes.Purple;

public List<MessageSubContent> GetMessage()
{
Expand Down Expand Up @@ -239,7 +227,7 @@ public List<MessageSubContent> GetMessage()
case ModbusRtuFrameType._0x97错误帧:
messages.Add(new MessageSubContent($"{SlaveId:X2}", ModbusRtuMessageType.SlaveId));
messages.Add(new MessageSubContent($"{(byte)Function:X2}", ModbusRtuMessageType.Function));
messages.Add(new MessageSubContent($"{ErrCodeBursh:X2}", ModbusRtuMessageType.ErrCode));
messages.Add(new MessageSubContent($"{ErrCode:X2}", ModbusRtuMessageType.ErrCode));
messages.Add(new MessageSubContent($"{DatasFormat(CrcCode)}", ModbusRtuMessageType.CrcCode));
break;

Expand Down Expand Up @@ -270,7 +258,7 @@ public List<MessageSubContent> GetmessageWithErrMsg()
List<MessageSubContent> messages = GetMessage();
if (!string.IsNullOrWhiteSpace(ErrMessage))
{
messages.Add(new MessageSubContent($" {ErrMessage}", ModbusRtuMessageType.ErrMsg));
messages.Add(new MessageSubContent($"错误: {ErrMessage}", ModbusRtuMessageType.ErrMsg));
}
return messages;
}
Expand All @@ -282,7 +270,6 @@ public List<MessageSubContent> GetmessageWithErrMsg()
/// <returns></returns>
public string GetFormatFrame()
{
//TODO 数据帧功能不同 格式化
try
{
//Todo 目前仅处理帧格式, 不解析帧内容是否符合要求
Expand Down Expand Up @@ -366,14 +353,15 @@ private void AnalyseFrame()
if (!IsCrcPassed)
{
Type = ModbusRtuFrameType.校验失败;
ErrMessage = "Crc校验失败";
ErrMessage = "Crc校验失败...";
return;
}

SlaveId = Frame[0]; //从站地址
Function = (ModbusRtuFunctionCode)Frame[1]; //功能码

//Todo 仅实现了部分功能码
//todo 根据消息内容判断消息的有效性,
switch (Function)
{
//0x01读线圈
Expand Down Expand Up @@ -761,6 +749,11 @@ private void AnalyseFrame()
default:
break;
}

if (CrcCode == null)
{
ErrMessage = "无法解析...";
}
}
#endregion
}
Expand Down
2 changes: 1 addition & 1 deletion Wu.CommTool/ViewModels/ModbusRtuViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,7 @@ private void ReceiveFrame()
}

//0x10功能码
else if (mFrame.Type.Equals(ModbusRtuFrameType._0x10响应帧))
else if (mFrame.Type.Equals(ModbusRtuFrameType._0x10响应帧) && DataMonitorConfig.IsOpened)
{
ShowMessage("数据写入成功");
}
Expand Down
4 changes: 4 additions & 0 deletions Wu.CommTool/Wu.CommTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
</PropertyGroup>
<ItemGroup>
<None Remove="Configs\ModbusRtuAutoResponseConfig\Default.jsonARC" />
<None Remove="Configs\ModbusRtuAutoResponseConfig\Test.jsonARC" />
<None Remove="Configs\ModbusRtuConfig\正泰DTSU666.jsonDMC" />
<None Remove="Configs\ModbusRtuConfig\西门子MAG6000流量计.jsonDMC" />
<None Remove="Configs\MqttClientConfig\Default.jsonMCC" />
Expand All @@ -26,6 +27,9 @@
<None Remove="Images\XX.png" />
</ItemGroup>
<ItemGroup>
<Content Include="Configs\ModbusRtuAutoResponseConfig\Test.jsonARC">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Configs\ModbusRtuAutoResponseConfig\Default.jsonARC">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down

0 comments on commit e7086a0

Please sign in to comment.