Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
RC1250-AssemblyLine
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 4d18eddc
由
LN
编写于
2020-01-02 16:48:54 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
1
1 个父辈
73248902
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
390 行增加
和
369 行删除
source/DeviceLibrary/DeviceLibrary.csproj
source/DeviceLibrary/assemblyLine/EquipBase.cs
source/DeviceLibrary/assemblyLine/LineBean.cs
source/DeviceLibrary/deviceLibrary/RFID/RFID.cs
source/DeviceLibrary/deviceLibrary/RFID/RFIDManager.cs
source/DeviceLibrary/deviceLibrary/RFID/RFIDReader.cs
source/DeviceLibrary/DeviceLibrary.csproj
查看文件 @
4d18edd
...
@@ -95,6 +95,8 @@
...
@@ -95,6 +95,8 @@
<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\RFID.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>
...
...
source/DeviceLibrary/assemblyLine/EquipBase.cs
查看文件 @
4d18edd
...
@@ -225,6 +225,7 @@ namespace OnlineStore.DeviceLibrary
...
@@ -225,6 +225,7 @@ namespace OnlineStore.DeviceLibrary
/// </summary>
/// </summary>
internal
virtual
void
OpenStopCylinder
()
internal
virtual
void
OpenStopCylinder
()
{
{
preRWTime
=
DateTime
.
Now
;
if
(
baseConfig
.
DType
.
Equals
(
DeviceType
.
MoveEquip
)
||
baseConfig
.
DType
.
Equals
(
DeviceType
.
ProvidingEquip
))
if
(
baseConfig
.
DType
.
Equals
(
DeviceType
.
MoveEquip
)
||
baseConfig
.
DType
.
Equals
(
DeviceType
.
ProvidingEquip
))
{
{
LogInfo
(
"OpenStopCylinder: 下降阻挡气缸,上下气缸上升,顶升气缸下降"
);
LogInfo
(
"OpenStopCylinder: 下降阻挡气缸,上下气缸上升,顶升气缸下降"
);
...
@@ -240,6 +241,49 @@ namespace OnlineStore.DeviceLibrary
...
@@ -240,6 +241,49 @@ namespace OnlineStore.DeviceLibrary
Thread
.
Sleep
(
30
);
Thread
.
Sleep
(
30
);
}
}
}
}
internal
virtual
bool
OpenStopCylinderOk
(
TimeSpan
span
)
{
TimeSpan
rwSpan
=
DateTime
.
Now
-
preRWTime
;
if
(
baseConfig
.
DType
.
Equals
(
DeviceType
.
MoveEquip
)
||
baseConfig
.
DType
.
Equals
(
DeviceType
.
ProvidingEquip
))
{
if
(
IOValue
(
IO_Type
.
StopCylinder_Down1
).
Equals
(
IO_VALUE
.
HIGH
)
&&
IOValue
(
IO_Type
.
StopCylinder_Down2
).
Equals
(
IO_VALUE
.
HIGH
))
{
return
true
;
}
else
if
(
rwSpan
.
TotalSeconds
>
5
&&
span
.
TotalSeconds
>
6
&&
span
.
TotalMilliseconds
<
LineManager
.
Config
.
IOSingle_TimerOut
*
2
)
{
preRWTime
=
DateTime
.
Now
;
IOMove
(
IO_Type
.
StopCylinder_Down1
,
IO_VALUE
.
HIGH
);
IOMove
(
IO_Type
.
StopCylinder_Down2
,
IO_VALUE
.
HIGH
);
}
}
else
if
(
baseConfig
.
DType
.
Equals
(
DeviceType
.
DischargeLine
))
{
return
true
;
}
else
if
(
baseConfig
.
DType
.
Equals
(
DeviceType
.
FeedingEquip
))
{
if
(
DeviceID
.
Equals
(
102
))
{
if
(
IOValue
(
IO_Type
.
FL_StopCylinder_Down1
).
Equals
(
IO_VALUE
.
HIGH
)
&&
IOValue
(
IO_Type
.
FL_StopCylinder_Down2
).
Equals
(
IO_VALUE
.
HIGH
))
{
return
true
;
}
else
if
(
rwSpan
.
TotalSeconds
>
5
&&
span
.
TotalSeconds
>
6
&&
span
.
TotalMilliseconds
<
LineManager
.
Config
.
IOSingle_TimerOut
*
2
)
{
IOMove
(
IO_Type
.
FL_StopCylinder_Down1
,
IO_VALUE
.
HIGH
);
IOMove
(
IO_Type
.
FL_StopCylinder_Down2
,
IO_VALUE
.
HIGH
);
}
}
else
{
return
true
;
}
}
return
false
;
}
internal
virtual
void
CloseCylinderStop
()
internal
virtual
void
CloseCylinderStop
()
{
{
if
(
baseConfig
.
DType
.
Equals
(
DeviceType
.
MoveEquip
)
||
baseConfig
.
DType
.
Equals
(
DeviceType
.
ProvidingEquip
))
if
(
baseConfig
.
DType
.
Equals
(
DeviceType
.
MoveEquip
)
||
baseConfig
.
DType
.
Equals
(
DeviceType
.
ProvidingEquip
))
...
...
source/DeviceLibrary/assemblyLine/LineBean.cs
查看文件 @
4d18edd
...
@@ -904,6 +904,17 @@ namespace OnlineStore.DeviceLibrary
...
@@ -904,6 +904,17 @@ namespace OnlineStore.DeviceLibrary
{
{
if
(
moveEquip
.
IsDebug
)
if
(
moveEquip
.
IsDebug
)
{
{
TimeSpan
span
=
DateTime
.
Now
-
MoveInfo
.
LastSetpTime
;
if
(!
moveEquip
.
OpenStopCylinderOk
(
span
))
{
if
(
span
.
TotalSeconds
>
LineManager
.
Config
.
IOSingle_TimerOut
)
{
SetWarnMsg
(
moveEquip
.
Name
+
"下降阻挡气缸超时,已等待"
+
FormUtil
.
GetSpanStr
(
span
));
LogUtil
.
error
(
moveEquip
.
Name
+
"下降阻挡气缸超时,已等待"
+
FormUtil
.
GetSpanStr
(
span
),
112
);
}
isOk
=
false
;
break
;
}
continue
;
continue
;
}
}
if
(
moveEquip
.
runStatus
.
Equals
(
LineRunStatus
.
HomeMoving
)
||
moveEquip
.
runStatus
.
Equals
(
LineRunStatus
.
Reset
)
||
moveEquip
.
runStatus
.
Equals
(
LineRunStatus
.
Wait
))
if
(
moveEquip
.
runStatus
.
Equals
(
LineRunStatus
.
HomeMoving
)
||
moveEquip
.
runStatus
.
Equals
(
LineRunStatus
.
Reset
)
||
moveEquip
.
runStatus
.
Equals
(
LineRunStatus
.
Wait
))
...
@@ -926,6 +937,10 @@ namespace OnlineStore.DeviceLibrary
...
@@ -926,6 +937,10 @@ namespace OnlineStore.DeviceLibrary
if
(
isOk
)
if
(
isOk
)
{
{
if
(
WarnMsg
.
Contains
(
"下降阻挡气缸超时"
))
{
SetWarnMsg
(
""
);
}
PreIsHasProcess
=
false
;
PreIsHasProcess
=
false
;
//打开流水线
//打开流水线
WriteDrivetMotorRun
(
IO_VALUE
.
HIGH
);
WriteDrivetMotorRun
(
IO_VALUE
.
HIGH
);
...
...
source/DeviceLibrary/deviceLibrary/RFID/RFID.cs
0 → 100644
查看文件 @
4d18edd
using
log4net
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
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
];
/// <summary>
/// 接收事件
/// </summary>
/// <param name="ip"></param>
/// <param name="buff"></param>
public
delegate
void
Received_Event
(
string
ip
,
byte
[]
buff
);
/// <summary>
/// 接收数据
/// </summary>
public
event
Received_Event
Received
;
public
RFID
(
string
ip
)
{
this
.
IP
=
ip
;
}
public
int
StopAutoScan
()
{
LOGGER
.
Info
(
"Close RFID ["
+
IP
+
"]"
);
IsConnect
=
false
;
byte
scanMode
=
0
;
return
SetAutoScanMode
(
addr
,
scanMode
);
}
public
int
StartAutoScan
(
Received_Event
OnReceive
)
{
if
(
IsConnect
)
{
LOGGER
.
Warn
(
" RFID ["
+
IP
+
"] is already connected, no need to start again"
);
return
0
;
}
this
.
Received
=
OnReceive
;
//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
);
if
(
ErrCode
==
0
)
{
ErrCode
=
OpenAutoScanMode
(
addr
);
LOGGER
.
Info
(
" ["
+
IP
+
"] Open Auto Scan Mode:"
+
ErrCode
);
Task
.
Factory
.
StartNew
(
AutoScan
);
}
return
ErrCode
;
}
private
int
SetAutoScanMode
(
byte
addr
,
byte
scanMode
)
{
byte
[]
scanModeData
=
new
byte
[
11
];
//bit0: 0停止扫描,1开始扫描
//bit1: 0正常数据扫描,1EAS扫描
//bit2: 0正常灵敏度,1高灵敏度
//bit3: 0禁止输入同步,1允许输入同步
//bit4: 0禁止指令同步,1允许指令同步
//bit5: 0禁止扫描提示,1允许扫描提示
//bit6: 0禁止EAS探测提示,1允许EAS探测提示
//bit7: 0禁止EAS消息输出提示,1允许EAS消息输出提示
scanModeData
[
0
]
=
scanMode
;
//bit0: 0不发送comAddr,1发送comAddr
//bit1: 0不带UID,1带UID
//bit2: 0不包含指定块,1包含指定块
//bit3: 0不带安全状态字,1带安全状态字
//bit4: 0 ASCII,1 HEX
//bit5: 0不进行开关射频场,1进行开关射频场
//bit6: 0无操作,1停止扫描关闭射频场
//bit7: 0无,1鸣叫闪烁
scanModeData
[
1
]
=
255
;
scanModeData
[
2
]
=
0
;
//起始块号
scanModeData
[
3
]
=
2
;
//块总数 之前是28
scanModeData
[
4
]
=
1
;
//块的起始字节
scanModeData
[
5
]
=
4
;
//块的字节数
//1 CR+LF 0x0D 0x0A
//2 CR 0x0D
//4 LF 0x0A
//8 BEL 0x07
//16 :(分号) 0x3B
//32 ,(逗号) 0x2C
//64 " "(空格) 0x20
//128 自定义
scanModeData
[
6
]
=
8
;
//间隔符
scanModeData
[
7
]
=
0
;
//自定义间隔符,[6] = 128
//1 CR+LF 0x0D 0x0A
//2 CR 0x0D
//4 LF 0x0A
//8 BEL 0x07
//16 :(分号) 0x3B
//32 ,(逗号) 0x2C
//64 " "(空格) 0x20
//128 自定义
scanModeData
[
8
]
=
8
;
//结束符
scanModeData
[
9
]
=
0
;
//自定义间隔符,[8] = 128
scanModeData
[
10
]
=
0x00
;
int
ErrCode
=
ReaderA
.
StaticClassReaderA
.
SetScanMode
(
ref
addr
,
scanModeData
,
portIndex
);
return
ErrCode
;
}
private
void
AutoScan
()
{
IsConnect
=
true
;
while
(
IsConnect
)
{
try
{
byte
[]
data
=
new
byte
[
100
];
int
len
=
0
;
int
ErrCode
=
ReaderA
.
StaticClassReaderA
.
ReadScanModeData
(
data
,
ref
len
,
portIndex
);
if
(
ErrCode
==
0
)
{
string
dataStr
=
byteToStr
(
data
,
len
);
LOGGER
.
Debug
(
IP
+
" Receive Code: "
+
ErrCode
+
" Len: "
+
len
+
" Data:"
+
dataStr
);
byte
[]
bb
=
new
byte
[
10
];
int
idx
=
-
1
;
bool
start
=
false
;
bool
end
=
false
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
byte
b
=
data
[
i
];
if
(
b
==
0x5A
)
{
start
=
true
;
idx
=
0
;
//bb[idx++] = result;
}
else
if
(
b
==
0x4A
&&
start
)
{
start
=
false
;
end
=
true
;
bb
[
idx
++]
=
b
;
}
if
(
start
)
{
if
(
idx
+
1
==
bb
.
Length
)
{
start
=
false
;
end
=
false
;
}
else
{
bb
[
idx
++]
=
b
;
}
}
if
(
end
)
{
byte
[]
_buff
=
new
byte
[
8
];
_buff
[
0
]
=
bb
[
0
];
_buff
[
1
]
=
bb
[
1
];
_buff
[
2
]
=
bb
[
2
];
_buff
[
3
]
=
bb
[
3
];
_buff
[
4
]
=
bb
[
5
];
_buff
[
5
]
=
bb
[
6
];
_buff
[
6
]
=
0
;
_buff
[
7
]
=
0
;
end
=
false
;
string
itemStr
=
byteToStr
(
_buff
,
_buff
.
Length
);
lastData
=
_buff
;
LOGGER
.
Debug
(
"["
+
IP
+
"] Item:"
+
itemStr
);
Received
?.
Invoke
(
IP
,
_buff
);
}
}
}
System
.
Threading
.
Thread
.
Sleep
(
60
);
}
catch
(
Exception
e
)
{
LOGGER
.
Error
(
"ReadScanModeData Error:"
,
e
);
}
}
}
public
byte
[]
ReadAndClear
()
{
byte
[]
data
=
lastData
;
lastData
=
new
byte
[
8
];
LOGGER
.
Info
(
"Read and clear RFID["
+
IP
+
"] data:"
+
byteToStr
(
data
,
data
.
Length
));
return
data
;
}
public
byte
[]
Read
()
{
return
lastData
;
}
private
int
OpenAutoScanMode
(
byte
addr
)
{
byte
scanMode
=
1
;
return
SetAutoScanMode
(
addr
,
scanMode
);
}
private
string
byteToStr
(
byte
[]
data
,
int
len
)
{
string
s
=
""
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
s
+=
data
[
i
].
ToString
(
"X2"
)
+
" "
;
}
return
s
;
}
}
}
source/DeviceLibrary/deviceLibrary/RFID/RFIDManager.cs
deleted
100644 → 0
查看文件 @
7324890
using
Asa.RFID
;
using
OnlineStore.Common
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading
;
using
System.Threading.Tasks
;
namespace
OnlineStore.DeviceLibrary
{
public
class
RFIDManager
{
public
static
Dictionary
<
string
,
Reader
>
RFReaderMap
=
new
Dictionary
<
string
,
Reader
>();
private
static
List
<
string
>
RfIPList
=
new
List
<
string
>();
private
static
System
.
Timers
.
Timer
conTimer
=
null
;
public
static
void
ConnectRFIOList
(
List
<
string
>
rfioNameList
)
{
try
{
if
(
conTimer
==
null
)
{
conTimer
=
new
System
.
Timers
.
Timer
();
conTimer
.
AutoReset
=
true
;
conTimer
.
Interval
=
60000
;
conTimer
.
Elapsed
+=
ConTimer_Elapsed
;
}
conTimer
.
Enabled
=
false
;
RfIPList
=
new
List
<
string
>(
rfioNameList
);
foreach
(
string
ip
in
rfioNameList
)
{
ConnectionIP
(
ip
);
}
if
(
RfIPList
.
Count
>
0
)
{
conTimer
.
Start
();
}
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"ConnectRFIOList出错:"
+
ex
.
ToString
());
}
}
private
static
int
DefaultTrayNum
=
ConfigAppSettings
.
GetIntValue
(
Setting_Init
.
DefaultTrayNum
);
/// <summary>
/// 获取托盘编码
/// </summary>
public
static
int
GetTrayNum
(
int
subType
,
bool
isClear
=
false
)
{
if
(
DefaultTrayNum
>
0
)
{
return
DefaultTrayNum
;
}
// return 9;
if
(
subType
.
Equals
(
104
))
{
return
LineManager
.
Line
.
Sw23TrayNum
;
}
else
if
(
subType
.
Equals
(
101
))
{
return
LineManager
.
Line
.
Sw41TrayNum
;
}
string
ip
=
GetRFIP
(
subType
);
//获取盘号
RFIDData
data
=
ReadRFID
(
ip
,
isClear
);
if
(
data
!=
null
)
{
if
(
data
.
RFType
.
Equals
((
byte
)
'E'
))
{
return
data
.
Num
;
}
else
if
(
data
.
RFType
>
0
)
{
LogUtil
.
error
(
"RFID [ "
+
ip
+
" ] 读到数据 "
+
data
.
ToStr
()
+
" 返回盘号 0"
);
}
else
{
LogUtil
.
debug
(
"RFID [ "
+
ip
+
" ] 读到数据 "
+
data
.
ToStr
()
+
" 返回盘号 0"
);
}
return
0
;
}
return
0
;
}
public
static
RFIDData
GetShelfData
(
int
subType
)
{
string
ip
=
GetRFIP
(
subType
,
1
);
return
ReadRFID
(
ip
);
}
public
static
RFIDData
ReadRFID
(
string
ip
,
bool
isClear
=
false
)
{
try
{
if
(
String
.
IsNullOrEmpty
(
ip
).
Equals
(
false
)
&&
LineManager
.
Line
.
rfidList
.
Contains
(
ip
))
{
RFIDData
data
=
new
RFIDData
(
RfidReader
.
Read
(
ip
));
if
(
isClear
)
{
RfidReader
.
Clear
(
ip
);
}
return
data
;
}
}
catch
(
Exception
ex
)
{
//LogUtil.error("ReadRFID["+ip+"]出错:" + ex.ToString());
}
return
new
RFIDData
(-
1
,
-
1
);
}
public
static
string
GetRFIP
(
int
subType
,
int
rtType
=
0
)
{
string
ip
=
""
;
string
rtName
=
DeviceConfig
.
RFIP_Str
+
"_"
+
subType
.
ToString
().
PadLeft
(
3
,
'0'
);
if
(
rtType
>
0
)
{
rtName
+=
"-"
+
rtType
.
ToString
();
}
if
(
DeviceConfig
.
ProRFIpMap
.
ContainsKey
(
rtName
))
{
ip
=
DeviceConfig
.
ProRFIpMap
[
rtName
];
}
return
ip
;
}
private
static
bool
isProcess
=
false
;
private
static
DateTime
lastTime
=
DateTime
.
Now
;
public
static
bool
IsConnect
(
string
ip
)
{
if
(
RFReaderMap
.
ContainsKey
(
ip
))
{
return
true
;
}
return
false
;
}
private
static
void
ConTimer_Elapsed
(
object
sender
,
System
.
Timers
.
ElapsedEventArgs
e
)
{
TimeSpan
span
=
DateTime
.
Now
-
lastTime
;
if
(
span
.
TotalMinutes
<
RfIPList
.
Count
&&
isProcess
)
{
return
;
}
isProcess
=
true
;
lastTime
=
DateTime
.
Now
;
try
{
List
<
string
>
list
=
new
List
<
string
>(
RfIPList
);
if
(
list
.
Count
>
0
)
{
LogUtil
.
info
(
"开始重连RFIP模块 ------------"
);
foreach
(
string
ip
in
list
)
{
ConnectionIP
(
ip
);
}
LogUtil
.
info
(
"结束重连RFIP模块 ------------"
);
}
GC
.
Collect
();
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"RFIP ConTimer_Elapsed 出错: "
+
ex
.
ToString
());
}
isProcess
=
false
;
}
public
static
bool
ConnectionIP
(
string
rfid
)
{
Reader
rfidReader
=
null
;
CloseRFID
(
rfid
);
string
logName
=
"RFIP模块["
+
rfid
+
"] "
;
try
{
LogUtil
.
debug
(
"开始连接"
+
logName
+
",尝试重连3次"
);
rfidReader
=
new
Reader
();
bool
result
=
rfidReader
.
Connect
(
rfid
,
true
);
if
(
result
)
{
//rfidReader.AutoScan(true);
LogUtil
.
info
(
"连接 "
+
logName
+
"成功"
);
RFReaderMap
.
Add
(
rfid
,
rfidReader
);
if
(
RfIPList
.
Contains
(
rfid
))
{
RfIPList
.
Remove
(
rfid
);
}
return
true
;
}
else
{
LogUtil
.
error
(
"连接 "
+
logName
+
"失败"
+
""
);
}
Thread
.
Sleep
(
5
);
}
catch
(
Exception
error
)
{
LogUtil
.
error
(
"连接RFIP模块 "
+
logName
+
" 出错:"
+
error
.
ToString
());
}
return
false
;
}
public
static
void
CloseRFID
(
string
rfid
)
{
try
{
if
(
RFReaderMap
.
ContainsKey
(
rfid
))
{
Reader
rfidReader
=
RFReaderMap
[
rfid
];
if
(
null
!=
rfidReader
)
{
rfidReader
.
Close
();
rfidReader
=
null
;
}
RFReaderMap
.
Remove
(
rfid
);
}
}
catch
(
Exception
exx
)
{
LogUtil
.
error
(
"关闭rfid【"
+
rfid
+
"】出错:"
+
rfid
);
}
}
public
static
void
CloseAllConnection
()
{
foreach
(
Reader
reader
in
RFReaderMap
.
Values
)
{
reader
.
Close
();
}
}
public
static
RFIDData
ReadData
(
string
IP
)
{
byte
[]
reviceData
=
ReadData
(
IP
,
3
);
if
(
reviceData
!=
null
)
{
return
new
RFIDData
(
reviceData
);
}
return
null
;
}
private
static
bool
FindRFID
(
string
IP
)
{
try
{
Reader
rfReader
=
getRfReader
(
IP
);
if
(
rfReader
!=
null
)
{
return
rfReader
.
FindRFID
();
}
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"RFIP FindRFID ["
+
IP
+
"] 出错 :"
+
ex
.
ToString
());
}
return
false
;
}
private
static
byte
[]
ReadData
(
string
IP
,
int
reReadCount
=
1
,
int
startIndex
=
0
,
int
readLength
=
4
)
{
try
{
Reader
rfReader
=
getRfReader
(
IP
);
if
(
rfReader
==
null
)
{
return
null
;
}
for
(
int
i
=
1
;
i
<=
reReadCount
;
i
++)
{
byte
[]
reviceData
=
rfReader
.
Read
(
startIndex
,
readLength
);
if
(
reviceData
!=
null
)
{
return
reviceData
;
}
LogUtil
.
error
(
"RFIP ReadData ["
+
IP
+
"] 第"
+
i
+
"次失败 "
);
}
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"RFIP ReadData ["
+
IP
+
"] 出错 :"
+
ex
.
ToString
());
}
return
null
;
}
private
static
bool
WriteData
(
string
IP
,
byte
[]
data
,
int
reWriteCount
=
1
)
{
try
{
Reader
rfReader
=
getRfReader
(
IP
);
if
(
rfReader
==
null
)
{
return
false
;
}
for
(
int
i
=
1
;
i
<=
reWriteCount
;
i
++)
{
bool
result
=
rfReader
.
Write
(
data
);
if
(
result
)
{
return
result
;
}
LogUtil
.
error
(
"RFIP WriteData ["
+
IP
+
"] 第"
+
i
+
"次失败:"
);
}
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"RFIP WriteData ["
+
IP
+
"] 出错 :"
+
ex
.
ToString
());
}
return
false
;
}
private
static
Reader
getRfReader
(
string
IP
)
{
Reader
rfReader
=
null
;
if
(
RFReaderMap
.
ContainsKey
(
IP
))
{
rfReader
=
RFReaderMap
[
IP
];
}
else
{
LogUtil
.
error
(
"getRfReader 没有连接RFIP模块:"
+
IP
);
}
return
rfReader
;
}
}
public
class
RFIDData
{
/// <summary>
/// RFID类型,区分是料架还是托盘,托盘E=69,A=65
/// </summary>
public
int
RFType
=
0
;
/// <summary>
/// 托盘编号,从1-32
/// </summary>
public
int
Num
=
0
;
public
RFIDData
(
int
num
,
int
t
)
{
this
.
RFType
=
t
;
this
.
Num
=
num
;
}
public
RFIDData
(
byte
[]
data
)
{
try
{
if
(
data
!=
null
&&
data
.
Length
>
2
)
{
RFType
=
data
[
1
];
Num
=
Convert
.
ToInt32
(
data
[
2
]);
}
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"RFIP 数据【"
+
data
+
"】 获取编码失败"
);
}
}
public
byte
[]
ToData
()
{
return
new
byte
[]
{
(
byte
)
RFType
,
(
byte
)
Num
};
}
public
string
ToStr
()
{
return
" ["
+
RFType
+
"],["
+
Num
+
"] "
;
}
}
}
source/DeviceLibrary/deviceLibrary/RFID/RFIDReader.cs
0 → 100644
查看文件 @
4d18edd
using
log4net
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
static
Asa
.
RFID
.
RFID
;
namespace
Asa.RFID
{
public
class
RFIDReader
{
public
static
readonly
ILog
LOGGER
=
LogManager
.
GetLogger
(
"TheRFID"
);
private
Dictionary
<
string
,
RFID
>
rfidMap
=
new
Dictionary
<
string
,
RFID
>();
/// <summary>
/// 打开所有
/// </summary>
/// <param name="ipArr"></param>
/// <param name="OnReceive"></param>
/// <param name="ip"></param>
public
void
Open
(
Received_Event
OnReceive
,
params
string
[]
ipArr
)
{
foreach
(
var
ip
in
ipArr
)
{
if
(
rfidMap
.
ContainsKey
(
ip
))
{
rfidMap
[
ip
].
StopAutoScan
(
OnReceive
);
}
else
{
RFID
rfid
=
new
RFID
(
ip
);
rfid
.
StartAutoScan
(
OnReceive
);
rfidMap
.
Add
(
ip
,
rfid
);
}
}
}
/// <summary>
/// 获取最后读到的标签并清理
/// </summary>
/// <param name="ip"></param>
/// <returns></returns>
public
byte
[]
ReadAndClear
(
string
ip
)
{
if
(
rfidMap
.
ContainsKey
(
ip
))
{
return
rfidMap
[
ip
].
ReadAndClear
();
}
return
null
;
}
/// <summary>
/// 获取最后读到的标签
/// </summary>
/// <param name="ip"></param>
/// <returns></returns>
public
byte
[]
Read
(
string
ip
)
{
if
(
rfidMap
.
ContainsKey
(
ip
))
{
return
rfidMap
[
ip
].
Read
();
}
return
null
;
}
/// <summary>
/// 关闭所有
/// </summary>
public
void
CloseAll
()
{
foreach
(
var
rfid
in
rfidMap
.
Values
)
{
rfid
.
StopAutoScan
();
}
}
}
}
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论