增加第三台打印机
This commit is contained in:
parent
1cbd295691
commit
2347c07d10
@ -219,6 +219,8 @@
|
|||||||
Binding="{Binding NetWeight}" />
|
Binding="{Binding NetWeight}" />
|
||||||
<DataGridTextColumn Header="控制号"
|
<DataGridTextColumn Header="控制号"
|
||||||
Binding="{Binding LastNo}" />
|
Binding="{Binding LastNo}" />
|
||||||
|
<DataGridTextColumn Header="主标签颜色"
|
||||||
|
Binding="{Binding LabelColor}" />
|
||||||
|
|
||||||
<DataGridTemplateColumn Header="操作">
|
<DataGridTemplateColumn Header="操作">
|
||||||
<DataGridTemplateColumn.CellTemplate>
|
<DataGridTemplateColumn.CellTemplate>
|
||||||
|
@ -106,10 +106,10 @@ public class HyosungPlcService(ILogger<HyosungPlcService> logger) : IHyosungPlcS
|
|||||||
await _writer.WriteShortsAsync(12120, ls.ToArray());
|
await _writer.WriteShortsAsync(12120, ls.ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task WritePrintLableOptionsAsync(int side, int slave)
|
public async Task WritePrintLabelOptionsAsync(int master, int slave, int color)
|
||||||
{
|
{
|
||||||
short masterCount = 0;
|
short masterCount = 0;
|
||||||
switch (side)
|
switch (master)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
masterCount = 1;
|
masterCount = 1;
|
||||||
@ -148,12 +148,19 @@ public class HyosungPlcService(ILogger<HyosungPlcService> logger) : IHyosungPlcS
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
await _writer.WriteShortsAsync(13050, [1, 1, 1, 2]);
|
if (color == 1)
|
||||||
|
await _writer.WriteShortsAsync(13050, [1, 1, 1, 2]);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await _writer.WriteShortsAsync(13056, 2);
|
||||||
|
//todo:此处是写副标签的,后续测试无问题则需要修改此处
|
||||||
|
await _writer.WriteShortsAsync(13052, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task WritePrintLabelResultAsync(int index, bool result)
|
public async Task WritePrintLabelResultAsync(int index, bool result)
|
||||||
{
|
{
|
||||||
var address = index == 1 ? 13060 : 13061;
|
var address = 13059 + index;
|
||||||
|
|
||||||
await _writer.WriteShortsAsync(address, (short)(result ? 1 : 2));
|
await _writer.WriteShortsAsync(address, (short)(result ? 1 : 2));
|
||||||
}
|
}
|
||||||
@ -375,7 +382,7 @@ public class HyosungPlcService(ILogger<HyosungPlcService> logger) : IHyosungPlcS
|
|||||||
|
|
||||||
private async Task QueryPrintLabel()
|
private async Task QueryPrintLabel()
|
||||||
{
|
{
|
||||||
var requestPrintLabel = await _reader.ReadShortsAsync(13010, 3);
|
var requestPrintLabel = await _reader.ReadShortsAsync(13010, 4);
|
||||||
if (requestPrintLabel[0] == 1)
|
if (requestPrintLabel[0] == 1)
|
||||||
{
|
{
|
||||||
await _writer.WriteShortsAsync(13010, 0);
|
await _writer.WriteShortsAsync(13010, 0);
|
||||||
@ -389,5 +396,12 @@ public class HyosungPlcService(ILogger<HyosungPlcService> logger) : IHyosungPlcS
|
|||||||
await _writer.WriteShortsAsync(13012, 0);
|
await _writer.WriteShortsAsync(13012, 0);
|
||||||
OnRequestPrintLabel?.Invoke(2, requestPrintLabel[2]);
|
OnRequestPrintLabel?.Invoke(2, requestPrintLabel[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (requestPrintLabel[3] == 1)
|
||||||
|
{
|
||||||
|
await _writer.WriteShortsAsync(13013, 0);
|
||||||
|
await _writer.WriteShortsAsync(13012, 0);
|
||||||
|
OnRequestPrintLabel?.Invoke(3, requestPrintLabel[2]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -58,11 +58,11 @@ public interface IHyosungPlcService
|
|||||||
|
|
||||||
Task WritePackLineOptionAsync(PackLineOption option);
|
Task WritePackLineOptionAsync(PackLineOption option);
|
||||||
|
|
||||||
Task WritePrintLableOptionsAsync(int side,int slaveCount);
|
Task WritePrintLabelOptionsAsync(int masterCount, int slaveCount, int color);
|
||||||
|
|
||||||
|
Task WritePrintLabelResultAsync(int index, bool result);
|
||||||
|
|
||||||
|
|
||||||
Task WritePrintLabelResultAsync(int index, bool result);
|
|
||||||
|
|
||||||
|
|
||||||
Task WriteScanEntryResultAsync(int index, bool result);
|
Task WriteScanEntryResultAsync(int index, bool result);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -101,6 +101,6 @@ public interface IHyosungPlcService
|
|||||||
event Func<int, int, Task> OnRequestPrintLabel;
|
event Func<int, int, Task> OnRequestPrintLabel;
|
||||||
|
|
||||||
event Func<string, Task> OnRequestGetPrintLableOption;
|
event Func<string, Task> OnRequestGetPrintLableOption;
|
||||||
|
|
||||||
event Func<int, Task> OnRequestScanEntry;
|
event Func<int, Task> OnRequestScanEntry;
|
||||||
}
|
}
|
@ -15,55 +15,58 @@ public class HyosungPrinter(
|
|||||||
IHyosungWmsService hyosungWmsService,
|
IHyosungWmsService hyosungWmsService,
|
||||||
IOptions<PrintTemp> options) : IHyosungPrinter
|
IOptions<PrintTemp> options) : IHyosungPrinter
|
||||||
{
|
{
|
||||||
private readonly AveryPrinter _masterPrinter = new("192.168.3.61", 9100);
|
private readonly Dictionary<int, AveryPrinter> _printers = new Dictionary<int, AveryPrinter>()
|
||||||
private readonly AveryPrinter _slavePrinter = new("192.168.3.60", 9100);
|
{
|
||||||
|
{ 1001, new AveryPrinter("192.168.3.61", 9100) },
|
||||||
|
{ 2, new AveryPrinter("192.168.3.62", 9100) },
|
||||||
|
{ 1, new AveryPrinter("192.168.3.60", 9100) }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
public async Task StartAsync(CancellationToken token)
|
public async Task StartAsync(CancellationToken token)
|
||||||
{
|
{
|
||||||
List<Task> ls = new List<Task>();
|
List<Task> ls = new List<Task>();
|
||||||
ls.Add(_masterPrinter.ConnectAsync(token));
|
foreach (var (_, printer) in _printers)
|
||||||
ls.Add(_slavePrinter.ConnectAsync(token));
|
{
|
||||||
|
ls.Add(printer.ConnectAsync(token));
|
||||||
|
}
|
||||||
|
|
||||||
await Task.WhenAll(ls);
|
await Task.WhenAll(ls);
|
||||||
logger.LogInformation("printer connected");
|
logger.LogInformation("printer connected");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task StopAsync(CancellationToken token)
|
public async Task StopAsync(CancellationToken token)
|
||||||
{
|
{
|
||||||
await _masterPrinter.CloseAsync(token);
|
foreach (var (_, printer) in _printers)
|
||||||
await _slavePrinter.CloseAsync(token);
|
{
|
||||||
|
printer.CloseAsync(token);
|
||||||
|
}
|
||||||
|
|
||||||
logger.LogInformation("printer disconnected");
|
logger.LogInformation("printer disconnected");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task PrintAsync(int index, string trayCode)
|
public async Task PrintMasterLabelAsync(int color, string trayCode)
|
||||||
{
|
{
|
||||||
var tray = await trayService.GetByCode(trayCode);
|
var tray = await trayService.GetByCode(trayCode);
|
||||||
if (index == 1)
|
var content = await GetMasterLabelContent(tray);
|
||||||
{
|
await _printers[color].CleanContextAsync();
|
||||||
await PrintLabel1Async(tray);
|
await _printers[color].SendContentAsync(content);
|
||||||
}
|
await _printers[color].PrintAsync();
|
||||||
else
|
|
||||||
{
|
|
||||||
await PrintLabel2Async(tray);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task PrintLabel1Async(Tray tray)
|
public async Task PrintSubLabelAsync(string trayCode)
|
||||||
{
|
{
|
||||||
await _masterPrinter.CleanContextAsync();
|
var tray = await trayService.GetByCode(trayCode);
|
||||||
var content = await GetPrint1Content(tray);
|
var content = await GetSubLabelContentAsync(tray);
|
||||||
await _masterPrinter.SendContentAsync(content);
|
await _printers[1001].CleanContextAsync();
|
||||||
await _masterPrinter.PrintAsync();
|
await _printers[1001].SendContentAsync(content);
|
||||||
|
await _printers[1001].PrintAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task PrintLabel2Async(Tray tray)
|
|
||||||
{
|
|
||||||
await _slavePrinter.CleanContextAsync();
|
|
||||||
var content = await GetPrint2Content(tray);
|
|
||||||
await _slavePrinter.SendContentAsync(content);
|
|
||||||
await _slavePrinter.PrintAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<string> GetPrint1Content(Tray tray)
|
|
||||||
|
|
||||||
|
private async Task<string> GetSubLabelContentAsync(Tray tray)
|
||||||
{
|
{
|
||||||
var variety = await varietyService.GetById(tray.VarietyId);
|
var variety = await varietyService.GetById(tray.VarietyId);
|
||||||
var yarns = await yarnService.GetYarnsByTrayIdAsync(tray.Id);
|
var yarns = await yarnService.GetYarnsByTrayIdAsync(tray.Id);
|
||||||
@ -100,7 +103,7 @@ public class HyosungPrinter(
|
|||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<string> GetPrint2Content(Tray tray)
|
private async Task<string> GetMasterLabelContent(Tray tray)
|
||||||
{
|
{
|
||||||
var variety = await varietyService.GetById(tray.VarietyId);
|
var variety = await varietyService.GetById(tray.VarietyId);
|
||||||
|
|
||||||
@ -128,6 +131,7 @@ public class HyosungPrinter(
|
|||||||
{
|
{
|
||||||
content = content.Replace(key, value);
|
content = content.Replace(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.LogInformation($"print content: {content}");
|
logger.LogInformation($"print content: {content}");
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,9 @@ public interface IHyosungPrinter
|
|||||||
|
|
||||||
Task StopAsync(CancellationToken token);
|
Task StopAsync(CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 打印指定垛的标签
|
|
||||||
/// </summary>
|
Task PrintMasterLabelAsync(int color, string trayCode);
|
||||||
/// <param name="trayCode"></param>
|
|
||||||
/// <returns></returns>
|
Task PrintSubLabelAsync(string trayCode);
|
||||||
Task PrintAsync(int index,string trayCode);
|
|
||||||
}
|
}
|
@ -84,6 +84,9 @@ public class VarietyEntity
|
|||||||
[SugarColumn(ColumnDescription = "副标签数量")]
|
[SugarColumn(ColumnDescription = "副标签数量")]
|
||||||
public int SubLabelCount { get; set; }
|
public int SubLabelCount { get; set; }
|
||||||
|
|
||||||
|
[SugarColumn(ColumnDescription = "标签颜色 1=红色 2=黑色")]
|
||||||
|
public int LabelColor { get; set; }
|
||||||
|
|
||||||
[SugarColumn(IsNullable = true)] public int? LastNo { get; set; }
|
[SugarColumn(IsNullable = true)] public int? LastNo { get; set; }
|
||||||
|
|
||||||
[SugarColumn(IsNullable = true)] public double? NetWeight { get; set; }
|
[SugarColumn(IsNullable = true)] public double? NetWeight { get; set; }
|
||||||
|
@ -70,6 +70,8 @@ public class Variety
|
|||||||
|
|
||||||
public double? GrossWeight { get; set; }
|
public double? GrossWeight { get; set; }
|
||||||
|
|
||||||
|
public int LabelColor { get; set; }
|
||||||
|
|
||||||
public static Variety Create(VarietyEntity entity, List<PalletEntity> pallets)
|
public static Variety Create(VarietyEntity entity, List<PalletEntity> pallets)
|
||||||
{
|
{
|
||||||
var variety = new Variety()
|
var variety = new Variety()
|
||||||
@ -101,7 +103,8 @@ public class Variety
|
|||||||
HasBox = entity.HasBox,
|
HasBox = entity.HasBox,
|
||||||
LastNo = entity.LastNo,
|
LastNo = entity.LastNo,
|
||||||
NetWeight = entity.NetWeight,
|
NetWeight = entity.NetWeight,
|
||||||
GrossWeight = entity.GrossWeight
|
GrossWeight = entity.GrossWeight,
|
||||||
|
LabelColor = entity.LabelColor,
|
||||||
};
|
};
|
||||||
if (entity.PaperTrayId != null && entity.PaperTrayId != 0)
|
if (entity.PaperTrayId != null && entity.PaperTrayId != 0)
|
||||||
variety.PaperTray = Pallet.FromEntity(pallets.First(x => x.Id == entity.PaperTrayId));
|
variety.PaperTray = Pallet.FromEntity(pallets.First(x => x.Id == entity.PaperTrayId));
|
||||||
@ -141,7 +144,8 @@ public class Variety
|
|||||||
HasBox = HasBox,
|
HasBox = HasBox,
|
||||||
LastNo = LastNo,
|
LastNo = LastNo,
|
||||||
NetWeight = NetWeight,
|
NetWeight = NetWeight,
|
||||||
GrossWeight = GrossWeight
|
GrossWeight = GrossWeight,
|
||||||
|
LabelColor = LabelColor,
|
||||||
};
|
};
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
@ -375,7 +375,8 @@ public class HyosungRuntime(
|
|||||||
var mod = await hyosungWmsService.GetItemInfoByItemCode(variety.Code);
|
var mod = await hyosungWmsService.GetItemInfoByItemCode(variety.Code);
|
||||||
_ = await trayService.PrintTrayAsync(arg, mod, variety);
|
_ = await trayService.PrintTrayAsync(arg, mod, variety);
|
||||||
await dictService.SetValue("System", "CurrentPackingTrayCode", arg);
|
await dictService.SetValue("System", "CurrentPackingTrayCode", arg);
|
||||||
await hyosungPlcService.WritePrintLableOptionsAsync(variety.MasterLabelCount, variety.SubLabelCount);
|
await hyosungPlcService.WritePrintLabelOptionsAsync(variety.MasterLabelCount, variety.SubLabelCount,
|
||||||
|
variety.LabelColor);
|
||||||
logger.LogInformation("request print option succeed");
|
logger.LogInformation("request print option succeed");
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -403,19 +404,16 @@ public class HyosungRuntime(
|
|||||||
{
|
{
|
||||||
if (arg1 == 1)
|
if (arg1 == 1)
|
||||||
{
|
{
|
||||||
await printer.PrintAsync(1, tray.TrayCode);
|
await printer.PrintSubLabelAsync(tray.TrayCode);
|
||||||
await hyosungPlcService.WritePrintLabelResultAsync(arg1, true);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await printer.PrintAsync(2, tray.TrayCode);
|
await printer.PrintMasterLabelAsync(arg1 - 1, tray.TrayCode);
|
||||||
await hyosungPlcService.WritePrintLabelResultAsync(arg1, true);
|
// await hyosungWmsService.AddLabelResult(new LabelResult(tray, variety));
|
||||||
//var version = await hyosungWmsService.GetItemInfoByItemCode(variety.Code);
|
|
||||||
// await varietyService.SetLastNo(variety.Id, tray.ControlNo.Value);
|
|
||||||
//await hyosungWmsService.UpdateControlNo(variety, tray.ControlNo.Value);
|
|
||||||
// await hyosungWmsService.AddLabelResult(new LabelResult(tray, variety));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await hyosungPlcService.WritePrintLabelResultAsync(arg1, true);
|
||||||
|
|
||||||
logger.LogInformation($"plc request print label success");
|
logger.LogInformation($"plc request print label success");
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -1,8 +1,4 @@
|
|||||||
using System.Windows;
|
using Seyounth.Hyosung.ViewModels;
|
||||||
using Seyounth.Hyosung.Data.Models;
|
|
||||||
using Seyounth.Hyosung.Data.Services;
|
|
||||||
using Seyounth.Hyosung.Runtime;
|
|
||||||
using Seyounth.Hyosung.ViewModels;
|
|
||||||
using Seyounth.Hyosung.Views.Pages;
|
using Seyounth.Hyosung.Views.Pages;
|
||||||
|
|
||||||
namespace Seyounth.Hyosung.Views;
|
namespace Seyounth.Hyosung.Views;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user