add-提交研发测试版

development
liuwf 1 month ago
parent 13784c8c79
commit d60a4e6e5a

@ -0,0 +1,83 @@
using Microsoft.Extensions.Logging;
using SlnMesnac.Config;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using TouchSocket.Core;
using TouchSocket.Sockets;
namespace SlnMesnac.TouchSocket
{
public class MyTcpClient : TcpClient
{
private DebugConfig config = DebugConfig.Instance;
private TcpClient tcpClient = new TcpClient();
//识别结果
public delegate void RefreshResult(string result);
public static event RefreshResult RefreshResultEvent;
public MyTcpClient()
{
}
public async Task StartAsync(string ip, string port)
{
try
{
tcpClient.Connecting = (client, e) => {
Console.WriteLine($"客户端{client.Port}正在接入服务");
return EasyTask.CompletedTask;
};
tcpClient.Connected = (client, e) => {
Console.WriteLine($"客户端{client.Port}接入服务成功");
return EasyTask.CompletedTask;
};
tcpClient.Disconnected = (client, e) => {
Console.WriteLine($"客户端{client.Port}断开连接");
return EasyTask.CompletedTask;
};
tcpClient.Received = (client, e) =>
{
//从服务器收到信息
var mes = Encoding.UTF8.GetString(e.ByteBlock.Buffer, 0, e.ByteBlock.Len);//注意数据长度是byteBlock.Len
Console.WriteLine($"{client.Port}接收到信息:{mes}");
RefreshResultEvent?.Invoke(mes);
return EasyTask.CompletedTask;
};
await tcpClient.ConnectAsync($"{ip}:{port}");
}catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
public void sendMessage(string type,string msg)
{
if(type== "ocr")
{
}else if(type == "pci")
{
// 使用转义字符正确构造字符串
string message = $"\x00\x00\x00+{{\"image_path\": \"{msg}\"}}";
tcpClient.Send(message);
}
}
}
}

@ -16,10 +16,12 @@ namespace SlnMesnac.TouchSocket
{
services.AddSingleton<TcpService>();//注册TouchSocket的服务
services.AddSingleton<TcpServer>();
}
public static IApplicationBuilder UseTouchSocketExtensions(this IApplicationBuilder app)
{
var _server = app.ApplicationServices.GetService<TcpServer>();
_server.Init(7024);
return app;

@ -1,6 +1,7 @@
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using HslCommunication.Enthernet;
using HslCommunication.Secs.Types;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
@ -21,12 +22,14 @@ using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Security.Policy;
using System.ServiceModel.Channels;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using TouchSocket.Sockets;
using static System.Net.Mime.MediaTypeNames;
namespace SlnMesnac.WPF.ViewModel
@ -37,7 +40,7 @@ namespace SlnMesnac.WPF.ViewModel
private GunHelper gunHelper = GunHelper.Instance;
public RelayCommand ResetCommand { get; set;}
//导入照片
public RelayCommand InputSourceCommand { get; set;}
public RelayCommand<string> InputSourceCommand { get; set;}
private LogoBusiness logoBusiness = null;
private LightHelper lightHelper = LightHelper.Instance;
@ -50,9 +53,13 @@ namespace SlnMesnac.WPF.ViewModel
private TcpServer? tcpServer;
private PlcPool plcPool = null;
private MyTcpClient pciClient = new MyTcpClient();
private MyTcpClient ocrClient = new MyTcpClient();
public IndexViewModel()
{
MyTcpClient.RefreshResultEvent += RefreshCheckResult;
logoIdentifyService = App.ServiceProvider.GetService<ILogoIdentifyService>();
LogoBusiness.RefreshMessageEvent += RefreshMessage;
LogoBusiness.RefreshBoxInfoEvent += RefreshBoxInfo;
@ -60,7 +67,7 @@ namespace SlnMesnac.WPF.ViewModel
LogoBusiness.RefreshDataGridEvent += RefreshDataGrid;
LightHelper.RefreshMessageEvent += RefreshMessage;
ResetCommand = new RelayCommand(Reset);
InputSourceCommand = new RelayCommand(InputSource);
InputSourceCommand = new RelayCommand<string>(InputSource);
RefreshDataGrid();
plcPool = App.ServiceProvider.GetService<PlcPool>();
@ -76,8 +83,26 @@ namespace SlnMesnac.WPF.ViewModel
// gunHelper.SendData("OK");
OKIsVis = Visibility.Hidden;
NGIsVis = Visibility.Hidden;
Init();
}
private void Init()
{
Task.Run(async () =>
{
await ocrClient.StartAsync("127.0.0.1", "10001");
await pciClient.StartAsync("127.0.0.1", "9999");
});
}
private void RefreshCheckResult(string message)
{
RefreshMessage(message);
}
/// <summary>
/// 复位方法
/// 复位PLC放行复位报警灯
@ -95,7 +120,7 @@ namespace SlnMesnac.WPF.ViewModel
/// <summary>
/// 导入按钮导入图片进行OCR识别与验证
/// </summary>
private void InputSource()
private void InputSource(string type)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "图片文件|*.jpg;*.png;*.bmp";
@ -109,8 +134,16 @@ namespace SlnMesnac.WPF.ViewModel
string fileName = Path.GetFileName(selectedFilePath);
RefreshPicture(File.ReadAllBytes(selectedFilePath));
if(type== "ocr")
{
ocrClient.sendMessage("ocr","hello world");
}
else if(type== "pci")
{
pciClient.sendMessage("pci",fileName);
}
}
}

@ -148,11 +148,13 @@
</StackPanel>
<StackPanel Grid.Row="2" Grid.Column="0" Orientation="Horizontal" VerticalAlignment="Center" >
<TextBlock Text="产品型号" FontSize="22" Foreground="White" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0 0 30 0"/>
<TextBox FontSize="18" Text="{Binding ProductModel,Mode=TwoWay}" BorderBrush="White" Foreground="White" Width="250" IsReadOnly="True" Margin="0 0 0 0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" />
<TextBox FontSize="18" Text="{Binding ProductModel,Mode=TwoWay}" BorderBrush="White" Foreground="White" Width="100" IsReadOnly="True" Margin="0 0 0 0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" />
<Button Content="复 位" Command="{Binding ResetCommand}"
Style="{StaticResource MaterialDesignRaisedSecondaryDarkButton}" Background="#FF1CC57B" Width="130" Height="50" Margin="50 0 0 0"/>
<Button Content="导 入" Command="{Binding InputSourceCommand}"
Style="{StaticResource MaterialDesignRaisedSecondaryDarkButton}" Background="Blue" Width="130" Height="50" Margin="50 0 0 0"/>
Style="{StaticResource MaterialDesignRaisedSecondaryDarkButton}" Background="#FF1CC57B" Width="130" Height="50" Margin="20 0 0 0"/>
<Button Content="PCI" Command="{Binding InputSourceCommand}" CommandParameter="pci"
Style="{StaticResource MaterialDesignRaisedSecondaryDarkButton}" Background="Blue" Width="130" Height="50" Margin="20 0 0 0"/>
<Button Content="OCR" Command="{Binding InputSourceCommand}" CommandParameter="ocr"
Style="{StaticResource MaterialDesignRaisedSecondaryDarkButton}" Background="Blue" Width="130" Height="50" Margin="20 0 0 0"/>
</StackPanel>

Loading…
Cancel
Save