Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
张东亮
/
NS100
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit ecd4c0a8
由
张东亮
编写于
2023-09-27 10:11:52 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
添加扫码相机
1 个父辈
a372778e
显示空白字符变更
内嵌
并排
正在显示
14 个修改的文件
包含
254 行增加
和
26 行删除
BLL/BLL.csproj
BLL/BLLCommon.cs
BLL/Camera.cs
BLL/Config.cs
BLL/Extension/Item_General.cs
SharedDll/IDHIKCamera.dll
SharedDll/MvCodeReaderSDK.Net.dll
SmartScan/Form/FrmLoading.cs
SmartScan/Form/FrmMain.cs
SmartScan/Program.cs
SmartScan/ScanWork.cs
SmartScan/SetControl/UsrCamera.cs
SmartScan/SetControl/UsrMaterialTemplate.cs
SmartScan/WebCallWork.cs
BLL/BLL.csproj
查看文件 @
ecd4c0a
...
...
@@ -56,6 +56,9 @@
<Reference Include="ExcelNumberFormat, Version=1.1.0.0, Culture=neutral, PublicKeyToken=23c6f5d73be07eca, processorArchitecture=MSIL">
<HintPath>..\packages\ExcelNumberFormat.1.1.0\lib\net20\ExcelNumberFormat.dll</HintPath>
</Reference>
<Reference Include="IDHIKCamera">
<HintPath>..\SharedDll\IDHIKCamera.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.12\lib\net45\log4net.dll</HintPath>
</Reference>
...
...
@@ -99,6 +102,7 @@
<ItemGroup>
<Compile Include="AsciiToCharReplacer.cs" />
<Compile Include="BLLCommon.cs" />
<Compile Include="Camera.cs" />
<Compile Include="Config.cs" />
<Compile Include="ConvertBarcode.cs" />
<Compile Include="Extension.cs" />
...
...
BLL/BLLCommon.cs
查看文件 @
ecd4c0a
...
...
@@ -12,7 +12,6 @@ namespace BLL
public
static
BLL
.
PrintLabelEdit
labelEdit
;
public
static
BLL
.
MaterialEdit
mateEdit
;
public
static
Model
.
OCR
ocr
;
public
static
Asa
.
Camera
.
VisionLib
cameraVision
;
public
static
BLL
.
IO_Interface
ioModule
;
public
static
LightSource
lightSource
;
public
static
ServerCommunication
SCMM
;
...
...
BLL/Camera.cs
0 → 100644
查看文件 @
ecd4c0a
using
CameraVisionLib.Model
;
using
IDHIKCamera
;
using
Model
;
using
System
;
using
System.Collections.Generic
;
using
System.Drawing
;
using
System.Linq
;
using
System.Runtime.ExceptionServices
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.Windows.Forms
;
using
System.Windows.Forms.VisualStyles
;
namespace
BLL
{
public
class
Camera
{
public
static
bool
useIDCamera
=
Config
.
Func_UseIDCamera
;
static
Asa
.
Camera
.
VisionLib
cameraVision
;
static
string
cameraName
=
null
;
public
static
void
LoadCamera
()
{
if
(
useIDCamera
)
{
try
{
LibLogUtil
.
LogEvent
+=
LibLogUtil_LogEvent
;
IDHIK
.
Instance
.
Load
();
List
<
string
>
names
=
IDHIK
.
Instance
.
cameraName
;
IDHIK
.
Instance
.
DrawLine
=
false
;
if
(
names
!=
null
)
{
// hikNameList.AddRange(names);
//foreach (string name in names)
//{
// LogNet.log.Info("加载到IDHIK相机:" + name);
//}
cameraName
=
names
.
Find
(
s
=>
s
.
Contains
(
"ID"
));
}
//IDHIK.Instance.OpenAll();
}
catch
(
Exception
ex
)
{
LogNet
.
log
.
Error
(
"解析IDHIK出错:"
+
ex
.
StackTrace
);
}
}
else
{
cameraVision
=
new
Asa
.
Camera
.
VisionLib
(
FilePath
.
CONFIG_CAMERA
,
BLLCommon
.
config
.
EnabledCamera
);
LogNet
.
log
.
Info
(
"加载相机,数量:"
+
cameraVision
.
Count
);
}
}
private
static
void
LibLogUtil_LogEvent
(
LibLogEventArg
libLogEventArg
)
{
switch
(
libLogEventArg
.
Level
)
{
case
LibLogLevel
.
Debug
:
LogNet
.
log
.
Debug
(
libLogEventArg
.
Msg
);
break
;
case
LibLogLevel
.
Info
:
LogNet
.
log
.
Info
(
libLogEventArg
.
Msg
);
break
;
case
LibLogLevel
.
Warning
:
LogNet
.
log
.
Warn
(
libLogEventArg
.
Msg
);
break
;
case
LibLogLevel
.
Error
:
LogNet
.
log
.
Error
(
libLogEventArg
.
Msg
,
libLogEventArg
.
Exception
);
break
;
}
}
public
static
bool
IsConnected
()
{
if
(
useIDCamera
)
{
bool
rtn
=
!
string
.
IsNullOrEmpty
(
cameraName
);
if
(
rtn
)
{
LogNet
.
log
.
Info
(
"扫码相机已连接"
);
}
else
LogNet
.
log
.
Info
(
"扫码相机未连接"
);
return
rtn
;
}
else
{
LogNet
.
log
.
Info
(
"相机数量为"
+
cameraVision
.
Count
);
return
cameraVision
.
Count
>
0
;
}
}
public
static
Bitmap
[]
Capture
()
{
Bitmap
[]
result
=
new
Bitmap
[
1
];
if
(
useIDCamera
)
{
grabOne
(
out
Bitmap
bitmap
);
result
[
0
]
=
bitmap
;
}
else
{
cameraVision
.
Open
();
result
=
cameraVision
.
GetImage
();
cameraVision
.
Close
();
}
return
result
;
}
public
static
Bitmap
[]
CaptureAndGetCode
(
out
List
<
BarcodeInfo
>
barcodeInfos
)
{
Bitmap
[]
result
=
new
Bitmap
[
1
];
barcodeInfos
=
new
List
<
BarcodeInfo
>();
if
(
useIDCamera
)
{
barcodeInfos
=
grabOne
(
out
Bitmap
bitmap
);
result
[
0
]
=
bitmap
;
}
else
{
cameraVision
.
Open
();
result
=
cameraVision
.
GetImage
();
cameraVision
.
Close
();
}
return
result
;
}
public
static
List
<
BarcodeInfo
>
GetBarCode
(
Bitmap
bitmap
)
{
return
cameraVision
.
GetBarCode
(
bitmap
);
}
public
static
void
Dispose
()
{
if
(
useIDCamera
)
{
}
else
{
cameraVision
?.
Dispose
();
}
}
public
static
void
Open
()
{
if
(
useIDCamera
)
{
IDHIK
.
Instance
.
OpenAll
();
}
else
{
cameraVision
?.
Open
();
}
}
public
static
void
Close
()
{
if
(
useIDCamera
)
{
IDHIK
.
Instance
.
CloseAll
();
}
else
{
cameraVision
?.
Close
();
}
}
public
static
string
[]
GetBarCodeText
(
List
<
BarcodeInfo
>
barcodeInfos
)
{
return
cameraVision
.
GetBarCodeText
(
barcodeInfos
);
}
[
HandleProcessCorruptedStateExceptions
]
static
List
<
BarcodeInfo
>
grabOne
(
out
Bitmap
bitmap
)
{
bitmap
=
null
;
List
<
BarcodeInfo
>
barcodeInfos
=
new
List
<
BarcodeInfo
>();
if
(
string
.
IsNullOrEmpty
(
cameraName
))
{
return
barcodeInfos
;
}
try
{
bitmap
=
(
Bitmap
)
IDHIK
.
Instance
.
GrabOne
(
cameraName
,
out
List
<
CodeInfo
>
cc
);
if
(
cc
!=
null
)
{
cc
.
ForEach
(
c
=>
{
barcodeInfos
.
Add
(
new
BarcodeInfo
()
{
Center
=
new
PointF
(
c
.
X
,
c
.
Y
),
Angle
=
(
float
)
c
.
Orientation
,
CodeType
=
c
.
CodeType
,
Text
=
c
.
CodeStr
});
});
}
}
catch
(
Exception
e
)
{
LogNet
.
log
.
Error
(
$
"{cameraName}取图失败:"
,
e
);
}
return
barcodeInfos
;
}
}
}
BLL/Config.cs
查看文件 @
ecd4c0a
...
...
@@ -335,6 +335,8 @@ namespace BLL
/// </summary>
[
MyConfigComment
(
"唯一码后缀编号重置策略"
)]
public
static
MyConfig
<
int
>
REEL_ID_AutoResetStrategy
;
[
MyConfigComment
(
"使用扫码相机"
)]
public
static
MyConfig
<
bool
>
Func_UseIDCamera
=
false
;
public
void
Save
()
{
config
.
Save
();
...
...
BLL/Extension/Item_General.cs
查看文件 @
ecd4c0a
...
...
@@ -112,6 +112,8 @@ namespace BLL
if
(
extensions
!=
null
&&
!
extensions
[
0
].
Control
.
InvokeRequired
)
{
//使用key填充时,请处理字段开头的<OCR>字段
if
(
key
.
ContainsKey
(
Config
.
DataSource_DataKey
))
{
string
CleanData
=
key
[
Config
.
DataSource_DataKey
].
Replace
(
"<OCR>"
,
""
);
if
(
key
.
ContainsKey
(
Config
.
DataSource_DataKey
)
&&
ExtraFileData
.
AllData
.
ContainsKey
(
CleanData
))
{
...
...
@@ -121,6 +123,8 @@ namespace BLL
key
[
d
.
Key
]
=
d
.
Value
;
}
}
}
//第二次刷新界面
for
(
int
i
=
0
;
i
<
extensions
.
Count
;
i
++)
{
...
...
SharedDll/IDHIKCamera.dll
0 → 100644
查看文件 @
ecd4c0a
此文件类型无法预览
SharedDll/MvCodeReaderSDK.Net.dll
0 → 100644
查看文件 @
ecd4c0a
此文件类型无法预览
SmartScan/Form/FrmLoading.cs
查看文件 @
ecd4c0a
...
...
@@ -36,8 +36,7 @@ namespace SmartScan
LogNet
.
log
.
Debug
(
"加载语言文件夹:"
+
FilePath
.
LANGUAGE_DIR
);
Asa
.
FaceControl
.
Language
.
LoadLanguage
(
BLLCommon
.
config
.
Language
);
BLLCommon
.
cameraVision
=
new
Asa
.
Camera
.
VisionLib
(
FilePath
.
CONFIG_CAMERA
,
BLLCommon
.
config
.
EnabledCamera
);
LogNet
.
log
.
Info
(
"加载相机,数量:"
+
BLLCommon
.
cameraVision
.
Count
);
Camera
.
LoadCamera
();
if
(
BLLCommon
.
config
.
EnabledIO
)
{
...
...
SmartScan/Form/FrmMain.cs
查看文件 @
ecd4c0a
...
...
@@ -33,15 +33,13 @@ namespace SmartScan
{
if
(
BLLCommon
.
config
.
EnabledCamera
)
{
if
(
BLLCommon
.
cameraVision
.
Count
<=
0
)
if
(
!
Camera
.
IsConnected
()
)
{
LogNet
.
log
.
Info
(
"相机数量为0"
);
LblCameraExist
.
BackColor
=
Color
.
Red
;
return
false
;
}
else
{
LogNet
.
log
.
Info
(
"相机数量为"
+
BLLCommon
.
cameraVision
.
Count
);
LblCameraExist
.
ForeColor
=
Color
.
Lime
;
return
true
;
}
...
...
SmartScan/Program.cs
查看文件 @
ecd4c0a
...
...
@@ -162,7 +162,7 @@ namespace SmartScan
LogNet
.
log
.
Info
(
"=====准备退出...====="
);
BLLCommon
.
lightSource
.
Close
();
BLLCommon
.
ioModule
?.
Close
();
BLLCommon
.
cameraVision
?
.
Dispose
();
Camera
.
Dispose
();
WebService
.
Close
();
LogNet
.
log
.
Info
(
"=====程序结束=====\r\n"
);
}
...
...
SmartScan/ScanWork.cs
查看文件 @
ecd4c0a
...
...
@@ -41,7 +41,7 @@ namespace SmartScan
LogNet
.
log
.
Info
(
"Work Start"
);
if
(
BLLCommon
.
config
.
EnabledCamera
)
BLLCommon
.
cameraVision
?
.
Open
();
Camera
.
Open
();
if
(
BLLCommon
.
config
.
TriggerOpenLight
)
//触发时才打开光源
BLLCommon
.
lightSource
?.
TurnOff
();
...
...
@@ -59,7 +59,7 @@ namespace SmartScan
LogNet
.
log
.
Info
(
"Work Stop"
);
if
(
BLLCommon
.
config
.
EnabledCamera
)
BLLCommon
.
cameraVision
?
.
Close
();
Camera
.
Close
();
BLLCommon
.
lightSource
?.
TurnOff
();
}
...
...
@@ -226,7 +226,7 @@ namespace SmartScan
BLLCommon
.
lightSource
.
TurnOn
();
System
.
Threading
.
Thread
.
Sleep
(
2000
);
//光源打开有一个由暗变亮的过程
}
workCodeInfo
=
BLLCommon
.
cameraVision
.
GetBarCode
(
out
List
<
Bitmap
>
image
);
List
<
Bitmap
>
image
=
new
List
<
Bitmap
>(
Camera
.
CaptureAndGetCode
(
out
workCodeInfo
)
);
if
(
image
.
Count
>
0
&&
!
BLL
.
Config
.
Backgrounder
)
picShow
.
Image
=
image
[
0
];
if
(
image
.
Count
>
0
)
BLLCommon
.
mateEdit
.
CurrntBitmap
=
image
[
0
];
...
...
@@ -248,7 +248,7 @@ namespace SmartScan
return
false
;
Bitmap
bmp
=
null
;
bmp
=
ObjConversion
.
ReadImageFile
(
filename
);
workCodeInfo
=
BLLCommon
.
cameraVision
.
GetBarCode
(
bmp
);
workCodeInfo
=
Camera
.
GetBarCode
(
bmp
);
Common
.
frmMain
.
Invoke
(
delegate
()
{
if
(!
BLL
.
Config
.
Backgrounder
)
...
...
@@ -286,7 +286,7 @@ namespace SmartScan
{
LogNet
.
log
.
Info
(
"Work MatchingTemplate"
);
if
(
workCodeInfo
.
Count
==
0
)
return
false
;
originalCodeText
=
BLLCommon
.
cameraVision
.
GetBarCodeText
(
workCodeInfo
);
originalCodeText
=
Camera
.
GetBarCodeText
(
workCodeInfo
);
bool
rtn
=
BLLCommon
.
mateEdit
.
MatchingTemplate
(
workCodeInfo
,
BLLCommon
.
config
.
DefaultMaterialName
,
false
,
out
string
mateName
,
out
workCodeKeyword
,
out
originalCodeIsUsed
);
BLL
.
MatchAnalysis
.
ShowResult
();
...
...
SmartScan/SetControl/UsrCamera.cs
查看文件 @
ecd4c0a
using
System
;
using
System.Collections.Generic
;
using
System.Drawing
;
using
System.Linq
;
using
System.Windows.Forms
;
using
BLL
;
using
CameraVisionLib.Model
;
using
DocumentFormat.OpenXml.Spreadsheet
;
using
Model
;
...
...
@@ -16,7 +18,7 @@ namespace SmartScan
{
InitializeComponent
();
Asa
.
FaceControl
.
Language
.
SetLanguage
(
this
);
BtnCameraImage
.
Enabled
=
BLLCommon
.
cameraVision
==
null
?
false
:
BLLCommon
.
cameraVision
.
Count
>
0
;
BtnCameraImage
.
Enabled
=
Camera
.
IsConnected
()
;
}
public
Asa
.
FaceControl
.
FacePanel
GetPanel
()
...
...
@@ -37,12 +39,10 @@ namespace SmartScan
{
BLLCommon
.
lightSource
.
TurnOff
();
}
List
<
BarcodeInfo
>
barcodeInfos
;
private
void
BtnCameraImage_Click
(
object
sender
,
EventArgs
e
)
{
BLLCommon
.
cameraVision
.
Open
();
Bitmap
[]
result
=
BLLCommon
.
cameraVision
.
GetImage
();
BLLCommon
.
cameraVision
.
Close
();
Bitmap
[]
result
=
Camera
.
CaptureAndGetCode
(
out
barcodeInfos
);
if
(
result
.
Length
==
0
)
return
;
bmp
=
result
[
0
];
LstCode
.
Items
.
Clear
();
...
...
@@ -64,7 +64,13 @@ namespace SmartScan
private
void
BtnScanCode_Click
(
object
sender
,
EventArgs
e
)
{
if
(
bmp
==
null
)
return
;
List
<
CameraVisionLib
.
Model
.
BarcodeInfo
>
info
=
BLLCommon
.
cameraVision
.
GetBarCode
(
bmp
);
List
<
CameraVisionLib
.
Model
.
BarcodeInfo
>
info
=
null
;
if
(
Camera
.
useIDCamera
)
{
info
=
barcodeInfos
.
ToList
();
}
else
info
=
Camera
.
GetBarCode
(
bmp
);
LstCode
.
Items
.
Clear
();
PicShow
.
CodeCenterClear
();
string
[]
arr
=
new
string
[
info
.
Count
];
...
...
SmartScan/SetControl/UsrMaterialTemplate.cs
查看文件 @
ecd4c0a
...
...
@@ -31,7 +31,7 @@ namespace SmartScan
LstMate
.
Items
.
AddRange
(
BLLCommon
.
mateEdit
.
Name
);
mateCopy
=
BLLCommon
.
mateEdit
.
ToCopy
();
Language
.
SetLanguage
(
this
);
BtnCameraImage
.
Enabled
=
BLLCommon
.
cameraVision
.
Count
>
0
;
BtnCameraImage
.
Enabled
=
Camera
.
IsConnected
()
;
//LstMate.SelectedFirst();
}
...
...
@@ -215,9 +215,8 @@ namespace SmartScan
private
void
BtnCameraImage_Click
(
object
sender
,
EventArgs
e
)
{
BLLCommon
.
cameraVision
.
Open
();
Bitmap
[]
result
=
BLLCommon
.
cameraVision
.
GetImage
();
BLLCommon
.
cameraVision
.
Close
();
if
(
mateIndex
==
-
1
)
return
;
Bitmap
[]
result
=
Camera
.
Capture
();
if
(
result
.
Length
==
0
)
return
;
bmp
=
result
[
0
];
...
...
@@ -248,6 +247,7 @@ namespace SmartScan
private
void
BtnScanCode_Click
(
object
sender
,
EventArgs
e
)
{
if
(
mateIndex
==
-
1
)
return
;
if
(
bmp
==
null
)
return
;
string
text
=
Language
.
Dialog
(
LanguageDialogKey
.
REMIND_CLEARTEMPLATE
,
"Recognizing code will reset the template.Are you sure to perform the action?"
);
DialogResult
dialogResult
=
new
FaceMessageBox
(
mateCopy
[
mateIndex
].
Name
,
text
,
MessageBoxButtons
.
YesNo
).
ShowDialog
();
...
...
@@ -255,7 +255,21 @@ namespace SmartScan
{
return
;
}
List
<
CameraVisionLib
.
Model
.
BarcodeInfo
>
info
=
BLLCommon
.
cameraVision
.
GetBarCode
(
bmp
);
List
<
BarcodeInfo
>
info
=
null
;
if
(
Camera
.
useIDCamera
)
{
Bitmap
[]
result
=
Camera
.
CaptureAndGetCode
(
out
info
);
if
(
result
.
Length
==
0
)
return
;
bmp
=
result
[
0
];
mateCopy
[
mateIndex
].
ImagePath
=
""
;
mateCopy
[
mateIndex
].
Image
=
bmp
;
ImgShow
.
Image
=
bmp
;
}
else
{
info
=
Camera
.
GetBarCode
(
bmp
);
}
LstCode
.
Items
.
Clear
();
ImgShow
.
CodeCenterClear
();
mateCopy
[
mateIndex
].
Match
.
Clear
();
...
...
@@ -309,10 +323,10 @@ namespace SmartScan
AsciiToCharReplacer
asciiControl
=
new
AsciiToCharReplacer
();
string
[]
strings
=
null
;
string
codestring
=
asciiControl
.
StringToAscii
(
code
.
Text
,
out
strings
);
string
codestring
=
asciiControl
.
StringToAscii
(
code
.
Text
,
out
strings
);
List
<
MaterialCodeMatch
>
match
=
mateCopy
[
mateIndex
].
Match
.
FindAll
(
s
=>
s
.
CodeID
==
code
.
ID
);
//如果使用新方法识别ocr,去除空格
if
(
code
.
CodeType
==
"OCR"
&&
codestring
==
"http://localhost:8090/paddle/SelectOcrMethod"
)
if
(
code
.
CodeType
==
"OCR"
&&
codestring
==
"http://localhost:8090/paddle/SelectOcrMethod"
)
{
codestring
=
code
.
Text
.
Replace
(
" "
,
""
);
}
...
...
SmartScan/WebCallWork.cs
查看文件 @
ecd4c0a
...
...
@@ -61,7 +61,7 @@ namespace SmartScan
List
<
CameraVisionLib
.
Model
.
BarcodeInfo
>
workCodeInfo
=
new
();
Dictionary
<
string
,
string
>
workCodeKeyword
;
// = new(StringComparer.OrdinalIgnoreCase);
bool
[]
originalCodeIsUsed
=
null
;
workCodeInfo
=
BLLCommon
.
cameraVision
.
GetBarCode
(
bitmap
);
workCodeInfo
=
Camera
.
GetBarCode
(
bitmap
);
if
(
workCodeInfo
.
Count
==
0
)
return
new
WebResultCode
()
{
ErrorCode
=
-
1
,
Msg
=
"扫码失败"
};
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论