Commit 0ac1cd37 LN

rfid更改为最新方式

1 个父辈 a683279f
此文件类型无法预览
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
<add key="NeedScanCode" value="1" /> <add key="NeedScanCode" value="1" />
<add key="Agv_Log_Open" value="0" /> <add key="Agv_Log_Open" value="0" />
<add key="NeedCheckTray" value="0" /> <add key="NeedCheckTray" value="0" />
<add key ="RfidServer_Port" value ="13000"/>
</appSettings> </appSettings>
<!-- <log4net> --> <!-- <log4net> -->
<!-- <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender"> --> <!-- <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender"> -->
......
...@@ -55,6 +55,9 @@ ...@@ -55,6 +55,9 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup /> <PropertyGroup />
<ItemGroup> <ItemGroup>
<Reference Include="Asa.RFID">
<HintPath>..\..\dll\RFID\Asa.RFID.dll</HintPath>
</Reference>
<Reference Include="Client"> <Reference Include="Client">
<HintPath>..\..\dll\Client.dll</HintPath> <HintPath>..\..\dll\Client.dll</HintPath>
</Reference> </Reference>
......
...@@ -42,20 +42,20 @@ namespace OnlineStore.AssemblyLine ...@@ -42,20 +42,20 @@ namespace OnlineStore.AssemblyLine
} }
lblConInfo.Text += msg; lblConInfo.Text += msg;
lblRFID.Text = "RFID信息:\r\n"; //lblRFID.Text = "RFID信息:\r\n";
msg = ""; //msg = "";
List<string> rfidList = new List<string>(DeviceConfig.ProRFIpMap.Values); //List<string> rfidList = new List<string>(DeviceConfig.ProRFIpMap.Values);
foreach (string ip in rfidList) //foreach (string ip in rfidList)
{ //{
string errorCode = "?"; // string errorCode = "?";
if (RFIDAutoReader.rfidErrorMap.ContainsKey(ip)) // if (RFIDAutoReader.rfidErrorMap.ContainsKey(ip))
{ // {
errorCode = "" + RFIDAutoReader.rfidErrorMap[ip]; // errorCode = "" + RFIDAutoReader.rfidErrorMap[ip];
} // }
// string con = RFIDManager.ReadRFID(ip) .NumStr() ; // // string con = RFIDManager.ReadRFID(ip) .NumStr() ;
msg += ("RFID[" + ip + "]:").PadLeft(26, ' ') + "ErrorCode=" + errorCode + "\n"; // msg += ("RFID[" + ip + "]:").PadLeft(26, ' ') + "ErrorCode=" + errorCode + "\n";
} //}
lblRFID.Text += msg; //lblRFID.Text += msg;
lblBox.Text = "料仓连接信息:\r\n"; lblBox.Text = "料仓连接信息:\r\n";
......
需要修改 20200528
RFID更改为最新方式。
接驳台等待料盘到位去掉超时时间。
需要修改
1.紧急出料托盘定位逻辑 1.紧急出料托盘定位逻辑
2.皮带线无信号不扫码。 2.皮带线无信号不扫码。
......
...@@ -89,5 +89,7 @@ namespace OnlineStore.Common ...@@ -89,5 +89,7 @@ namespace OnlineStore.Common
public static string UseBuzzer = "UseBuzzer"; public static string UseBuzzer = "UseBuzzer";
public static string NeedCheckTray = "NeedCheckTray"; public static string NeedCheckTray = "NeedCheckTray";
public static string RfidServer_Port = "RfidServer_Port";
} }
} }
...@@ -36,6 +36,9 @@ ...@@ -36,6 +36,9 @@
<Prefer32Bit>false</Prefer32Bit> <Prefer32Bit>false</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Asa.RFID">
<HintPath>..\..\dll\RFID\Asa.RFID.dll</HintPath>
</Reference>
<Reference Include="Client, Version=1.0.0.1, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Client, Version=1.0.0.1, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\dll\Client.dll</HintPath> <HintPath>..\..\dll\Client.dll</HintPath>
...@@ -94,9 +97,6 @@ ...@@ -94,9 +97,6 @@
<Compile Include="deviceLibrary\PanasonicServo\ACServerManager.cs" /> <Compile Include="deviceLibrary\PanasonicServo\ACServerManager.cs" />
<Compile Include="deviceLibrary\PanasonicServo\ACServerManager_Partial.cs" /> <Compile Include="deviceLibrary\PanasonicServo\ACServerManager_Partial.cs" />
<Compile Include="assemblyLine\EquipBase.cs" /> <Compile Include="assemblyLine\EquipBase.cs" />
<Compile Include="deviceLibrary\RFID\RFIDAuto.cs" />
<Compile Include="deviceLibrary\RFID\RFIDAutoReader.cs" />
<Compile Include="deviceLibrary\RFID\RFIDReader.cs" />
<Compile Include="model\LineAlarm.cs"> <Compile Include="model\LineAlarm.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
......
...@@ -162,7 +162,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -162,7 +162,7 @@ namespace OnlineStore.DeviceLibrary
MoveInfo.NextMoveStep(LineMoveStep.DON_05_LineRun); MoveInfo.NextMoveStep(LineMoveStep.DON_05_LineRun);
LogUtil.info(hengyiName + MoveInfo.SLog + "送料,NG->接驳台,转动接驳台皮带"); LogUtil.info(hengyiName + MoveInfo.SLog + "送料,NG->接驳台,转动接驳台皮带");
// IOMove(IO_Type.SeparateDevice_Run, IO_VALUE.HIGH); // IOMove(IO_Type.SeparateDevice_Run, IO_VALUE.HIGH);
Line3Turn.StartLineRun( Line3EndProcess); Line3Turn.StartLineRun(Line3EndProcess);
SeparateLineRun(MoveInfo); SeparateLineRun(MoveInfo);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(3000)); MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(3000));
MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Location_Check3, IO_VALUE.HIGH)); MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Location_Check3, IO_VALUE.HIGH));
...@@ -172,10 +172,10 @@ namespace OnlineStore.DeviceLibrary ...@@ -172,10 +172,10 @@ namespace OnlineStore.DeviceLibrary
{ {
MoveInfo.NextMoveStep(LineMoveStep.DON_07_SeparateCheck); MoveInfo.NextMoveStep(LineMoveStep.DON_07_SeparateCheck);
// Line3LastTrayP++; // Line3LastTrayP++;
LogUtil.info(hengyiName + MoveInfo.SLog + "送料,等待料盘到达接驳台,最多等待65000"); LogUtil.info(hengyiName + MoveInfo.SLog + "送料,等待料盘到达接驳台 ");
MoveInfo.TimeOutSeconds = 40; MoveInfo.TimeOutSeconds = 40;
MoveInfo.OneWaitCanEndStep = true; //MoveInfo.OneWaitCanEndStep = true;
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(65000)); //MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(65000));
MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SeparateDevice_Check, IO_VALUE.HIGH)); MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SeparateDevice_Check, IO_VALUE.HIGH));
} }
else if (MoveInfo.MoveStep.Equals(LineMoveStep.DON_07_SeparateCheck)) else if (MoveInfo.MoveStep.Equals(LineMoveStep.DON_07_SeparateCheck))
...@@ -190,17 +190,24 @@ namespace OnlineStore.DeviceLibrary ...@@ -190,17 +190,24 @@ namespace OnlineStore.DeviceLibrary
LogUtil.info(hengyiName + MoveInfo.SLog + "送料,接驳台有料,调用arriveRobotLocation=" + robotIndex + "[" + StationInfo_Move.CodeStr + "]"); LogUtil.info(hengyiName + MoveInfo.SLog + "送料,接驳台有料,调用arriveRobotLocation=" + robotIndex + "[" + StationInfo_Move.CodeStr + "]");
SServerManager.arriveRobotLocation(Name, robotIndex, StationInfo_Move.CodeStr); SServerManager.arriveRobotLocation(Name, robotIndex, StationInfo_Move.CodeStr);
} }
else if (span.TotalSeconds <= 60)
{
int robotIndex = GetRobotIndex();
LogUtil.info(hengyiName + MoveInfo.SLog + "送料,接驳台应有料"+FormUtil.GetSpanStr(span)+",调用arriveRobotLocation=" + robotIndex + "[" + StationInfo_Move.CodeStr + "]");
SServerManager.arriveRobotLocation(Name, robotIndex, StationInfo_Move.CodeStr);
}
else else
{ {
LogUtil.info(hengyiName + MoveInfo.SLog + "送料,接驳台无料"); MoveInfo.NextMoveStep(LineMoveStep.DON_07_SeparateCheck);
LogUtil.info(hengyiName + MoveInfo.SLog + "送料,未检测到SeparateDevice_Check,再次 等待料盘到达接驳台 ");
MoveInfo.TimeOutSeconds = 40;
MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SeparateDevice_Check, IO_VALUE.HIGH));
} }
//MoveInfo.EndStepWait(); //}
//else if (span.TotalSeconds <= 60)
//{
// int robotIndex = GetRobotIndex();
// LogUtil.info(hengyiName + MoveInfo.SLog + "送料,接驳台应有料"+FormUtil.GetSpanStr(span)+",调用arriveRobotLocation=" + robotIndex + "[" + StationInfo_Move.CodeStr + "]");
// SServerManager.arriveRobotLocation(Name, robotIndex, StationInfo_Move.CodeStr);
//}
//else
//{
// LogUtil.info(hengyiName + MoveInfo.SLog + "送料,接驳台无料");
//}
} }
else if (MoveInfo.MoveStep.Equals(LineMoveStep.DON_08_CRun)) else if (MoveInfo.MoveStep.Equals(LineMoveStep.DON_08_CRun))
{ {
......
...@@ -323,6 +323,10 @@ namespace OnlineStore.DeviceLibrary ...@@ -323,6 +323,10 @@ namespace OnlineStore.DeviceLibrary
} }
return true; return true;
} }
internal void ClearTrayRFID()
{
RFIDManager.ClearTrayNum(DeviceID);
}
#region 伺服运动 #region 伺服运动
......
...@@ -659,34 +659,34 @@ namespace OnlineStore.DeviceLibrary ...@@ -659,34 +659,34 @@ namespace OnlineStore.DeviceLibrary
#endregion #endregion
#region AGV #region AGV
internal bool AgvCanEnter(string nodeId, RFIDData data) //internal bool AgvCanEnter(string nodeId, RFIDData data)
{ //{
string logN = Name + "收到 AgvCanEnter 事件 [" + nodeId + "] [" + data.ToData() + "] "; // string logN = Name + "收到 AgvCanEnter 事件 [" + nodeId + "] [" + data.NumStr() + "] ";
bool usable = false; // bool usable = false;
if (nodeId.Equals(Config.AgvInName)) // if (nodeId.Equals(Config.AgvInName))
{ // {
if (isInSuddenDown || isNoAirCheck) // if (isInSuddenDown || isNoAirCheck)
{ // {
usable = false; // usable = false;
} // }
else // else
{ // {
//入料口无料架即可进入 // //入料口无料架即可进入
usable = (runStatus >= LineRunStatus.Runing // usable = (runStatus >= LineRunStatus.Runing
&& ProcessShelfEnter.Equals(false) // && ProcessShelfEnter.Equals(false)
&& IOValue(IO_Type.SL_Entry_Check).Equals(IO_VALUE.LOW)); // && IOValue(IO_Type.SL_Entry_Check).Equals(IO_VALUE.LOW));
} // }
} // }
else if (nodeId.Equals(Config.AgvOutName)) // else if (nodeId.Equals(Config.AgvOutName))
{ // {
//出口有料架才可以进入 // //出口有料架才可以进入
usable = (runStatus >= LineRunStatus.Runing // usable = (runStatus >= LineRunStatus.Runing
&& ProcessShelfOut.Equals(false) // && ProcessShelfOut.Equals(false)
&& IOValue(IO_Type.SL_Out_Check).Equals(IO_VALUE.HIGH)); // && IOValue(IO_Type.SL_Out_Check).Equals(IO_VALUE.HIGH));
} // }
LogUtil.info(logN + ":" + usable); // LogUtil.info(logN + ":" + usable);
return usable; // return usable;
} //}
internal void AgvArrive(string nodeId, string rfid) internal void AgvArrive(string nodeId, string rfid)
{ {
......
...@@ -116,16 +116,12 @@ namespace OnlineStore.DeviceLibrary ...@@ -116,16 +116,12 @@ namespace OnlineStore.DeviceLibrary
lastStopDown = DateTime.Now; lastStopDown = DateTime.Now;
SecondMoveInfo.NewMove(LineMoveType.CheckFixture, CheckParam); SecondMoveInfo.NewMove(LineMoveType.CheckFixture, CheckParam);
SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_00_Stop1Down); SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_00_Stop1Down);
// SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(200)); LogUtil.debug(Name + " [" + trayCount + "] 检测到SW_StopCheck:" + SecondMoveInfo.SLog + "阻挡气缸下降 ,等待 SW_StopCheck=0,清理托盘RFID");
LogUtil.debug(Name + " [" + trayCount + "] 检测到SW_StopCheck:" + SecondMoveInfo.SLog + "阻挡气缸下降 ,等待 SW_StopCheck=0"); ClearTrayRFID();
//CheckLog("检测到SW_StopCheck:" + SecondMoveInfo.SLog + "阻挡气缸下降 ,等待 SW_StopCheck=0" );
IOMove(IO_Type.SW_StopDown, IO_VALUE.HIGH, 1200); IOMove(IO_Type.SW_StopDown, IO_VALUE.HIGH, 1200);
SecondMoveInfo.OneWaitCanEndStep = true; SecondMoveInfo.OneWaitCanEndStep = true;
// SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(TrayManager.StopDownWaitTime));
//SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SW_StopDown, IO_VALUE.HIGH));
SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SW_StopCheck, IO_VALUE.LOW)); SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SW_StopCheck, IO_VALUE.LOW));
SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SW_TrayCheck, IO_VALUE.HIGH)); SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SW_TrayCheck, IO_VALUE.HIGH));
//IOMove(IO_Type.SW_StopDown, IO_VALUE.HIGH, TrayManager.StopDownWaitTime);
} }
} }
else else
......
...@@ -166,7 +166,6 @@ namespace OnlineStore.DeviceLibrary ...@@ -166,7 +166,6 @@ namespace OnlineStore.DeviceLibrary
LogUtil.error(Name + "加载调试设备出错:", ex); LogUtil.error(Name + "加载调试设备出错:", ex);
} }
} }
RFIDManager.Init();
Task.Factory.StartNew(delegate Task.Factory.StartNew(delegate
{ {
LogUtil.info(Name + "开始连接IO模块 "); LogUtil.info(Name + "开始连接IO模块 ");
......
...@@ -571,14 +571,12 @@ namespace OnlineStore.DeviceLibrary ...@@ -571,14 +571,12 @@ namespace OnlineStore.DeviceLibrary
//托盘在第一个阻挡处 //托盘在第一个阻挡处
SecondMoveInfo.NewMove(LineMoveType.CheckFixture); SecondMoveInfo.NewMove(LineMoveType.CheckFixture);
SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_00_Stop1Down); SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_00_Stop1Down);
//SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(200)); CheckLog(" 托盘检测:料盘检测StopCylinder_Check1 " + SecondMoveInfo.SLog + "阻挡气缸1-1下降 , 等待 StopCylinder_Check1=0,清理托盘RFID");
CheckLog(" 托盘检测:料盘检测StopCylinder_Check1 " + SecondMoveInfo.SLog + "阻挡气缸1-1下降 , 等待 StopCylinder_Check1=0"); ClearTrayRFID();
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH, 1200); IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH, 1200);
SecondMoveInfo.OneWaitCanEndStep = true; SecondMoveInfo.OneWaitCanEndStep = true;
// SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH));
SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Check1, IO_VALUE.LOW)); SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Check1, IO_VALUE.LOW));
SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Check2, IO_VALUE.HIGH)); SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Check2, IO_VALUE.HIGH));
// SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(TrayManager.StopDownWaitTime));
} }
} }
else else
......
...@@ -74,15 +74,12 @@ namespace OnlineStore.DeviceLibrary ...@@ -74,15 +74,12 @@ namespace OnlineStore.DeviceLibrary
//托盘在第一个阻挡处 //托盘在第一个阻挡处
SecondMoveInfo.NewMove(LineMoveType.CheckFixture); SecondMoveInfo.NewMove(LineMoveType.CheckFixture);
SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_00_Stop1Down); SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_00_Stop1Down);
// SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(200)); LogUtil.debug(Name + " [" + trayCount + "] 托盘检测:" + SecondMoveInfo.SLog + "阻挡气缸1-1下降 ,等待 StopCylinder_Check1=0,清理托盘RFID");
LogUtil.debug(Name + " [" + trayCount + "] 托盘检测:" + SecondMoveInfo.SLog + "阻挡气缸1-1下降 ,等待 StopCylinder_Check1=0"); ClearTrayRFID();
//CheckLog(" 托盘检测:" + SecondMoveInfo.SLog + "阻挡气缸1-1下降 ,等待 StopCylinder_Check1=0" );
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH, 1200); IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH, 1200);
SecondMoveInfo.OneWaitCanEndStep = true; SecondMoveInfo.OneWaitCanEndStep = true;
// SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH));
SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Check1, IO_VALUE.LOW)); SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Check1, IO_VALUE.LOW));
SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Check2, IO_VALUE.HIGH)); SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Check2, IO_VALUE.HIGH));
// SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(TrayManager.StopDownWaitTime));
} }
} }
else else
......
...@@ -3,6 +3,7 @@ using Asa.RFID; ...@@ -3,6 +3,7 @@ using Asa.RFID;
using OnlineStore.Common; using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary; using OnlineStore.LoadCSVLibrary;
using System; using System;
using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
...@@ -13,48 +14,38 @@ namespace OnlineStore.DeviceLibrary ...@@ -13,48 +14,38 @@ namespace OnlineStore.DeviceLibrary
{ {
public class RFIDManager public class RFIDManager
{ {
public static List<string> ShelfIpList = new List<string>();
public static List<string> TrayIpList = new List<string>();
private static int DefaultTrayNum = ConfigAppSettings.GetIntValue(Setting_Init.DefaultTrayNum); private static int DefaultTrayNum = ConfigAppSettings.GetIntValue(Setting_Init.DefaultTrayNum);
public static void Init() private static ReadAll readAll = new ReadAll("TheRFID");
private static bool IsOpen = false;
private static ConcurrentDictionary<string, string> LastRfidMap = new ConcurrentDictionary<string, string>();
public static void Open( )
{ {
TrayIpList = new List<string>(); if (IsOpen)
ShelfIpList = new List<string>();
Dictionary<string, string> rfidMap = DeviceConfig.ProRFIpMap;
foreach (string key in rfidMap.Keys)
{ {
//if (key.EndsWith("-1")) return;
//{
// ShelfIpList.Add(rfidMap[key]);
//}
//else
{
TrayIpList.Add(rfidMap[key]);
} }
try
{
int port = ConfigAppSettings.GetIntValue(Setting_Init.RfidServer_Port);
if (port <= 0)
{
port = 13000;
} }
LogUtil.info("RFID Server Open,port=" + port);
readAll.Start();
IsOpen = true;
} }
public static void Open() catch (Exception ex)
{
Task.Factory.StartNew(delegate
{ {
LogUtil.info( "RFIDManager.Open"); LogUtil.error("Open 出错:" + ex.ToString());
RFIDReader.Open(ShelfIpList.ToArray()); }
// RFIDAutoReader.Open(null, new List<string>(rfidMap.Values).ToArray());
RFIDAutoReader.Open(null, TrayIpList.ToArray());
});
} }
/// <summary>
/// 获取托盘编码
/// </summary>
public static int GetTrayNum(int subType, bool isClear = false) public static int GetTrayNum(int subType, bool isClear = false)
{ {
if (DefaultTrayNum > 0) if (DefaultTrayNum > 0)
{ {
return DefaultTrayNum; return DefaultTrayNum;
} }
// return 9;
if (subType.Equals(104)) if (subType.Equals(104))
{ {
return LineManager.Line.Sw23TrayNum; return LineManager.Line.Sw23TrayNum;
...@@ -86,54 +77,31 @@ namespace OnlineStore.DeviceLibrary ...@@ -86,54 +77,31 @@ namespace OnlineStore.DeviceLibrary
return 0; return 0;
} }
public static RFIDData GetShelfId(int subType) public static void ClearTrayNum(int subType)
{
string ip = GetRFIP(subType, 1);
return ReadRFID(ip, true);
}
public static RFIDData ReadRFID(string ip, bool isClear = false)
{ {
try try
{ {
if (String.IsNullOrEmpty(ip).Equals(false) && ShelfIpList.Contains(ip)) if (subType.Equals(104))
{
byte[] bdata = RFIDReader.Read(ip, isClear);
if (bdata == null)
{ {
LogUtil.error("RFID [ " + ip + " ] 读到数据=null"); return;
}
RFIDData data = new RFIDData(bdata);
return data;
} }
else else if (subType.Equals(101))
//if (String.IsNullOrEmpty(ip).Equals(false) && LineManager.Line.rfidList.Contains(ip))
{
byte[] bdata = null;
if (isClear)
{ {
bdata = RFIDAutoReader.ReadAndClear(ip); return;
} }
else
{
bdata = RFIDAutoReader.Read(ip);
string ip = GetRFIP(subType);
RFIDData data = ReadRFID(ip, true);
} }
if (bdata == null) catch (Exception ex)
{ {
LogUtil.error("RFID [ " + ip + " ] 读到数据=null"); LogUtil.error("ClearTrayNum【" + subType + "】出错:" + ex.ToString());
}
RFIDData data = new RFIDData(bdata);
return data;
} }
} }
catch (Exception ex) public static RFIDData GetShelfId(int subType)
{ {
//LogUtil.error("ReadRFID["+ip+"]出错:",ex); string ip = GetRFIP(subType, 1);
} return ReadRFID(ip, true);
return new RFIDData();
} }
public static string GetRFIP(int subType, int rtType = 0) public static string GetRFIP(int subType, int rtType = 0)
...@@ -151,87 +119,113 @@ namespace OnlineStore.DeviceLibrary ...@@ -151,87 +119,113 @@ namespace OnlineStore.DeviceLibrary
return ip; return ip;
} }
public static void Close() public static RFIDData ReadRFID(string ip, bool isClear = false)
{
Task.Factory.StartNew(delegate
{ {
LogUtil.info( "RFIDManager.Close");
try try
{ {
LogUtil.info("调用 RFIDAutoReader.CloseAll"); if (String.IsNullOrEmpty(ip).Equals(false))
RFIDAutoReader.CloseAll(); {
string outValue = readAll.Read(ip);
if (isClear)
{
readAll.Clear(ip);
}
if (outValue.Equals("000"))
{
// LogUtil.error("ReadRFID[" + ip + "]=" + outValue);
}
RFIDData data = new RFIDData(outValue);
return data;
}
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error("RFIDAutoReader.CloseAll()出错:", ex); LogUtil.error("ReadRFID[" + ip + "] [" + isClear + "] 出错:" + ex.ToString());
} }
return new RFIDData();
}
public static void Close()
{
try try
{ {
LogUtil.info("调用 RFIDReader.CloseAll"); readAll.Stop();
RFIDReader.CloseAll();
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error("RFIDReader.CloseAll()出错:", ex); LogUtil.error("关闭RFID出错:" + ex.ToString());
} }
});
} }
} }
public class RFIDData public class RFIDData
{ {
/// <summary> public string StrData = "";
/// RFID类型,区分是料架还是托盘,托盘E=69,包装料料架A=65,料串=B
/// </summary>
public char RFType = '0';
/// <summary>
/// 托盘编号,从1-32
/// </summary>
public int Num = 0;
public char RFType
public RFIDData(int num=0, int t=0)
{ {
if (t < 65) get
{ {
RFType = '0'; char[] charArray = StrData.ToCharArray();
} if (charArray.Length > 0)
else
{ {
this.RFType = (char)t; return charArray[0];
} }
this.Num = num; return '0';
} }
}
public RFIDData(byte[] data) public int Num
{ {
try get
{ {
if (data != null && data.Length > 2) try
{ {
if (data[1] < 65) if (StrData.Length >= 2)
{ {
RFType = '0'; return Convert.ToInt32(StrData.Substring(1, StrData.Length - 1));
} }
else }
catch (Exception ex)
{ {
RFType = (char)data[1];
} }
Num = (int)(data[2]); return 0;
} }
} }
catch (Exception ex)
public RFIDData(string data = "00")
{
if (String.IsNullOrEmpty(data))
{ {
LogUtil.error("RFIP 数据【" + data + "】 获取编码失败"); data = "00";
} }
this.StrData = data;
} }
public byte[] ToData() public string NumStr()
{ {
return new byte[] { (byte)RFType, (byte)Num }; return StrData;
} }
public string NumStr()
internal static bool IsRealRfid(string shelfRfid)
{ {
return "" + RFType + "" + Num.ToString() + ""; //判断料架号是否是真实的料架号
if (shelfRfid.StartsWith("C") || shelfRfid.StartsWith("D"))
{
int num = -1;
try
{
num = Convert.ToInt32(shelfRfid.Substring(1, shelfRfid.Length - 1));
}
catch (Exception ex)
{
}
if (num > 0)
{
return true;
}
}
return false;
} }
} }
} }
...@@ -21,10 +21,6 @@ namespace OnlineStore.DeviceLibrary ...@@ -21,10 +21,6 @@ namespace OnlineStore.DeviceLibrary
private static ConcurrentDictionary<int, TrayInfo> TrayInfoMap = new ConcurrentDictionary<int, TrayInfo>(); private static ConcurrentDictionary<int, TrayInfo> TrayInfoMap = new ConcurrentDictionary<int, TrayInfo>();
/// <summary> /// <summary>
/// 流水线需要的空盘数量
/// </summary>
// internal static int LineNeedEmptyTrayNum = 0;
/// <summary>
/// 最大托盘号,必须按照顺序从1到6走过 /// 最大托盘号,必须按照顺序从1到6走过
/// </summary> /// </summary>
internal static int MaxTrayNum = 0; internal static int MaxTrayNum = 0;
...@@ -44,15 +40,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -44,15 +40,7 @@ namespace OnlineStore.DeviceLibrary
{ {
return new List<TrayInfo>(TrayInfoMap.Values); return new List<TrayInfo>(TrayInfoMap.Values);
} }
//internal static void AddNeedEmptyTrayNum()
//{
// Interlocked.Increment(ref LineNeedEmptyTrayNum);
//}
//internal static void DelNeedEmptyTrayNum()
//{
// Interlocked.Decrement(ref LineNeedEmptyTrayNum);
//}
/// <summary> /// <summary>
/// 对应的盘号(1-6)是否有料盘 /// 对应的盘号(1-6)是否有料盘
/// </summary> /// </summary>
......
using log4net;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Asa.RFID
{
}
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Asa.RFID.RFIDAuto;
namespace Asa.RFID
{
public class RFID
{
public static readonly ILog LOGGER = LogManager.GetLogger("TheRFID");
private string IP = "";
private byte addr;
private int portIndex;
private bool IsConnect = false;
private byte[] lastData = new byte[8];
internal byte[] _buff; //8字节缓存
private byte[] _uid; //卡片ID
public bool IsExist = false;
public int ErrCode = 0;
public RFID(string ip)
{
this.IP = ip;
}
public int Close()
{
try
{
IsConnect = false;
int ErrCode = ReaderA.StaticClassReaderA.CloseNetPort(portIndex);
LOGGER.Info("Close RFID [" + IP + "]:" + ErrCode);
return ErrCode;
}
catch (Exception e)
{
LOGGER.Error("Close RFID[" + IP + "] has error", e);
}
return -1;
}
public int Open()
{
if (IsConnect)
{
LOGGER.Warn(" RFID [" + IP + "] is already connected, no need to start again");
return 0;
}
//IP合法
string pattern = @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$";
bool rtn = System.Text.RegularExpressions.Regex.IsMatch(IP, pattern);
if (!rtn)
{
LOGGER.Error(IP + " is error");
return -1;
}
string[] arr = IP.Split('.');
if (arr.Length != 4)
{
LOGGER.Error(IP + " length is not 4");
return -1;
}
addr = Convert.ToByte(arr[3]);
int port = 6000 + Convert.ToInt32(arr[3]);
portIndex = 0;
int ErrCode = ReaderA.StaticClassReaderA.OpenNetPort(port, IP, ref addr, ref portIndex);
LOGGER.Info("Connect [" + IP + "] :" + ErrCode);
// 在 OpenNetPort 后面使用
System.Threading.Thread.Sleep(100);
OpenCloseRF(false);
System.Threading.Thread.Sleep(100);
OpenCloseRF(true);
return ErrCode;
}
private void OpenCloseRF(bool rtn)
{
if (rtn)
ErrCode = ReaderA.StaticClassReaderA.OpenRf(ref addr, portIndex);
else
ErrCode = ReaderA.StaticClassReaderA.CloseRf(ref addr, portIndex);
}
/// <summary>
/// 查找电子标签,扫描模式不能使用
/// </summary>
/// <returns></returns>
public bool FindRFID()
{
//0 不带AFI
//1 带AFI
//2 不带AFI,继续查询
//3 带AFI,继续查询
//6 不带AFI,新的查询
//7 带AFI,新的查询
byte state = 0;
//Select模式需要AFI
byte AFI = 0;
//输出,1字节DSFID,8字节UID
byte[] DSFIDAndUID = new byte[9];
//输出,标签数量
byte cardNumber = 0;
ErrCode = ReaderA.StaticClassReaderA.Inventory(ref addr, ref state, ref AFI, DSFIDAndUID, ref cardNumber, portIndex);
if (ErrCode == 0)
{
//查询时间
//fCmdRet = StaticClassReaderA.GetInventoryTime(ref n_time, portIndex);
Array.Copy(DSFIDAndUID, 1, _uid, 0, 8);
IsExist = true;
return true;
}
else
{
for (int i = 0; i < _uid.Length; i++)
_uid[i] = 0;
IsExist = false;
return false;
}
}
public byte[] Read(bool isNeedFind = false)
{
if (isNeedFind)
{
FindRFID();
}
if (IsExist)
{
ReadRFID();
return _buff;
}
else
{
LOGGER.Info(IP + " Read: IsExist=false ");
}
return null;
}
private void ReadRFID()
{
//0 不带AFI
//1 带AFI
//2 不带AFI,继续查询
//3 带AFI,继续查询
//6 不带AFI,新的查询
//7 带AFI,新的查询
byte state = 0;
//起始块号
byte blockNum = 0;
//块数量
byte blockCount = 2;
//输出,块内安全信息,长度为BlockCount个字节
byte[] blockSecStatus = new byte[blockCount];
//输出,块内数据信息,长度为块的大小(4或8字节)乘以BlockCount个字节
byte[] data = new byte[4 * blockCount];
//错误代码
byte errorCode = 0;
ErrCode = ReaderA.StaticClassReaderA.ReadMultipleBlock(ref addr, ref state, _uid, blockNum, blockCount, blockSecStatus, data, ref errorCode, portIndex);
if (ErrCode == 0)
{
Array.Copy(data, 0, _buff, 0, data.Length);
string dataStr = byteToStr(data, data.Length);
LOGGER.Info(IP + " ReadMultipleBlock: Length: " + data.Length + " Data:" + dataStr);
}
else
{
LOGGER.Info(IP + " ReadMultipleBlock: ErrCode: " + ErrCode);
}
}
private string byteToStr(byte[] data, int len)
{
string s = "";
for (int i = 0; i < len; i++)
{
s += data[i].ToString("X2") + " ";
}
return s;
}
}
public class RFIDReader
{
public static readonly ILog LOGGER = LogManager.GetLogger("TheRFID");
private static Dictionary<string, RFID> rfidMap = new Dictionary<string, RFID>();
public static void Open(params string[] ipArr)
{
foreach (var ip in ipArr)
{
if (rfidMap.ContainsKey(ip))
{
rfidMap[ip].Open();
}
else
{
RFID rfid = new RFID(ip);
rfid.Open();
rfidMap.Add(ip, rfid);
}
}
}
public static bool FindRFID(string ip)
{
if (rfidMap.ContainsKey(ip))
{
return rfidMap[ip].FindRFID();
}
return false;
}
public static byte[] Read(string ip, bool isNeedFind)
{
if (rfidMap.ContainsKey(ip))
{
return rfidMap[ip].Read(isNeedFind);
}
return null;
}
public static void CloseAll()
{
foreach (var rfid in rfidMap.Values)
{
rfid.Close();
}
}
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!