Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
RC1250-AssemblyLine
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 01c8f861
由
LN
编写于
2020-02-14 16:25:51 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
料架修改
1 个父辈
52d7b130
显示空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
244 行增加
和
212 行删除
dll/Client.dll
dll/Client.xml
source/AssemblyLineClient/FrmLineStore.Designer.cs
source/AssemblyLineClient/Program.cs
source/DeviceLibrary/DeviceLibrary.csproj
source/DeviceLibrary/assemblyLine/LineBean.cs
source/DeviceLibrary/assemblymanager/RFIDManagercs.cs
source/DeviceLibrary/deviceLibrary/RFID/RFID.cs
source/DeviceLibrary/deviceLibrary/RFID/RFIDReader.cs
dll/Client.dll
查看文件 @
01c8f86
此文件类型无法预览
dll/Client.xml
查看文件 @
01c8f86
...
...
@@ -276,13 +276,6 @@
<param
name=
"action"
></param>
<param
name=
"level"
></param>
</member>
<member
name=
"M:Asa.Client2.Reconnect"
>
<summary>
发送RFID
</summary>
<param
name=
"name"
></param>
<param
name=
"content"
></param>
</member>
<member
name=
"M:Asa.Client2.Splice(Asa.ClientNode)"
>
<summary>
拼接命令
...
...
source/AssemblyLineClient/FrmLineStore.Designer.cs
查看文件 @
01c8f86
...
...
@@ -32,6 +32,7 @@
System
.
ComponentModel
.
ComponentResourceManager
resources
=
new
System
.
ComponentModel
.
ComponentResourceManager
(
typeof
(
FrmLineStore
));
this
.
tabControl1
=
new
System
.
Windows
.
Forms
.
TabControl
();
this
.
tabPage1
=
new
System
.
Windows
.
Forms
.
TabPage
();
this
.
checkBox1
=
new
System
.
Windows
.
Forms
.
CheckBox
();
this
.
logBox
=
new
System
.
Windows
.
Forms
.
RichTextBox
();
this
.
lblCID
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
groupBox3
=
new
System
.
Windows
.
Forms
.
GroupBox
();
...
...
@@ -98,7 +99,6 @@
this
.
toolStripSeparator8
=
new
System
.
Windows
.
Forms
.
ToolStripSeparator
();
this
.
toolStripMenuItem1
=
new
System
.
Windows
.
Forms
.
ToolStripMenuItem
();
this
.
timer1
=
new
System
.
Windows
.
Forms
.
Timer
(
this
.
components
);
this
.
checkBox1
=
new
System
.
Windows
.
Forms
.
CheckBox
();
this
.
tabControl1
.
SuspendLayout
();
this
.
tabPage1
.
SuspendLayout
();
this
.
groupBox3
.
SuspendLayout
();
...
...
@@ -141,6 +141,20 @@
this
.
tabPage1
.
Text
=
"状态信息"
;
this
.
tabPage1
.
UseVisualStyleBackColor
=
true
;
//
// checkBox1
//
this
.
checkBox1
.
AutoSize
=
true
;
this
.
checkBox1
.
Checked
=
true
;
this
.
checkBox1
.
CheckState
=
System
.
Windows
.
Forms
.
CheckState
.
Checked
;
this
.
checkBox1
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
10.5F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
checkBox1
.
Location
=
new
System
.
Drawing
.
Point
(
478
,
137
);
this
.
checkBox1
.
Name
=
"checkBox1"
;
this
.
checkBox1
.
Size
=
new
System
.
Drawing
.
Size
(
119
,
24
);
this
.
checkBox1
.
TabIndex
=
198
;
this
.
checkBox1
.
Text
=
"启用agvClient"
;
this
.
checkBox1
.
UseVisualStyleBackColor
=
true
;
this
.
checkBox1
.
CheckedChanged
+=
new
System
.
EventHandler
(
this
.
checkBox1_CheckedChanged
);
//
// logBox
//
this
.
logBox
.
Anchor
=
((
System
.
Windows
.
Forms
.
AnchorStyles
)((((
System
.
Windows
.
Forms
.
AnchorStyles
.
Top
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Bottom
)
...
...
@@ -599,7 +613,7 @@
// 扫码测试ToolStripMenuItem
//
this
.
扫码测试
ToolStripMenuItem
.
Name
=
"扫码测试ToolStripMenuItem"
;
this
.
扫码测试
ToolStripMenuItem
.
Size
=
new
System
.
Drawing
.
Size
(
1
80
,
26
);
this
.
扫码测试
ToolStripMenuItem
.
Size
=
new
System
.
Drawing
.
Size
(
1
76
,
26
);
this
.
扫码测试
ToolStripMenuItem
.
Text
=
"扫码测试"
;
this
.
扫码测试
ToolStripMenuItem
.
Visible
=
false
;
this
.
扫码测试
ToolStripMenuItem
.
Click
+=
new
System
.
EventHandler
(
this
.
扫码测试
ToolStripMenuItem_Click
);
...
...
@@ -607,61 +621,61 @@
// toolStripSeparator6
//
this
.
toolStripSeparator6
.
Name
=
"toolStripSeparator6"
;
this
.
toolStripSeparator6
.
Size
=
new
System
.
Drawing
.
Size
(
17
7
,
6
);
this
.
toolStripSeparator6
.
Size
=
new
System
.
Drawing
.
Size
(
17
3
,
6
);
this
.
toolStripSeparator6
.
Visible
=
false
;
//
// 二维码学习ToolStripMenuItem
//
this
.
二维码学习
ToolStripMenuItem
.
Name
=
"二维码学习ToolStripMenuItem"
;
this
.
二维码学习
ToolStripMenuItem
.
Size
=
new
System
.
Drawing
.
Size
(
1
80
,
26
);
this
.
二维码学习
ToolStripMenuItem
.
Size
=
new
System
.
Drawing
.
Size
(
1
76
,
26
);
this
.
二维码学习
ToolStripMenuItem
.
Text
=
"二维码学习"
;
this
.
二维码学习
ToolStripMenuItem
.
Click
+=
new
System
.
EventHandler
(
this
.
二维码学习
ToolStripMenuItem_Click
);
//
// toolStripSeparator7
//
this
.
toolStripSeparator7
.
Name
=
"toolStripSeparator7"
;
this
.
toolStripSeparator7
.
Size
=
new
System
.
Drawing
.
Size
(
17
7
,
6
);
this
.
toolStripSeparator7
.
Size
=
new
System
.
Drawing
.
Size
(
17
3
,
6
);
//
// 托盘初始化ToolStripMenuItem
//
this
.
托盘初始化
ToolStripMenuItem
.
Name
=
"托盘初始化ToolStripMenuItem"
;
this
.
托盘初始化
ToolStripMenuItem
.
Size
=
new
System
.
Drawing
.
Size
(
1
80
,
26
);
this
.
托盘初始化
ToolStripMenuItem
.
Size
=
new
System
.
Drawing
.
Size
(
1
76
,
26
);
this
.
托盘初始化
ToolStripMenuItem
.
Text
=
"托盘编码"
;
this
.
托盘初始化
ToolStripMenuItem
.
Click
+=
new
System
.
EventHandler
(
this
.
托盘初始化
ToolStripMenuItem_Click
);
//
// toolStripSeparator9
//
this
.
toolStripSeparator9
.
Name
=
"toolStripSeparator9"
;
this
.
toolStripSeparator9
.
Size
=
new
System
.
Drawing
.
Size
(
17
7
,
6
);
this
.
toolStripSeparator9
.
Size
=
new
System
.
Drawing
.
Size
(
17
3
,
6
);
//
// iO模块状态ToolStripMenuItem
//
this
.
iO
模块状态
ToolStripMenuItem
.
Name
=
"iO模块状态ToolStripMenuItem"
;
this
.
iO
模块状态
ToolStripMenuItem
.
Size
=
new
System
.
Drawing
.
Size
(
1
80
,
26
);
this
.
iO
模块状态
ToolStripMenuItem
.
Size
=
new
System
.
Drawing
.
Size
(
1
76
,
26
);
this
.
iO
模块状态
ToolStripMenuItem
.
Text
=
"IO模块状态"
;
this
.
iO
模块状态
ToolStripMenuItem
.
Click
+=
new
System
.
EventHandler
(
this
.
iO
模块状态
ToolStripMenuItem_Click
);
//
// toolStripSeparator13
//
this
.
toolStripSeparator13
.
Name
=
"toolStripSeparator13"
;
this
.
toolStripSeparator13
.
Size
=
new
System
.
Drawing
.
Size
(
17
7
,
6
);
this
.
toolStripSeparator13
.
Size
=
new
System
.
Drawing
.
Size
(
17
3
,
6
);
//
// toolStripMenuItem2
//
this
.
toolStripMenuItem2
.
Name
=
"toolStripMenuItem2"
;
this
.
toolStripMenuItem2
.
Size
=
new
System
.
Drawing
.
Size
(
1
80
,
26
);
this
.
toolStripMenuItem2
.
Size
=
new
System
.
Drawing
.
Size
(
1
76
,
26
);
this
.
toolStripMenuItem2
.
Text
=
"AGV调试"
;
this
.
toolStripMenuItem2
.
Click
+=
new
System
.
EventHandler
(
this
.
toolStripMenuItem2_Click
);
//
// toolStripSeparator12
//
this
.
toolStripSeparator12
.
Name
=
"toolStripSeparator12"
;
this
.
toolStripSeparator12
.
Size
=
new
System
.
Drawing
.
Size
(
17
7
,
6
);
this
.
toolStripSeparator12
.
Size
=
new
System
.
Drawing
.
Size
(
17
3
,
6
);
//
// 清空托盘信息ToolStripMenuItem
//
this
.
清空托盘信息
ToolStripMenuItem
.
Name
=
"清空托盘信息ToolStripMenuItem"
;
this
.
清空托盘信息
ToolStripMenuItem
.
Size
=
new
System
.
Drawing
.
Size
(
1
80
,
26
);
this
.
清空托盘信息
ToolStripMenuItem
.
Size
=
new
System
.
Drawing
.
Size
(
1
76
,
26
);
this
.
清空托盘信息
ToolStripMenuItem
.
Text
=
"清空托盘信息"
;
this
.
清空托盘信息
ToolStripMenuItem
.
Click
+=
new
System
.
EventHandler
(
this
.
清空托盘信息
ToolStripMenuItem_Click
);
//
...
...
@@ -750,18 +764,6 @@
this
.
timer1
.
Interval
=
2000
;
this
.
timer1
.
Tick
+=
new
System
.
EventHandler
(
this
.
timer1_Tick
);
//
// checkBox1
//
this
.
checkBox1
.
AutoSize
=
true
;
this
.
checkBox1
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
10.5F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
checkBox1
.
Location
=
new
System
.
Drawing
.
Point
(
478
,
137
);
this
.
checkBox1
.
Name
=
"checkBox1"
;
this
.
checkBox1
.
Size
=
new
System
.
Drawing
.
Size
(
119
,
24
);
this
.
checkBox1
.
TabIndex
=
198
;
this
.
checkBox1
.
Text
=
"启用agvClient"
;
this
.
checkBox1
.
UseVisualStyleBackColor
=
true
;
this
.
checkBox1
.
CheckedChanged
+=
new
System
.
EventHandler
(
this
.
checkBox1_CheckedChanged
);
//
// FrmLineStore
//
this
.
AutoScaleMode
=
System
.
Windows
.
Forms
.
AutoScaleMode
.
None
;
...
...
source/AssemblyLineClient/Program.cs
查看文件 @
01c8f86
...
...
@@ -107,23 +107,23 @@ namespace OnlineStore.AssemblyLine
private
static
void
CurrentDomain_FirstChanceException
(
object
sender
,
System
.
Runtime
.
ExceptionServices
.
FirstChanceExceptionEventArgs
e
)
{
LogUnhandledException
(
"CurrentDomain_FirstChanceException"
,
e
);
//
LogUnhandledException("CurrentDomain_FirstChanceException", e);
}
static
void
CurrentDomain_UnhandledException
(
object
sender
,
UnhandledExceptionEventArgs
e
)
{
LogUnhandledException
(
"CurrentDomain_UnhandledException"
,
e
);
LogUnhandledException
(
"CurrentDomain_UnhandledException"
,
e
);
}
static
void
Application_ThreadException
(
object
sender
,
System
.
Threading
.
ThreadExceptionEventArgs
e
)
{
LogUnhandledException
(
"Application_ThreadException"
,
e
);
LogUnhandledException
(
"Application_ThreadException"
,
e
);
}
static
void
LogUnhandledException
(
string
type
,
Exception
exceptionobj
)
static
void
LogUnhandledException
(
string
type
,
object
exceptionobj
)
{
//这里可以进一步地写日志
LOGGER
.
Error
(
"【"
+
type
+
"】"
+
exceptionobj
.
ToString
());
LOGGER
.
Error
(
"【"
+
type
+
"】"
+
exceptionobj
.
ToString
());
MessageBox
.
Show
(
exceptionobj
.
ToString
(),
type
);
}
}
...
...
source/DeviceLibrary/DeviceLibrary.csproj
查看文件 @
01c8f86
...
...
@@ -96,7 +96,6 @@
<Compile Include="deviceLibrary\PanasonicServo\ACServerManager.cs" />
<Compile Include="deviceLibrary\PanasonicServo\ACServerManager_Partial.cs" />
<Compile Include="assemblyLine\EquipBase.cs" />
<Compile Include="deviceLibrary\RFID\RFID.cs" />
<Compile Include="deviceLibrary\RFID\RFIDAuto.cs" />
<Compile Include="deviceLibrary\RFID\RFIDReader.cs" />
<Compile Include="deviceLibrary\RFID\RFIDAutoReader.cs" />
...
...
source/DeviceLibrary/assemblyLine/LineBean.cs
查看文件 @
01c8f86
...
...
@@ -20,7 +20,7 @@ namespace OnlineStore.DeviceLibrary
public
partial
class
LineBean
:
KTK_Store
{
public
bool
IsDebug
=
false
;
public
bool
UseAgvClient
=
fals
e
;
public
bool
UseAgvClient
=
tru
e
;
/// <summary>
/// 灯闪烁定时器
/// </summary>
...
...
@@ -166,7 +166,7 @@ namespace OnlineStore.DeviceLibrary
LogUtil
.
error
(
Name
+
"加载调试设备出错:"
,
ex
);
}
}
RFIDManager
.
Init
();
Task
.
Factory
.
StartNew
(
delegate
{
LogUtil
.
info
(
Name
+
"开始连接IO模块 "
);
...
...
source/DeviceLibrary/assemblymanager/RFIDManagercs.cs
查看文件 @
01c8f86
...
...
@@ -16,9 +16,10 @@ namespace OnlineStore.DeviceLibrary
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
);
public
static
void
Open
()
public
static
void
Init
()
{
TrayIpList
=
new
List
<
string
>();
ShelfIpList
=
new
List
<
string
>();
Dictionary
<
string
,
string
>
rfidMap
=
DeviceConfig
.
ProRFIpMap
;
foreach
(
string
key
in
rfidMap
.
Keys
)
{
...
...
@@ -31,7 +32,13 @@ namespace OnlineStore.DeviceLibrary
TrayIpList
.
Add
(
rfidMap
[
key
]);
}
}
RFIDAutoReader
.
Open
(
null
,
new
List
<
string
>(
rfidMap
.
Values
).
ToArray
());
}
public
static
void
Open
()
{
// RFIDAutoReader.Open(null, new List<string>(rfidMap.Values).ToArray());
RFIDAutoReader
.
Open
(
null
,
TrayIpList
.
ToArray
());
RFIDReader
.
Open
(
ShelfIpList
.
ToArray
());
}
/// <summary>
...
...
@@ -78,16 +85,26 @@ namespace OnlineStore.DeviceLibrary
public
static
RFIDData
GetShelfId
(
int
subType
)
{
string
ip
=
GetRFIP
(
subType
,
1
);
RFIDData
data
=
ReadRFID
(
ip
,
true
);
return
data
;
return
ReadRFID
(
ip
,
true
);
}
public
static
RFIDData
ReadRFID
(
string
ip
,
bool
isClear
=
false
)
{
try
{
if
(
String
.
IsNullOrEmpty
(
ip
).
Equals
(
false
)
)
if
(
String
.
IsNullOrEmpty
(
ip
).
Equals
(
false
)
&&
ShelfIpList
.
Contains
(
ip
))
{
byte
[]
bdata
=
RFIDReader
.
Read
(
ip
,
true
);
if
(
bdata
==
null
)
{
LogUtil
.
error
(
"RFID [ "
+
ip
+
" ] 读到数据=null"
);
}
RFIDData
data
=
new
RFIDData
(
bdata
);
return
data
;
}
else
//if (String.IsNullOrEmpty(ip).Equals(false) && LineManager.Line.rfidList.Contains(ip))
{
byte
[]
bdata
=
null
;
...
...
@@ -112,7 +129,7 @@ namespace OnlineStore.DeviceLibrary
{
//LogUtil.error("ReadRFID["+ip+"]出错:",ex);
}
return
new
RFIDData
(
);
return
new
RFIDData
();
}
public
static
string
GetRFIP
(
int
subType
,
int
rtType
=
0
)
...
...
@@ -138,7 +155,15 @@ namespace OnlineStore.DeviceLibrary
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"关闭RFID出错:"
,
ex
);
LogUtil
.
error
(
"RFIDAutoReader.CloseAll()出错:"
,
ex
);
}
try
{
RFIDReader
.
CloseAll
();
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"RFIDReader.CloseAll()出错:"
,
ex
);
}
}
}
...
...
source/DeviceLibrary/deviceLibrary/RFID/RFID.cs
查看文件 @
01c8f86
...
...
@@ -8,164 +8,4 @@ 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
];
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
);
return
ErrCode
;
}
/// <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
;
}
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
);
}
}
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/RFIDReader.cs
查看文件 @
01c8f86
...
...
@@ -8,6 +8,179 @@ 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
;
}
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
);
}
}
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"
);
...
...
@@ -15,9 +188,9 @@ namespace Asa.RFID
private
static
Dictionary
<
string
,
RFID
>
rfidMap
=
new
Dictionary
<
string
,
RFID
>();
public
static
void
Open
(
params
string
[]
ipArr
)
public
static
void
Open
(
params
string
[]
ipArr
)
{
foreach
(
var
ip
in
ipArr
)
foreach
(
var
ip
in
ipArr
)
{
if
(
rfidMap
.
ContainsKey
(
ip
))
{
...
...
@@ -40,7 +213,7 @@ namespace Asa.RFID
return
false
;
}
public
static
byte
[]
Read
(
string
ip
,
bool
isNeedFind
)
public
static
byte
[]
Read
(
string
ip
,
bool
isNeedFind
)
{
if
(
rfidMap
.
ContainsKey
(
ip
))
{
...
...
@@ -51,7 +224,7 @@ namespace Asa.RFID
public
static
void
CloseAll
()
{
foreach
(
var
rfid
in
rfidMap
.
Values
)
foreach
(
var
rfid
in
rfidMap
.
Values
)
{
rfid
.
Close
();
}
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论