Compare commits

...

2 Commits

Author SHA1 Message Date
zhangxy 77a5559f8d 1.GPI日志 2 weeks ago
zhangxy c85cf6f0b4 1.调整了标签信息的显示格式
2.修复了时间显示
2 weeks ago

@ -6,7 +6,7 @@
xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:local="clr-namespace:SocketExample" xmlns:local="clr-namespace:SocketExample"
mc:Ignorable="d" mc:Ignorable="d"
Title="RFID读写器多终端监控软件v1.041" Height="450" Width="800"> Title="RFID读写器多终端监控软件v1.051" Height="450" Width="800">
<Window.Resources> <Window.Resources>
<Style x:Key="SocketButton" TargetType="Button" BasedOn="{StaticResource BaseButtonStyle}"> <Style x:Key="SocketButton" TargetType="Button" BasedOn="{StaticResource BaseButtonStyle}">
@ -135,34 +135,34 @@
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal"> <StackPanel Grid.Row="0" Orientation="Horizontal">
<Label Content="标签:"/> <Label Content="接收消息:"/>
<TextBlock Text="{Binding EPCinfo}" VerticalAlignment="Center"></TextBlock> <TextBlock Text="{Binding OriginMessage}" VerticalAlignment="Center"></TextBlock>
</StackPanel> </StackPanel>
<StackPanel Grid.Row="1" Orientation="Horizontal"> <StackPanel Grid.Row="1" Orientation="Horizontal">
<Label Content="标签:"/>
<TextBlock Text="{Binding EPCinfo}" FontSize="15" FontWeight="Bold" Foreground="Green" VerticalAlignment="Center"></TextBlock>
</StackPanel>
<StackPanel Grid.Row="2" Orientation="Horizontal">
<Label Content="HEX:"/> <Label Content="HEX:"/>
<TextBlock Text="{Binding EPCASC}" VerticalAlignment="Center"></TextBlock> <TextBlock Text="{Binding EPCASC}" VerticalAlignment="Center"></TextBlock>
</StackPanel> </StackPanel>
<Grid Grid.Row="2"> <StackPanel Grid.Row="3" Orientation="Horizontal">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation="Horizontal"> <StackPanel Grid.Column="0" Orientation="Horizontal">
<Label Content="RSSI:"/> <Label Content="RSSI:"/>
<TextBlock Text="{Binding RSSIinfo}" VerticalAlignment="Center"/> <TextBlock Text="{Binding RSSIinfo}" VerticalAlignment="Center"/>
</StackPanel> </StackPanel>
<StackPanel Grid.Column="1" Orientation="Horizontal"> <StackPanel Grid.Column="1" Orientation="Horizontal">
<Label Content="Count:"/> <Label Margin="5 0 0 0" Content="Count:"/>
<TextBlock Text="{Binding Countinfo}" VerticalAlignment="Center"/> <TextBlock Text="{Binding Countinfo}" VerticalAlignment="Center"/>
</StackPanel> </StackPanel>
<StackPanel Grid.Column="2" Orientation="Horizontal"> <StackPanel Grid.Column="2" Orientation="Horizontal">
<Label Content="Time:"/> <Label Margin="5 0 0 0" Content="Time:"/>
<TextBlock Text="{Binding Timeinfo}" VerticalAlignment="Center"/> <TextBlock Text="{Binding Timeinfo}" VerticalAlignment="Center"/>
</StackPanel> </StackPanel>
</Grid> </StackPanel>
</Grid> </Grid>
</ScrollViewer> </ScrollViewer>
@ -404,7 +404,13 @@
<StackPanel Grid.Column="0" Orientation="Horizontal"> <StackPanel Grid.Column="0" Orientation="Horizontal">
<Label Content="GPI1" HorizontalAlignment="Left" Margin="0 0 6 0"/> <Label Content="GPI1" HorizontalAlignment="Left" Margin="0 0 6 0"/>
<Border BorderBrush="Black" BorderThickness="0.5"> <Border BorderBrush="Black" BorderThickness="0.5">
<Label Content="{Binding GPI1}"></Label> <Label Content="{Binding GPI1}" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="">
</i:EventTrigger>
</i:Interaction.Triggers>
</Label>
</Border> </Border>
</StackPanel> </StackPanel>
<StackPanel Grid.Column="1" Orientation="Horizontal"> <StackPanel Grid.Column="1" Orientation="Horizontal">

@ -20,6 +20,7 @@ using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Markup; using System.Windows.Markup;
using System.Windows.Shapes;
using System.Xml; using System.Xml;
using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Command;
using Google.Protobuf.WellKnownTypes; using Google.Protobuf.WellKnownTypes;
@ -136,10 +137,10 @@ namespace SocketExample
public string GPO3 { get => _gpo3; set { _gpo3 = value; OnPropertyChanged(); } } public string GPO3 { get => _gpo3; set { _gpo3 = value; OnPropertyChanged(); } }
public string GPO4 { get => _gpo4; set { _gpo4 = value; OnPropertyChanged(); } } public string GPO4 { get => _gpo4; set { _gpo4 = value; OnPropertyChanged(); } }
public string GPI1 { get => _gpi1; set { _gpi1 = value; OnPropertyChanged(); } } public string GPI1 { get => _gpi1; set { if (_gpi1 != value && _gpi1 != null) { _gpi1 = value; LabelPropertyChanged(); } else { _gpi1 = value; OnPropertyChanged(); } } }
public string GPI2 { get => _gpi2; set { _gpi2 = value; OnPropertyChanged(); } } public string GPI2 { get => _gpi2; set { if (_gpi2 != value && _gpi1 != null) { _gpi2 = value; LabelPropertyChanged(); } else { _gpi2 = value; OnPropertyChanged(); } } }
public string GPI3 { get => _gpi3; set { _gpi3 = value; OnPropertyChanged(); } } public string GPI3 { get => _gpi3; set { if (_gpi3 != value && _gpi1 != null) { _gpi3 = value; LabelPropertyChanged(); } else { _gpi3 = value; OnPropertyChanged(); } } }
public string GPI4 { get => _gpi4; set { _gpi4 = value; OnPropertyChanged(); } } public string GPI4 { get => _gpi4; set { if (_gpi4 != value && _gpi1 != null) { _gpi4 = value; LabelPropertyChanged(); } else { _gpi4 = value; OnPropertyChanged(); } } }
private string _moduleinfo; private string _moduleinfo;
private string _motherboardhardware; private string _motherboardhardware;
@ -249,6 +250,7 @@ namespace SocketExample
private Task onRecieved(ITcpClient client, ReceivedDataEventArgs e) //接收事件 private Task onRecieved(ITcpClient client, ReceivedDataEventArgs e) //接收事件
{ {
path = "";
string time = DateTime.Now.ToString(); string time = DateTime.Now.ToString();
string currentTime = time.Substring(9, time.Length-9); string currentTime = time.Substring(9, time.Length-9);
var mes = e.ByteBlock.Span.ToString(Encoding.UTF8); var mes = e.ByteBlock.Span.ToString(Encoding.UTF8);
@ -275,7 +277,7 @@ namespace SocketExample
Array.Copy(data, 0, newData, 0, 5); // 复制前半部分 // 插入新值 Array.Copy(data, 0, newData, 0, 5); // 复制前半部分 // 插入新值
Array.Copy(data, 5, newData, 5, 4); Array.Copy(data, 5, newData, 5, 4);
Array.Copy(data, 5, newData, 6, data.Length - 5); Array.Copy(data, 5, newData, 6, data.Length - 5);
Timeinfo = $"{currentTime} {time.Substring(0, 10)}";//获取时间 Timeinfo = $"{time}";//获取时间
string NewDataString = BitConverter.ToString(newData).Replace("-", " "); string NewDataString = BitConverter.ToString(newData).Replace("-", " ");
int startTemp = 33; int startTemp = 33;
@ -288,12 +290,13 @@ namespace SocketExample
{ {
int TempLength = taglist[j].EPCstring.Length * 3 - 1; int TempLength = taglist[j].EPCstring.Length * 3 - 1;
EPCinfo = NewDataString.Substring(startTemp, TempLength); EPCinfo = NewDataString.Substring(startTemp, TempLength);
items.Add(new TagItem(taglist[j].EPCstring, EPCinfo, taglist[j].RSSI.ToString(), taglist[j].Count.ToString(), Timeinfo)); items.Add(new TagItem(hexString,taglist[j].EPCstring, EPCinfo, taglist[j].RSSI.ToString(), taglist[j].Count.ToString(), Timeinfo));
startTemp += 16 + TempLength; startTemp += 16 + TempLength;
string year = DateTime.Now.ToString("yyyy-MM-dd"); string year = DateTime.Now.ToString("yyyy-MM-dd");
EnsureFolderExists($"日志文件夹/{year}/{Text}"); EnsureFolderExists($"日志文件夹/{year}/{Text}");
path = $"日志文件夹/{year}/{Text}/" + path + Text + ".txt"; path = $"日志文件夹/{year}/{Text}/" + Text +"("+ IPtext+")"+ ".txt";
writeToTxt(path, $"EPC:{taglist[j].EPCstring}\nHEX:{EPCinfo}\nRSSI:{taglist[j].RSSI.ToString()} Count:{taglist[j].Count.ToString()} Time:{Timeinfo}\n____________________________"); EnsureTxtExists(path,Text, IPtext, Porttext);
writeToTxt(path, $"接收消息:{hexString}\nEPC:{taglist[j].EPCstring}\nHEX:{EPCinfo}\nRSSI:{taglist[j].RSSI.ToString()} Count:{taglist[j].Count.ToString()} Time:{Timeinfo}\n____________________________");
path = ""; path = "";
//LogService.Instance.Debug(""); //LogService.Instance.Debug("");
@ -311,7 +314,7 @@ namespace SocketExample
case "02": case "02":
try try
{ {
Timeinfo = $"{currentTime} {time.Substring(0, 10)}";//获取时间 Timeinfo = $"{time}";//获取时间
int startTemp = 33; int startTemp = 33;
@ -323,12 +326,13 @@ namespace SocketExample
{ {
int TempLength = taglist[j].EPCstring.Length * 3 -1; int TempLength = taglist[j].EPCstring.Length * 3 -1;
EPCinfo = hexString.Substring(startTemp, TempLength); EPCinfo = hexString.Substring(startTemp, TempLength);
items.Add(new TagItem(taglist[j].EPCstring, EPCinfo, taglist[j].RSSI.ToString(), taglist[j].Count.ToString(), Timeinfo)); items.Add(new TagItem(hexString,taglist[j].EPCstring, EPCinfo, taglist[j].RSSI.ToString(), taglist[j].Count.ToString(), Timeinfo));
startTemp += 16 + TempLength; startTemp += 16 + TempLength;
string year = DateTime.Now.ToString("yyyy-MM-dd"); string year = DateTime.Now.ToString("yyyy-MM-dd");
EnsureFolderExists($"日志文件夹/{year}/{Text}"); EnsureFolderExists($"日志文件夹/{year}/{Text}");
path = $"日志文件夹/{year}/{Text}/" + path + Text + ".txt"; path = $"日志文件夹/{year}/{Text}/" + Text + "(" + IPtext + ")" + ".txt";
writeToTxt(path, $"EPC:{taglist[j].EPCstring}\nHEX:{EPCinfo}\nRSSI:{taglist[j].RSSI.ToString()} Count:{taglist[j].Count.ToString()} Time:{Timeinfo}\n____________________________"); EnsureTxtExists(path, Text, IPtext, Porttext);
writeToTxt(path, $"接收消息:{hexString}\nEPC:{taglist[j].EPCstring}\nHEX:{EPCinfo}\nRSSI:{taglist[j].RSSI.ToString()} Count:{taglist[j].Count.ToString()} Time:{Timeinfo}\n____________________________");
path = ""; path = "";
//LogService.Instance.Debug(""); //LogService.Instance.Debug("");
@ -463,7 +467,7 @@ namespace SocketExample
} }
break; break;
default: default:
Infotext += $"default"; //Infotext += $"default";
break; break;
} }
@ -473,16 +477,23 @@ namespace SocketExample
{ {
switch (commandState) switch (commandState)
{ {
case "01":
case "02": case "02":
Infotext += "未读取到\n"; Infotext += "未读取到\n";
RSSIinfo = "##";//未读取到数值时清空数据为初始值 RSSIinfo = "No Read";//未读取到数值时清空数据为初始值
Countinfo = "00"; Countinfo = "00";
EPCASC = "###"; EPCASC = "No Read";
EPCinfo = "###"; EPCinfo = "No Read";
Timeinfo = $" {currentTime}\n{time.Substring(0, 10)}";//获取时间 Timeinfo = $" {time}";//获取时间
ObservableCollection<TagItem> items = new ObservableCollection<TagItem>(); ObservableCollection<TagItem> items = new ObservableCollection<TagItem>();
items.Add(new TagItem(EPCASC, EPCinfo, RSSIinfo, Countinfo, Timeinfo)); items.Add(new TagItem(hexString,EPCASC, EPCinfo, RSSIinfo, Countinfo, Timeinfo));
TagItems = items; TagItems = items;
string year = DateTime.Now.ToString("yyyy-MM-dd");
EnsureFolderExists($"日志文件夹/{year}/{Text}");
path = $"日志文件夹/{year}/{Text}/" + Text + "(" + IPtext + ")" + ".txt";
EnsureTxtExists(path, Text, IPtext, Porttext);
writeToTxt(path, $"接收消息:{hexString}\nEPC:{EPCASC}\nHEX:{EPCinfo}\nRSSI:{RSSIinfo} Count:{Countinfo} Time:{Timeinfo}\n____________________________");
path = "";
break; break;
} }
} }
@ -745,7 +756,7 @@ namespace SocketExample
{ {
case "单次读取": case "单次读取":
ActionType = "单次读取"; ActionType = "单次读取";
data = strToToHexByte("AA 55 02 01 00 64 67 0D");//单次 data = strToToHexByte(CheckForOnce());//单次
break; break;
/* /*
case "连续读取": case "连续读取":
@ -909,11 +920,24 @@ namespace SocketExample
} }
string CheckForOnce()
{
string actionstring = "AA 55 02 01 ";
if(TimeOut!=""&&TimeOut!=null)
actionstring += Convert.ToInt32(TimeOut).ToString("X").PadLeft(4, '0').Insert(2, " ") + " ";
else
actionstring +="00 00 ";
actionstring += Convert.ToString(GetXor(strToToHexByte(actionstring), 2), 16).PadLeft(2,'0').ToUpper() + " 0D";
return actionstring;
}
string CheckDuringTime() string CheckDuringTime()
{ {
string actionstring = "AA 55 02 02 "; string actionstring = "AA 55 02 02 ";
actionstring += Convert.ToInt32(TimeOut).ToString("X").PadLeft(4, '0').Insert(2, " ")+ " "; if (TimeOut != "" && TimeOut != null)
actionstring += Convert.ToString(GetXor(strToToHexByte(actionstring), 2), 16) + " 0D"; actionstring += Convert.ToInt32(TimeOut).ToString("X").PadLeft(4, '0').Insert(2, " ") + " ";
else
actionstring += "00 00 ";
actionstring += Convert.ToString(GetXor(strToToHexByte(actionstring), 2), 16).PadLeft(2, '0') + " 0D";
return actionstring; return actionstring;
} }
void SaveCommand() void SaveCommand()
@ -938,8 +962,52 @@ namespace SocketExample
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
} }
protected void LabelPropertyChanged([CallerMemberName] string propertyName = null)
{
if(GPI1 == "" || GPI2 == ""|| GPI3 == ""|| GPI4 == "" || GPI1 ==null || GPI2 == null || GPI3 == null || GPI4 == null ||client == null)
{
return;
}
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
string year = DateTime.Now.ToString("yyyy-MM-dd");
EnsureFolderExists($"日志文件夹/{year}/{Text}");
string temppath = $"日志文件夹/{year}/{Text}/" + Text + "GPI"+"(" + IPtext + ")" + ".txt";
EnsureTxtExists(temppath, Text, IPtext, Porttext);
string GPIname = "";
string front = "";
string back = "";
switch (propertyName)
{
case "GPI1":
GPIname = "GPI1";
back = GPI1;
break;
case "GPI2":
GPIname = "GPI2";
back = GPI2;
break;
case "GPI3":
GPIname = "GPI3";
back = GPI3;
break;
case "GPI4":
GPIname = "GPI4";
back = GPI4;
break;
}
if (back == "高")
front = "低";
else
front = "高";
writeToTxt(temppath,$"{GPIname}:{front} => {back}\n当前状态GPI1:{GPI1} GPI2:{GPI2} GPI3:{GPI3} GPI4:{GPI4}\n当前时间{year}\n ______________________________");
}
public class TagItem : INotifyPropertyChanged public class TagItem : INotifyPropertyChanged
{ {
private string _originmessage;//原始数据
public string OriginMessage { get => _originmessage;set { _originmessage = value;OnPropertyChanged(); } }
private string _rssiinfo;//RSSI强度 private string _rssiinfo;//RSSI强度
public string RSSIinfo { get => _rssiinfo; set { _rssiinfo = value; OnPropertyChanged(); } } public string RSSIinfo { get => _rssiinfo; set { _rssiinfo = value; OnPropertyChanged(); } }
private string _countinfo;//count数值 private string _countinfo;//count数值
@ -951,8 +1019,9 @@ namespace SocketExample
public string EPCinfo { get => _epcinfo; set { _epcinfo = value; OnPropertyChanged(); } } public string EPCinfo { get => _epcinfo; set { _epcinfo = value; OnPropertyChanged(); } }
public string EPCASC { get => _epcasc; set { _epcasc = value; OnPropertyChanged(); } } public string EPCASC { get => _epcasc; set { _epcasc = value; OnPropertyChanged(); } }
public TagItem(string infoEPC,string ascEPC,string RSSI,string count,string time) public TagItem(string originMessage,string infoEPC,string ascEPC,string RSSI,string count,string time)
{ {
OriginMessage = originMessage;
EPCinfo = infoEPC; EPCinfo = infoEPC;
EPCASC = ascEPC; EPCASC = ascEPC;
RSSIinfo = RSSI; RSSIinfo = RSSI;
@ -1215,5 +1284,27 @@ namespace SocketExample
} }
} }
private static void EnsureTxtExists(string txtPath,string MachineName,string IPinfo,string Portinfo)
{
// 检查指定的txt路径对应的txt是否已经存在
if (!File.Exists(txtPath))
{
try
{
StreamWriter streamWriter = new StreamWriter(txtPath, true);
streamWriter.WriteLineAsync($"设备名称:{MachineName}\nIP地址:{IPinfo}\n端口号:{Portinfo}\n____________________________");
streamWriter.Close();
}
catch (IOException ex)
{
// 如果在创建文件夹过程中出现IOException异常比如权限不足、磁盘已满等原因导致无法创建文件夹
// 这里通过消息框向用户展示创建文件夹失败的异常信息,方便用户知晓问题所在
MessageBox.Show($"创建txt {txtPath} 失败,异常信息: {ex.Message}");
// 重新抛出异常,让调用这个方法的上层代码知道创建文件夹出现了问题,以便进行进一步的处理,比如终止程序或者尝试其他恢复操作
throw;
}
}
}
} }
} }

Loading…
Cancel
Save