change-测试版

foamRearStore
liuwf 8 months ago
parent 8f79ff027d
commit 5d47a04f7b

Binary file not shown.

@ -12,6 +12,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using static Aucma.Core.Scanner.MvCodeHelper;
using static Aucma.Scada.Business.InStoreTaskHandle;
namespace Aucma.Scada.Business
@ -115,9 +116,10 @@ namespace Aucma.Scada.Business
_productPlanInfoServices = registerServices.GetService<IProductPlanInfoService>();
taskHandle.InStoreFinsihEvent += InStoreFinish;
taskHandle.InStoreAnswerEvent += InStoreAnswer;
MvCodeHelper.RefreshMaterialCodeStrEvent += InStore;
MvCodeHelper.RefreshLogMessageEvent += PrintLogInfoMessage;
MvCodeHelper.MessageNoReadEvent += MessageNoRead;
StartPassDown();
@ -191,6 +193,9 @@ namespace Aucma.Scada.Business
{
try
{
// plc报警信息清除
taskHandle.SendPlcWarnInfo(0);
PrintLogInfoMessage($"扫码成功,物料码:{materialCode}");
string materialType = SubStringMaterialCode(materialCode);
// 加防呆,判断任务表是否有任务了
@ -228,6 +233,9 @@ namespace Aucma.Scada.Business
{
//报警停线
PrintLogInfoMessage($"物料码:{materialCode};未匹配到可用货道");
// 下发plc报警信息
taskHandle.SendPlcWarnInfo(2);
}
}
catch (Exception ex)
@ -475,6 +483,20 @@ namespace Aucma.Scada.Business
logHelper.Info(message);
}
/// <summary>
/// 未扫描上条码
/// </summary>
/// <param name="message"></param>
private void MessageNoRead()
{
PrintLogInfoMessage("PrintLogInfoMessage");
// 下发plc报警信号
taskHandle.SendPlcWarnInfo(1);
}
/// <summary>
/// 异常日志输出
/// </summary>
@ -575,7 +597,7 @@ namespace Aucma.Scada.Business
if (list.Count > 0)
{
result = list.OrderByDescending(x => x.spaceStock).OrderBy(x => x.spaceCode).First();
result = list.OrderByDescending(x => x.spaceStock).First();
}
}
}

@ -116,20 +116,27 @@ namespace Aucma.Scada.Business
{
Task.Run(() =>
{
Thread.Sleep(3000);
IPlc _plc = _plcDictionary[appConfig.foamStoreCode];
if (_plc != null)
try
{
while (true)
Thread.Sleep(3000);
IPlc _plc = _plcDictionary[appConfig.foamStoreCode];
if (_plc != null)
{
_plc.writeInt32ByAddress("D7020",1);
Thread.Sleep(1000);
_plc.writeInt32ByAddress("D7020", 0);
Thread.Sleep(1000);
while (true)
{
_plc.writeInt32ByAddress("D7020", 1);
Thread.Sleep(1000);
_plc.writeInt32ByAddress("D7020", 0);
Thread.Sleep(1000);
}
}
}
}
catch (Exception ex)
{
logHelper.Error(ex.Message.ToString());
}
});
}
#region 判断入库是否完成 delete20240224-入库完成信号改回监测在途数
@ -271,8 +278,7 @@ namespace Aucma.Scada.Business
if (_plc != null)
{
// 测试方法模拟plc正式启用删除
// _plc.writeInt32ByAddress(plcConfig.in_foam_answer, 1);
if (_plc.readInt32ByAddress(plcConfig.in_foam_answer) == 1)
{
logHelper.Info("泡后入库应答字为1货道号:" + plcConfig.in_foam_spaceCode + ";写" + short.Parse(taskInfo.spaceCode.Substring(5, 1)));
@ -359,14 +365,39 @@ namespace Aucma.Scada.Business
}
}
}
#endregion
#endregion
/// <summary>
/// 通过PLC获取货道信息
/// </summary>
/// <param name="spaceInfo"></param>
/// <returns></returns>
public BaseSpaceInfo ReadSpaceInfoByPlc(BaseSpaceInfo spaceInfo)
/// <summary>
/// 0正常清除plc报警信息1-扫码失败2-库满,未匹配到可用货道
/// </summary>
/// <param name="flag"></param>
#region 泡后库plc报警信息
public void SendPlcWarnInfo(short flag)
{
try
{
IPlc _plc = _plcDictionary[appConfig.foamStoreCode];
if (_plc != null)
{
_plc.writeInt32ByAddress("D7018", flag);
}
}
catch (Exception ex)
{
logHelper.Error(ex.Message.ToString());
}
}
#endregion
/// <summary>
/// 通过PLC获取货道信息
/// </summary>
/// <param name="spaceInfo"></param>
/// <returns></returns>
public BaseSpaceInfo ReadSpaceInfoByPlc(BaseSpaceInfo spaceInfo)
{
var spaceAddress = spaceConfig.GetSpaceAddress(spaceInfo.storeCode, spaceInfo.spaceCode);
IPlc _plc = _plcDictionary[spaceInfo.storeCode];

@ -782,7 +782,7 @@ namespace Aucma.Scada.Business
if (list.Count > 0)
{
result = info.OrderBy(x => x.spaceStock).OrderBy(x => x.spaceCode).First();
result = info.OrderBy(x => x.spaceStock).First();
}
else
{

@ -14,10 +14,35 @@ namespace Aucma.Core.Scanner
{
public class MvCodeHelper
{
private static LogHelper logHelper = LogHelper.Instance;
private static AppConfig appConfig = AppConfig.Instance;
public static bool m_bGrabbing = true;
private static string SheellLastCode;
// 箱壳扫码器ip
private static string ShellScannerIp = appConfig.foamHikRobotIp;
#region 全局变量定义
public static DateTime ShellLiveTime = DateTime.Now;
#endregion
#region 委托事件
/// <summary>
/// 刷新扫码器状态
/// </summary>
/// <param name="materialCodeStr"></param>
/// <param name="ip"></param>
public delegate void RefreshState(bool flag);
public static event RefreshState RefreshStateEvent;
//NoRead事件通知
public delegate void MessageNoRead();
public static event MessageNoRead MessageNoReadEvent;
public delegate void RefreshMaterialCodeStr(string materialCodeStr);
public static event RefreshMaterialCodeStr RefreshMaterialCodeStrEvent;
/// <summary>
@ -28,266 +53,224 @@ namespace Aucma.Core.Scanner
public static event RefreshLogMessage RefreshLogMessageEvent;
#endregion
// 获取到的所有设备
public static MvCodeReader.MV_CODEREADER_DEVICE_INFO_LIST m_stDeviceList = new MvCodeReader.MV_CODEREADER_DEVICE_INFO_LIST();
public static void ShellImageCallbackFunc(IntPtr pData, IntPtr pstFrameInfoEx2, IntPtr pUser)
{
var stFrameInfo = (MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2)Marshal.PtrToStructure(pstFrameInfoEx2, typeof(MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2));
// (成功创建)连接上的设备和其ip(string)集合
public static Dictionary<MvCodeReader, string> m_cMyDevices = new Dictionary<MvCodeReader, string>();
MvCodeReader.MV_CODEREADER_RESULT_BCR_EX2 stBcrResult = (MvCodeReader.MV_CODEREADER_RESULT_BCR_EX2)Marshal.PtrToStructure(stFrameInfo.UnparsedBcrList.pstCodeListEx2, typeof(MvCodeReader.MV_CODEREADER_RESULT_BCR_EX2));
#region 设备连接状态
/// <summary>
/// 获取不到任务设备即连接失败
/// </summary>
/// <returns></returns>
public static bool ConnectionStatus(string ip)
{
try
// Console.WriteLine("CodeNum[" + Convert.ToString(stBcrResult.nCodeNum) + "]");
if (stBcrResult.nCodeNum == 0)
{
// 遍历所有已打开相机
foreach (KeyValuePair<MvCodeReader, string> hashmap in m_cMyDevices)
//更新扫码器存活时间
ShellLiveTime = DateTime.Now;
Console.WriteLine("箱壳No Read 处理");
MessageNoReadEvent();
}
for (Int32 i = 0; i < stBcrResult.nCodeNum; i++)
{
bool bIsValidUTF8 = IsTextUTF8(stBcrResult.stBcrInfoEx2[i].chCode);
if (bIsValidUTF8)
{
string strCode = Encoding.UTF8.GetString(stBcrResult.stBcrInfoEx2[i].chCode);
Console.WriteLine("Get CodeNum: " + "CodeNum[" + i.ToString() + "], CodeString[" + strCode.Trim().TrimEnd('\0') + "]");
}
else
{
if (ip.Equals(hashmap.Value))
string strCode = Encoding.GetEncoding("GB2312").GetString(stBcrResult.stBcrInfoEx2[i].chCode);
Console.WriteLine(DateTime.Now + ":箱壳扫码器==>Get CodeNum: " + "CodeNum[" + i.ToString() + "], CodeString[" + strCode.Trim().TrimEnd('\0') + "]");
if (string.IsNullOrEmpty(SheellLastCode) || SheellLastCode != strCode.Trim().TrimEnd('\0'))
{
//更新扫码器存活时间
ShellLiveTime = DateTime.Now;
RefreshMaterialCodeStrEvent?.Invoke(strCode.Trim().TrimEnd('\0'));
SheellLastCode = strCode.Trim().TrimEnd('\0');
}
if (SheellLastCode == strCode.Trim().TrimEnd('\0'))
{
return true;
Console.WriteLine("箱壳和上次扫描结果一样,不作处理");
}
}
// 没有连接上,重新获取并创建设备
Task.Run(() =>
{
DeviceListAcq();
});
}
catch (Exception ex)
MvCodeReader.MV_CODEREADER_OCR_INFO_LIST stOcrInfo = (MvCodeReader.MV_CODEREADER_OCR_INFO_LIST)Marshal.PtrToStructure(stFrameInfo.UnparsedOcrList.pstOcrList, typeof(MvCodeReader.MV_CODEREADER_OCR_INFO_LIST));
for (int i = 0; i < stOcrInfo.nOCRAllNum; i++)
{
logHelper.Error(ex.Message.ToString());
string strOcrCharCode = Encoding.UTF8.GetString(stOcrInfo.stOcrRowInfo[i].chOcr);
Console.WriteLine("Get OcrInfo:" + "ocrNum[" + i.ToString() + "], ocrLen[" + Convert.ToString(stOcrInfo.stOcrRowInfo[i].nOcrLen) + "], ocrChar[" + strOcrCharCode.Trim().TrimEnd('\0') + "]");
}
return false;
}
#endregion
#region 获取并创建设备列表
/// <summary>
/// 获取并创建设备列表
/// </summary>
public static void DeviceListAcq()
public static void Shell()
{
try
ShellLiveTime = DateTime.Now;
MvCodeReader.cbOutputEx2delegate ImageCallback;
MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2 stFrameInfo = new MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2();
MvCodeReader device = new MvCodeReader();
int nRet = MvCodeReader.MV_CODEREADER_OK;
do
{
// RefreshLogMessageEvent?.Invoke("获取扫码器设备列表,进入DeviceListAcq()方法");
// 扫码器ip
string scannerIp = appConfig.foamHikRobotIp;
if (string.IsNullOrEmpty(scannerIp)) return;
System.GC.Collect();
m_stDeviceList.nDeviceNum = 0;
// 获取设备列表
int nRet = MvCodeReader.MV_CODEREADER_EnumDevices_NET(ref m_stDeviceList, MvCodeReader.MV_CODEREADER_GIGE_DEVICE);
if (0 != nRet)
// ch:枚举设备 | en:Enum device
MvCodeReader.MV_CODEREADER_DEVICE_INFO_LIST stDevList = new MvCodeReader.MV_CODEREADER_DEVICE_INFO_LIST();
nRet = MvCodeReader.MV_CODEREADER_EnumDevices_NET(ref stDevList, MvCodeReader.MV_CODEREADER_GIGE_DEVICE);
if (MvCodeReader.MV_CODEREADER_OK != nRet)
{
logHelper.Info("获取扫码器列表失败,扫码器错误码:" + nRet);
RefreshLogMessageEvent?.Invoke("获取扫码器列表失败,扫码器错误码:" + nRet);
return;
}
// 刷新扫码器状态
RefreshStateEvent?.Invoke(false);
if (0 == m_stDeviceList.nDeviceNum)
{
// RefreshLogMessageEvent?.Invoke("获取扫码器数量为0请检查扫码器连接:");
return;
RefreshStateEvent?.Invoke(false);
Thread.Sleep(1000 * 10);
Console.WriteLine("Enum device failed:{0:x8}", nRet);
break;
}
Console.WriteLine("Enum device count : " + Convert.ToString(stDevList.nDeviceNum));
if (0 == stDevList.nDeviceNum)
{
// 刷新扫码器状态
RefreshStateEvent?.Invoke(false);
MvCodeReader m_cMyDevice = new MvCodeReader();
RefreshStateEvent?.Invoke(false);
Thread.Sleep(1000 * 10);
//创建所有设备
for (int i = 0; i < m_stDeviceList.nDeviceNum; i++)
break;
}
MvCodeReader.MV_CODEREADER_DEVICE_INFO stDevInfo; // 通用设备信息
int nDevIndex = -1;
// ch:打印设备信息 | en:Print device info
for (Int32 i = 0; i < stDevList.nDeviceNum; i++)
{
MvCodeReader.MV_CODEREADER_DEVICE_INFO stDevInfo = (MvCodeReader.MV_CODEREADER_DEVICE_INFO)Marshal.PtrToStructure(m_stDeviceList.pDeviceInfo[i], typeof(MvCodeReader.MV_CODEREADER_DEVICE_INFO));
if (stDevInfo.nTLayerType == MvCodeReader.MV_CODEREADER_GIGE_DEVICE)
stDevInfo = (MvCodeReader.MV_CODEREADER_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[i], typeof(MvCodeReader.MV_CODEREADER_DEVICE_INFO));
if (MvCodeReader.MV_CODEREADER_GIGE_DEVICE == stDevInfo.nTLayerType)
{
IntPtr buffer = Marshal.UnsafeAddrOfPinnedArrayElement(stDevInfo.SpecialInfo.stGigEInfo, 0);
MvCodeReader.MV_CODEREADER_GIGE_DEVICE_INFO stGigEDeviceInfo = (MvCodeReader.MV_CODEREADER_GIGE_DEVICE_INFO)Marshal.PtrToStructure(buffer, typeof(MvCodeReader.MV_CODEREADER_GIGE_DEVICE_INFO));
// 获取ip
string ip = ((stGigEDeviceInfo.nCurrentIp & 0xff000000) >> 24) + "." + ((stGigEDeviceInfo.nCurrentIp & 0x00ff0000) >> 16) + "." + ((stGigEDeviceInfo.nCurrentIp & 0x0000ff00) >> 8) + "." + (stGigEDeviceInfo.nCurrentIp & 0x000000ff);
// 只连接配置的扫码器
if (!scannerIp.Equals(ip)) continue;
// 创建第i个设备
stDevInfo = (MvCodeReader.MV_CODEREADER_DEVICE_INFO)Marshal.PtrToStructure(m_stDeviceList.pDeviceInfo[i], typeof(MvCodeReader.MV_CODEREADER_DEVICE_INFO));
nRet = m_cMyDevice.MV_CODEREADER_CreateHandle_NET(ref stDevInfo);//创建设备
if (MvCodeReader.MV_CODEREADER_OK != nRet)
MvCodeReader.MV_CODEREADER_GIGE_DEVICE_INFO stGigEDeviceInfo = (MvCodeReader.MV_CODEREADER_GIGE_DEVICE_INFO)MvCodeReader.ByteToStruct(stDevInfo.SpecialInfo.stGigEInfo, typeof(MvCodeReader.MV_CODEREADER_GIGE_DEVICE_INFO));
uint nIp1 = ((stGigEDeviceInfo.nCurrentIp & 0xff000000) >> 24);
uint nIp2 = ((stGigEDeviceInfo.nCurrentIp & 0x00ff0000) >> 16);
uint nIp3 = ((stGigEDeviceInfo.nCurrentIp & 0x0000ff00) >> 8);
uint nIp4 = (stGigEDeviceInfo.nCurrentIp & 0x000000ff);
// Console.WriteLine("\n" + i.ToString() + ": [GigE] User Define Name : " + stGigEDeviceInfo.chUserDefinedName);
// Console.WriteLine("device IP :" + nIp1 + "." + nIp2 + "." + nIp3 + "." + nIp4);
string ipStr = nIp1 + "." + nIp2 + "." + nIp3 + "." + nIp4;
if (ipStr == ShellScannerIp)
{
// Console.WriteLine("创建第" + i + "个扫码器设备失败,ip:" + ip);
return;
}
// 打开设备
nRet = m_cMyDevice.MV_CODEREADER_OpenDevice_NET();
if (MvCodeReader.MV_CODEREADER_OK != nRet)
{
m_cMyDevice.MV_CODEREADER_DestroyHandle_NET();
// Console.WriteLine("Device open fail!");
return;
}
// RefreshLogMessageEvent?.Invoke("创建并打开第" + i + "个扫码器设备成功,ip:" + ip);
//设置触发模式
nRet = m_cMyDevice.MV_CODEREADER_SetEnumValue_NET("TriggerMode", (uint)MvCodeReader.MV_CODEREADER_TRIGGER_MODE.MV_CODEREADER_TRIGGER_MODE_ON);
if (MvCodeReader.MV_CODEREADER_OK != nRet)
{
// Console.WriteLine("设置触发模式失败");
return;
nDevIndex = i;
Console.WriteLine("device IP :" + ipStr);
}
//添加到集合
m_cMyDevices.Add(m_cMyDevice, ip);
}
}
}
catch (Exception ex)
{
logHelper.Error("获取和创建扫码器设备异常:" + ex.Message.ToString());
}
}
#endregion
if (nDevIndex < 0)
{
Console.WriteLine("未找到箱壳扫码器");
// 刷新扫码器状态
RefreshStateEvent?.Invoke(false);
Thread.Sleep(1000 * 30);
break;
}
stDevInfo = (MvCodeReader.MV_CODEREADER_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[nDevIndex], typeof(MvCodeReader.MV_CODEREADER_DEVICE_INFO));
#region 光电触发扫码器接收条码处理业务
public static void StartGrab()
{
try
{
int nRet = MvCodeReader.MV_CODEREADER_OK;
// 3.开启抓图
int nCount = 0;
IntPtr pData = IntPtr.Zero;
MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2 stFrameInfoEx2 = new MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2();
IntPtr pstFrameInfoEx2 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2)));
Marshal.StructureToPtr(stFrameInfoEx2, pstFrameInfoEx2, false);
foreach (KeyValuePair<MvCodeReader, string> hashmap in m_cMyDevices)
// ch:创建设备 | en:Create device
nRet = device.MV_CODEREADER_CreateHandle_NET(ref stDevInfo);
if (MvCodeReader.MV_CODEREADER_OK != nRet)
{
nRet = hashmap.Key.MV_CODEREADER_StartGrabbing_NET();
while (m_bGrabbing)
{
// 光电触发了有图像
nRet = hashmap.Key.MV_CODEREADER_GetOneFrameTimeoutEx2_NET(ref pData, pstFrameInfoEx2, 1000);
// ch:获取一帧图像 | en:Get one image
if (MvCodeReader.MV_CODEREADER_OK == nRet)
{
stFrameInfoEx2 = (MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2)Marshal.PtrToStructure(pstFrameInfoEx2, typeof(MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2));
// 分配条码内存空间
MvCodeReader.MV_CODEREADER_RESULT_BCR_EX2 stBcrResult = (MvCodeReader.MV_CODEREADER_RESULT_BCR_EX2)Marshal.PtrToStructure(stFrameInfoEx2.UnparsedBcrList.pstCodeListEx2, typeof(MvCodeReader.MV_CODEREADER_RESULT_BCR_EX2));
for (int i = 0; i < stBcrResult.nCodeNum; ++i)
{
bool bIsValidUTF8 = IsTextUTF8(stBcrResult.stBcrInfoEx2[i].chCode);
if (bIsValidUTF8)
{
// string strCode = System.Text.Encoding.Default.GetString(stBcrResult.stBcrInfoEx2[i].chCode);
string strCode = Encoding.UTF8.GetString(stBcrResult.stBcrInfoEx2[i].chCode);
// logHelper.Info("bIsValidUTF8:: Get CodeNum: " + "CodeNum[" + i.ToString() + "], CodeString[" + strCode.Trim().TrimEnd('\0') + "]");
}
else
{
byte[] buffer = new byte[22];
if (stBcrResult.stBcrInfoEx2[i].chCode.Length > 0)
{
Array.Copy(stBcrResult.stBcrInfoEx2[i].chCode, buffer, 22);
}
string strCode = Encoding.GetEncoding("UTF-8").GetString(buffer).Trim().TrimEnd('\0');
// RefreshLogMessageEvent?.Invoke("相机ip:" + hashmap.Value + " Get CodeNum: " + "CodeNum[" + i.ToString() + "], CodeString[" + strCode + "]");
if (!string.IsNullOrEmpty(strCode))
{
logHelper.Info("扫码器扫描到条码:"+strCode);
// 获取到条码处理业务
RefreshMaterialCodeStrEvent?.Invoke(strCode);
}
}
}
}
Thread.Sleep(500);
Console.WriteLine("Create device failed:{0:x8}", nRet);
// 刷新扫码器状态
RefreshStateEvent?.Invoke(false);
break;
}
}
// ch:打开设备 | en:Open device
nRet = device.MV_CODEREADER_OpenDevice_NET();
if (MvCodeReader.MV_CODEREADER_OK != nRet)
{
Console.WriteLine("Open device failed:{0:x8}", nRet);
// 刷新扫码器状态
RefreshStateEvent?.Invoke(false);
break;
}
}
catch (Exception ex)
{
Console.WriteLine("扫码异常:" + ex);
}
}
#endregion
// 刷新扫码器状态
RefreshStateEvent?.Invoke(true);
// ch:注册回调函数 | en:Register image callback
ImageCallback = new MvCodeReader.cbOutputEx2delegate(ShellImageCallbackFunc);
nRet = device.MV_CODEREADER_RegisterImageCallBackEx2_NET(ImageCallback, IntPtr.Zero);
if (MvCodeReader.MV_CODEREADER_OK != nRet)
{
Console.WriteLine("Register image callback failed!");
// 刷新扫码器状态
RefreshStateEvent?.Invoke(false);
break;
}
#region 关闭所有设备
public static void CloseAllDevice()
{
try
{
Console.WriteLine("开始关闭所有设备");
int nRet = MvCodeReader.MV_CODEREADER_OK;
// 关闭所有已打开相机
foreach (KeyValuePair<MvCodeReader, string> hashmap in m_cMyDevices)
// ch:开启抓图 || en: start grab image
nRet = device.MV_CODEREADER_StartGrabbing_NET();
if (MvCodeReader.MV_CODEREADER_OK != nRet)
{
// ch:停止抓图 | en:Stop grab image
nRet = hashmap.Key.MV_CODEREADER_StopGrabbing_NET();
if (MvCodeReader.MV_CODEREADER_OK != nRet)
{
Console.WriteLine("设备ip:" + hashmap.Value + "停止抓图失败");
Console.WriteLine("Stop grabbing failed{0:x8}", nRet);
}
// ch:关闭设备 | en:Close device
nRet = hashmap.Key.MV_CODEREADER_CloseDevice_NET();
if (MvCodeReader.MV_CODEREADER_OK != nRet)
{
Console.WriteLine("设备ip:" + hashmap.Value + "关闭失败");
Console.WriteLine("Start grabbing failed:{0:x8}", nRet);
// 刷新扫码器状态
RefreshStateEvent?.Invoke(false);
break;
}
}
// ch:销毁设备 | en:Destroy device
nRet = hashmap.Key.MV_CODEREADER_DestroyHandle_NET();
if (MvCodeReader.MV_CODEREADER_OK != nRet)
Console.WriteLine("Press enter to exit");
Console.WriteLine(DateTime.Now.ToString());
while (true)
{
Thread.Sleep(1000 * 60);
DateTime dateTime = DateTime.Now;
TimeSpan timeSpan = dateTime.Subtract(ShellLiveTime);
if (timeSpan.TotalMinutes >= 10)
{
Console.WriteLine("设备ip:" + hashmap.Value + "销毁失败");
Console.WriteLine("箱壳扫码器超时");
//CloseShell();
//Shell();
break;
}
Console.WriteLine("设备ip:" + hashmap.Value + "关闭成功!");
}
}
catch (Exception ex)
{
Console.WriteLine("设备关闭异常:" + ex);
}
}
#endregion
#region 关闭指定设备
public void CloseDevice(KeyValuePair<MvCodeReader, string> hashmap)
{
try
{
int nRet = MvCodeReader.MV_CODEREADER_OK;
// ch:停止抓图 | en:Stop grab image
nRet = hashmap.Key.MV_CODEREADER_StopGrabbing_NET();
}
// Console.ReadLine();
// 刷新扫码器状态
RefreshStateEvent?.Invoke(false);
// ch:停止抓图 | en:Stop grabbing
nRet = device.MV_CODEREADER_StopGrabbing_NET();
if (MvCodeReader.MV_CODEREADER_OK != nRet)
{
Console.WriteLine("设备ip:" + hashmap.Value + "停止抓图失败");
Console.WriteLine("Stop grabbing failed{0:x8}", nRet);
return;
break;
}
// ch:关闭设备 | en:Close device
nRet = hashmap.Key.MV_CODEREADER_CloseDevice_NET();
nRet = device.MV_CODEREADER_CloseDevice_NET();
if (MvCodeReader.MV_CODEREADER_OK != nRet)
{
Console.WriteLine("设备ip:" + hashmap.Value + "关闭失败");
return;
Console.WriteLine("Close device failed{0:x8}", nRet);
break;
}
}
catch (Exception ex)
{
Console.WriteLine("设备关闭异常:" + ex);
}
// ch:销毁设备 | en:Destroy device
nRet = device.MV_CODEREADER_DestroyHandle_NET();
if (MvCodeReader.MV_CODEREADER_OK != nRet)
{
Console.WriteLine("Destroy device failed:{0:x8}", nRet);
break;
}
} while (false);
Thread.Sleep(1000);
Shell();
}
#endregion
#region 判断字符编码
@ -363,27 +346,6 @@ namespace Aucma.Core.Scanner
#endregion
#region 将Byte转换为结构体类型
//将Byte转换为结构体类型
public static object ByteToStruct(byte[] bytes, Type type)
{
int size = Marshal.SizeOf(type);
if (size > bytes.Length)
{
return null;
}
//分配结构体内存空间
IntPtr structPtr = Marshal.AllocHGlobal(size);
//将byte数组拷贝到分配好的内存空间
Marshal.Copy(bytes, 0, structPtr, size);
//将内存空间转换为目标结构体
object obj = Marshal.PtrToStructure(structPtr, type);
//释放内存空间
Marshal.FreeHGlobal(structPtr);
return obj;
}
#endregion
}

@ -6,7 +6,7 @@
xmlns:local="clr-namespace:Aucma.Scada.UI.Page.AssemblyPlan"
xmlns:local1="clr-namespace:Aucma.Scada.UI.Converter.AssemblyPlan"
mc:Ignorable="d"
Title="MES生产计划" Height="650" Width="1000" Name="window" WindowStartupLocation="CenterScreen" FontFamily="Microsoft YaHei" Background="#1152AC"
Title="MES生产计划" Height="800" Width="1500" Name="window" WindowStartupLocation="CenterScreen" FontFamily="Microsoft YaHei" Background="#1152AC"
ResizeMode="NoResize" >
<Window.Resources>
<Style x:Key="DataGridTextColumnCenterSytle" TargetType="{x:Type TextBlock}">
@ -147,7 +147,7 @@
<DataGridTextColumn Binding="{Binding planCode}" Header="计划编号" Width="1*" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding orderCode}" Header="工单编号" Width="1*" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding materialCode}" Header="产品编码" Width="1.3*" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding materialName}" Header="产品型号" Width="2.3*" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding materialName}" Header="产品型号" Width="4*" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding planAmount}" Header="计划数量" Width="0.8*" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding completeAmount}" Header="完成数量" Width="0.8*" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding beginTime,StringFormat=\{0:MM月dd日 HH:mm\}}" Header="开始时间" Width="1*" IsReadOnly="True" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>

@ -92,7 +92,16 @@
<Border.Effect>
<DropShadowEffect Color="#1254AB" ShadowDepth="0" BlurRadius="5" Opacity="0.5" Direction="0"></DropShadowEffect>
</Border.Effect>
<ScrollViewer VerticalScrollBarVisibility="Auto">
<ScrollViewer VerticalScrollBarVisibility="Auto" >
<ScrollViewer.Resources>
<!--定义垂直滚动条的样式-->
<Style TargetType="ScrollBar">
<Setter Property="Background" Value="#4285DE"/>
<Setter Property="Width" Value="5"/>
</Style>
</ScrollViewer.Resources>
<ItemsControl Grid.Column="0" ItemsSource="{Binding Shapes}" VerticalAlignment="Center" HorizontalAlignment="Center" >
<ItemsControl.ItemsPanel>
<!--布局-->

@ -1,4 +1,4 @@
E:\c#\AUCMA\aucma.scada\foam\Aucma.Scada.UI\obj\Debug\GeneratedInternalTypeHelper.g.cs

FE:\c#\AUCMA\aucma.scada\foam\Aucma.Scada.UI\App.xaml;;
FE:\c#\AUCMA\aucma.scada\foam\Aucma.Scada.UI\Page\AssemblyPlan\AssemblyPlanControl.xaml;;
FE:\c#\AUCMA\aucma.scada\foam\Aucma.Scada.UI\Page\AssemblyPlan\PlanInfoEditWindow.xaml;;

@ -1,2 +1,62 @@

//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace XamlGeneratedNamespace {
/// <summary>
/// GeneratedInternalTypeHelper
/// </summary>
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public sealed class GeneratedInternalTypeHelper : System.Windows.Markup.InternalTypeHelper {
/// <summary>
/// CreateInstance
/// </summary>
protected override object CreateInstance(System.Type type, System.Globalization.CultureInfo culture) {
return System.Activator.CreateInstance(type, ((System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic)
| (System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.CreateInstance)), null, null, culture);
}
/// <summary>
/// GetPropertyValue
/// </summary>
protected override object GetPropertyValue(System.Reflection.PropertyInfo propertyInfo, object target, System.Globalization.CultureInfo culture) {
return propertyInfo.GetValue(target, System.Reflection.BindingFlags.Default, null, null, culture);
}
/// <summary>
/// SetPropertyValue
/// </summary>
protected override void SetPropertyValue(System.Reflection.PropertyInfo propertyInfo, object target, object value, System.Globalization.CultureInfo culture) {
propertyInfo.SetValue(target, value, System.Reflection.BindingFlags.Default, null, null, culture);
}
/// <summary>
/// CreateDelegate
/// </summary>
protected override System.Delegate CreateDelegate(System.Type delegateType, object target, string handler) {
return ((System.Delegate)(target.GetType().InvokeMember("_CreateDelegate", (System.Reflection.BindingFlags.InvokeMethod
| (System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)), null, target, new object[] {
delegateType,
handler}, null)));
}
/// <summary>
/// AddEventHandler
/// </summary>
protected override void AddEventHandler(System.Reflection.EventInfo eventInfo, object target, System.Delegate handler) {
eventInfo.AddEventHandler(target, handler);
}
}
}

@ -1,4 +1,4 @@
#pragma checksum "..\..\..\..\Page\AssemblyPlan\PlanInfoEditWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "A8BCABA5CBE8F206A8C3B8531F1994EAA59CB846EA6698F761A3BEFADAC62040"
#pragma checksum "..\..\..\..\Page\AssemblyPlan\PlanInfoEditWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "6DA0971FEEFF86ABE715CAE90CF158E4845B3F2075983251ADE14C38565EE308"
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。

@ -1,4 +1,4 @@
#pragma checksum "..\..\..\..\Page\AssemblyPlan\PlanInfoEditWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "A8BCABA5CBE8F206A8C3B8531F1994EAA59CB846EA6698F761A3BEFADAC62040"
#pragma checksum "..\..\..\..\Page\AssemblyPlan\PlanInfoEditWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "6DA0971FEEFF86ABE715CAE90CF158E4845B3F2075983251ADE14C38565EE308"
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。

@ -1,4 +1,4 @@
#pragma checksum "..\..\..\..\Page\InventoryInfo\BomFoamRearInventory.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "051C148C286C0C6F0D9F7368DD7DD9D694A4480FCEB90FF0E65EB555235E1435"
#pragma checksum "..\..\..\..\Page\InventoryInfo\BomFoamRearInventory.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "4118EDE7E02AB173F3E20E151078599BC65473CB5136EAEC887E470925918EE8"
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。

@ -1,4 +1,4 @@
#pragma checksum "..\..\..\..\Page\InventoryInfo\BomFoamRearInventory.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "051C148C286C0C6F0D9F7368DD7DD9D694A4480FCEB90FF0E65EB555235E1435"
#pragma checksum "..\..\..\..\Page\InventoryInfo\BomFoamRearInventory.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "4118EDE7E02AB173F3E20E151078599BC65473CB5136EAEC887E470925918EE8"
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。

@ -48,6 +48,7 @@ namespace Aucma.Scada.UI.viewModel
FormControlCommand = new RelayCommand<object>(obj => FormControl(obj));
UserContent = inStoreInfoControl;
MvCodeHelper.RefreshStateEvent += Scanner1State;
init();
}
@ -238,8 +239,7 @@ namespace Aucma.Scada.UI.viewModel
{
RefreshMesDb();
RefreshPlc();
RefreshScanner();
}
/// <summary>
/// 数据库状态刷新
@ -271,18 +271,7 @@ namespace Aucma.Scada.UI.viewModel
}
}
/// <summary>
/// 扫码器状态刷新
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void RefreshScanner()
{
string ip1 = appConfig.foamHikRobotIp;
bool flag1 = MvCodeHelper.ConnectionStatus(ip1);
Scanner1State(flag1);
}
#endregion
#region MES数据库状态
@ -440,13 +429,13 @@ namespace Aucma.Scada.UI.viewModel
{
if (type)
{
Scanner1UIStatusWb = "扫码器1连接成功";
Scanner1UIStatusWb = "泡后库扫码器";
Scanner1UIColor = "Green";
Scanner1UIIcon = "templates/image/Green.png";
}
else
{
Scanner1UIStatusWb = "扫码器1状态异常";
Scanner1UIStatusWb = "泡后库扫码器";
Scanner1UIColor = "Red";
Scanner1UIIcon = "templates/image/Red.png";
}

Loading…
Cancel
Save