change-成品下线添加扫码枪,验证扫码

dev
liuwf 11 months ago
parent 6d1c92f39c
commit e2483160a9

@ -0,0 +1,140 @@
using Admin.Core.Common;
using Aucma.Core.ProductOffLine.Config;
using Aucma.Core.Scanner;
using log4net;
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Aucma.Core.ProductOffLine.Business
{
/// <summary>
/// 扫码枪补扫
/// </summary>
public class GunBusiness
{
private static AppConfig appConfig = AppConfig.Instance;
private static SerialPort serialPort = new SerialPort();
private static List<ScannerModel> allScanners = Appsettings.app<ScannerModel>("ScannerServer").ToList();
// 内胆扫码器ip
private static string LinerScannerIp = allScanners.First(x => x.Name == "内侧扫码器1").Ip;
// 箱壳扫码器ip
private static string ShellScannerIp = allScanners.First(x => x.Name == "外侧扫码器2").Ip;
#region 单例实现
private static readonly GunBusiness lazy = new GunBusiness();
/// <summary>
/// 扫码委托
/// </summary>
/// <param name="materialCodeStr"></param>
/// <param name="ip"></param>
public delegate void RefreshMaterialCodeStr(string materialCodeStr, string ip);
public static event RefreshMaterialCodeStr RefreshMaterialCodeStrEvent;
public static GunBusiness Instance
{
get
{
return lazy;
}
}
#endregion
private static readonly log4net.ILog logHelper = LogManager.GetLogger(typeof(GunBusiness));
//初始化串口并启动接收数据
public static void InstanceSerialPort3()
{
try
{
string port = System.IO.Ports.SerialPort.GetPortNames().FirstOrDefault();
//实例化串行端口
//端口名 注:因为使用的是USB转RS232 所以去设备管理器中查看一下虚拟com口的名字
serialPort.PortName = port;// portName;
//波特率
serialPort.BaudRate = 115200;
//奇偶校验
serialPort.Parity = Parity.None;
//停止位
serialPort.StopBits = StopBits.One;
//数据位
serialPort.DataBits = 8;
//忽略null字节
serialPort.DiscardNull = true;
//接收事件
serialPort.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(serialPort1_DataReceived);
//开启串口
serialPort.Open();
}
catch (Exception ex)
{
logHelper.Error(ex.Message.ToString());
}
}
private static void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
Thread.Sleep(50);
int nums = serialPort.BytesToRead;
byte[] receiveBytes = new byte[nums];
serialPort.Read(receiveBytes, 0, nums);
StringBuilder sb = new StringBuilder();
string str = Encoding.ASCII.GetString(receiveBytes);
string ip = DirectionToIP();
if (!string.IsNullOrEmpty(ip))
{
RefreshMaterialCodeStrEvent?.Invoke(str,ip);
int direction = -1;
appConfig.GunDirection = direction.ToString();
}
sb.Clear();
}
/// <summary>
/// 将用户选择的放行方向转换为对应位置的扫码器ip
/// </summary>
/// <returns></returns>
private static string DirectionToIP()
{
try
{
// 外侧方向转换为外侧扫码器ip
if (int.Parse(appConfig.GunDirection) == 0)
{
return ShellScannerIp;
}
// 内侧方向转换为内侧扫码器ip
else if (int.Parse(appConfig.GunDirection) == 1)
{
return LinerScannerIp;
}
else
{
return "";
}
}
catch (Exception ex)
{
return "";
}
}
}
}

@ -109,8 +109,10 @@ namespace Aucma.Core.ProductOffLine.Business
public OffLineBusiness()
{
MvCodeHelper.RefreshMaterialCodeStrEvent += MaterialBarScan;
GunBusiness.RefreshMaterialCodeStrEvent += MaterialBarScan;
ChooseDirectionWindow.SendPlcPassEvent += DownLoadPassFlag;
test();
//test();
}
#region 变量定义
/// <summary>
@ -122,6 +124,15 @@ namespace Aucma.Core.ProductOffLine.Business
public void test()
{
//Task.Run(() =>
//{
// Thread.Sleep(5000);
//});
// private static readonly log4net.ILog log = LogManager.GetLogger(typeof(OffLineBusiness));
// string result = _productOffLineServices.QueryChecked("1520870000099E2V0004");
// string result = _productOffLineServices.QueryChecked("1530080CD0098E1V1714");
@ -129,33 +140,28 @@ namespace Aucma.Core.ProductOffLine.Business
// string strSave = _productOffLineServices.SaveBarcodeInfo("1520870000099E2V0004", "ILS_SORT", result.Replace("0000",""), 1);
// LogHelper.Info("成品码:1520870000099E2V0004"+strSave);
// string tt = "Y@1104@16160030000000910780@000010034895@@ @000000@000000009000004899@BCD-160C,家电下乡@@BCD-160C@皓月白-家电下乡@161601300@160@1-00版@家电下乡产品@默认@2010-09-01";
Task.Run(() =>
{
//while (true)
//{
Thread.Sleep(5000);
// string aa = appConfig.BarCodeAccount;
// string bb = appConfig.ProductlineCode;
// appConfig.BarCodeAccount = "123";
//TempOffLineInfo1.QualityResult = "失败";
//TempOffLineInfo1.ProductSNCode = "323222444"; //产品SN条码*1
//TempOffLineInfo1.ProductScanTime = System.DateTime.Now; // 扫码时间*2
//TempOffLineInfo1.MsgInfo = "条码质检失败:";
//RefreshScanMateriaCodeEvent?.Invoke(TempOffLineInfo1);
// Random random = new Random();
// MaterialBarScan("32160030000000912" + random.Next(100, 999), "10.10.92.141");
//Thread.Sleep(3000);
//Random random1 = new Random();
//MaterialBarScan("99160030000000912" + random1.Next(100, 999), "10.10.92.141");
//Thread.Sleep(3000);
//Random random2 = new Random();
//MaterialBarScan("44160030000000912" + random2.Next(100, 999), "10.10.92.141");
// }
// Thread.Sleep(1000);
// MaterialBarScanEvent("33160030000000910780", "192.168.1.20");
});
// string aa = appConfig.BarCodeAccount;
// string bb = appConfig.ProductlineCode;
// appConfig.BarCodeAccount = "123";
//TempOffLineInfo1.QualityResult = "失败";
//TempOffLineInfo1.ProductSNCode = "323222444"; //产品SN条码*1
//TempOffLineInfo1.ProductScanTime = System.DateTime.Now; // 扫码时间*2
//TempOffLineInfo1.MsgInfo = "条码质检失败:";
//RefreshScanMateriaCodeEvent?.Invoke(TempOffLineInfo1);
// Random random = new Random();
// MaterialBarScan("32160030000000912" + random.Next(100, 999), "10.10.92.141");
//Thread.Sleep(3000);
//Random random1 = new Random();
//MaterialBarScan("99160030000000912" + random1.Next(100, 999), "10.10.92.141");
//Thread.Sleep(3000);
//Random random2 = new Random();
//MaterialBarScan("44160030000000912" + random2.Next(100, 999), "10.10.92.141");
// }
// Thread.Sleep(1000);
// MaterialBarScanEvent("33160030000000910780", "192.168.1.20");
}
public void MaterialBarScan(string code, string scannerIp)

@ -53,5 +53,13 @@ namespace Aucma.Core.ProductOffLine.Config
set { iniHelper.IniWriteValue("system", "LoginTeam", value); }
}
/// <summary>
/// 扫码枪放行方向0外侧1内侧-1都未选中
/// </summary>
public string GunDirection
{
get { return iniHelper.IniReadValue("system", "GunDirection"); }
set { iniHelper.IniWriteValue("system", "GunDirection", value); }
}
}
}

@ -58,11 +58,12 @@ namespace Aucma.Core.ProductOffLine.ViewModels
Scanner2State(false);
// Job_AllState_Quartz.RefreshStateEvent += RefreshStatus;
InitHikRobot();
InitHikRobotAndGun();
}
#region 开启海康扫码器
public void InitHikRobot()
#region 开启海康扫码器和扫码枪
public void InitHikRobotAndGun()
{
try
{
@ -70,14 +71,16 @@ namespace Aucma.Core.ProductOffLine.ViewModels
{
Thread.Sleep(2000);
//MvCodeHelper1.DeviceListAcq();//获取创建设备
// MvCodeHelper1.StartGrab(); // 开启触发扫码接收数据
Business.MvCodeHelper.Shell();
});
Task.Run(() =>
{
Thread.Sleep(4000);
// 启动扫码枪服务
GunBusiness.InstanceSerialPort3();
//更新plc状态
var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("成品下线Plc"));
if (obj.plc.IsConnected)
@ -88,29 +91,17 @@ namespace Aucma.Core.ProductOffLine.ViewModels
{
PlcState(false);
}
//MvCodeHelper1.DeviceListAcq();//获取创建设备
// MvCodeHelper1.StartGrab(); // 开启触发扫码接收数据
Business.MvCodeHelper.Liner();
});
// 心跳线程
//Task.Run(() =>
//{
// while (true)
// {
// //扫码器心跳监测并重连
// MvCodeHelper.JudgeShellIsConnectedAndReConnect();
// Thread.Sleep(2000);
// }
//});
}
catch (Exception ex)
{
//MvCodeHelper.CloseAllDevice();
InitHikRobot();
log.Error("InitHikRobotAndGun()开启海康扫码器和扫码枪方法异常" + ex.Message.ToString());
}
}
#endregion

@ -5,15 +5,28 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Aucma.Core.ProductOffLine.Views"
mc:Ignorable="d" FontFamily="Microsoft YaHei" WindowStartupLocation="CenterScreen"
Title="选择放行方向" Height="300" Width="300">
Title="选择放行方向" Height="500" Width="700">
<Grid Background="#1152AC">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="97*"/>
<ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="50,0,0,0">
<Button Content="外侧提升机" Click="LeftButton_Click" Width="100" Height="50" HorizontalAlignment="Center" Margin="50 0 0 20"/>
<Button Content="内侧提升机" Click="RightButton_Click" Width="100" Height="50" HorizontalAlignment="Center" Margin="50 0 0 20"/>
</StackPanel>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Label Content="扫码枪扫描位置" FontSize="20" Foreground="White" HorizontalAlignment="Left" Margin="122,120,0,0" VerticalAlignment="Top" Height="50" Width="148"/>
<ComboBox Name="SelectedMaterialType" Margin="290,120,167,0" FontSize="30" Foreground="White" VerticalAlignment="Top">
<ComboBoxItem Content="外侧提升机" Foreground="Blue"/>
<ComboBoxItem Content="内侧提升机" Foreground="Blue" />
</ComboBox>
</Grid>
<Grid Grid.Row="1">
<Button Content="外侧提升机" Click="LeftButton_Click" Height="50" Width="130" Margin="162,66,210,126" Background="Green"/>
<Button Content="内侧提升机" Click="RightButton_Click" Height="50" Width="130" Margin="310,66,60,126" Background="Green" />
<Label Content="放行方向:" FontSize="20" Foreground="White" HorizontalAlignment="Left" Margin="125,66,0,0" VerticalAlignment="Top" Height="50" Width="97"/>
<Button Content="保存" FontSize="20" HorizontalAlignment="Left" Margin="554,178,0,0" VerticalAlignment="Top" Width="100" Height="45" Click="Button_Click"/>
</Grid>
<!--</StackPanel>-->
</Grid>
</Window>

@ -1,4 +1,5 @@
using Aucma.Core.ProductOffLine.Models;
using Aucma.Core.ProductOffLine.Config;
using Aucma.Core.ProductOffLine.Models;
using System;
using System.Collections.Generic;
using System.Linq;
@ -12,6 +13,7 @@ using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using static Aucma.Core.ProductOffLine.Business.OffLineBusiness;
namespace Aucma.Core.ProductOffLine.Views
{
@ -20,6 +22,8 @@ namespace Aucma.Core.ProductOffLine.Views
/// </summary>
public partial class ChooseDirectionWindow : Window
{
private AppConfig appConfig = AppConfig.Instance;
/// <summary>
/// 下发plc放行信号,传进来扫码器编号分垛方向A或者B,返回plc反馈结果
@ -35,6 +39,16 @@ namespace Aucma.Core.ProductOffLine.Views
public ChooseDirectionWindow()
{
InitializeComponent();
// 外侧
if (int.Parse(appConfig.GunDirection) == 0)
{
SelectedMaterialType.SelectedIndex = 0;
}
// 内侧
if (int.Parse(appConfig.GunDirection) == 1)
{
SelectedMaterialType.SelectedIndex = 1;
}
}
private void LeftButton_Click(object sender, RoutedEventArgs e)
@ -73,5 +87,17 @@ namespace Aucma.Core.ProductOffLine.Views
}
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
MessageBoxResult result = MessageBox.Show("确认保存吗?", "确认", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
{
Console.WriteLine(SelectedMaterialType.SelectedIndex);
appConfig.GunDirection = SelectedMaterialType.SelectedIndex.ToString();
this.Close();
}
}
}
}

@ -216,7 +216,7 @@
<Border Grid.Row="3" Grid.Column="5">
<Button Content="手动放行" Background="Green" FontSize="20" Width="150" Click="Button_Click"
<Button Content="异常放行" Background="Green" FontSize="20" Width="150" Click="Button_Click"
HorizontalAlignment="Stretch" Margin="0" />
</Border>
</Grid>

@ -47,7 +47,7 @@
</StackPanel>
<StackPanel Grid.Row="4" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button Content="登 录" FontSize="20" Command="{Binding SaveCommand}" Background="#FF36B5C1" BorderBrush="#FF36B5C1" Foreground="white" Margin="0,0,10,0" Height="50" Width="100" />
<Button Content="登 录" FontSize="20" Command="{Binding SaveCommand}" Background="#FF36B5C1" BorderBrush="#FF36B5C1" Foreground="white" Margin="0,0,10,0" Height="50" Width="100" Click="Button_Click" />
<Button Content="取 消" FontSize="20" Command="{Binding CloseWindowCommand}" CommandParameter="{Binding ElementName=window}" Background="#FF9900" Foreground="white" Margin="10,0,0,0" Height="50" BorderBrush="#FF9900" Width="100" />
</StackPanel>
</Grid>

@ -25,5 +25,10 @@ namespace Aucma.Core.ProductOffLine.Views
InitializeComponent();
this.DataContext = new LoginViewModel();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
}
}
}

Loading…
Cancel
Save