Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
G
GC_Branch
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
周磊
GC_Branch
Commits
814b29ff
Commit
814b29ff
authored
Jun 04, 2018
by
wangjunqiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化文件提交接口和自动批处理接口
parent
b4191e67
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
229 additions
and
52 deletions
+229
-52
FileServerClient.cs
GcDevicePc/FileServerClient.cs
+195
-29
MDIBase.cs
GcDevicePc/MDIBase.cs
+34
-23
No files found.
GcDevicePc/FileServerClient.cs
View file @
814b29ff
...
...
@@ -3,6 +3,8 @@ using System.Collections.Generic;
using
System.Linq
;
using
System.Text
;
using
System.Runtime.InteropServices
;
using
System.Threading
;
using
GcDevicePc.Common
;
namespace
GcDevicePc
{
...
...
@@ -32,69 +34,233 @@ namespace GcDevicePc
private
uint
hFileServerHandle
;
private
byte
[]
bfilename
;
private
byte
[]
bfilepath
;
private
byte
[]
bRemoteFilePath
;
private
byte
[]
fIP
;
private
ushort
wport
;
public
void
WtClientClose
()
#
region
文件传输接口
public
int
WtClientInit
(
String
RemoteIP
,
ushort
port
)
{
int
bret
=
1
;
try
{
fnWtClientClose
(
this
.
hFileServerHandle
);
fIP
=
Encoding
.
Unicode
.
GetBytes
(
RemoteIP
);
wport
=
port
;
CallWithTimeout
(
ClientInit
,
5000
);
}
catch
catch
(
TimeoutException
ex
)
{
Console
.
WriteLine
(
"fnWtClientClose Error"
);
bret
=
0
;
Log
.
Error
(
ex
.
Message
);
return
bret
;
}
return
bret
;
}
public
void
WtClientInit
(
String
RemoteIP
,
ushort
wport
)
public
int
WtClientClose
(
)
{
int
bret
=
1
;
try
{
byte
[]
fIP
=
Encoding
.
Unicode
.
GetBytes
(
RemoteIP
);
this
.
hFileServerHandle
=
fnWtClientInit
(
fIP
,
wport
);
CallWithTimeout
(
ClientClose
,
5000
);
}
catch
catch
(
TimeoutException
ex
)
{
Console
.
WriteLine
(
"WtClientInit Error"
);
bret
=
0
;
Log
.
Error
(
ex
.
Message
);
Thread
.
Sleep
(
2000
);
return
bret
;
}
return
bret
;
}
public
int
WtClientCopytoServer
(
String
filename
,
String
filepath
,
String
RemoteFilePath
)
{
int
bret
;
byte
[]
bfilename
=
Encoding
.
Unicode
.
GetBytes
(
filename
);
byte
[]
bfilepath
=
Encoding
.
Unicode
.
GetBytes
(
filepath
);
byte
[]
bRemoteFilePath
=
Encoding
.
Unicode
.
GetBytes
(
RemoteFilePath
);
int
bret
=
1
;
try
{
bfilename
=
Encoding
.
Unicode
.
GetBytes
(
filename
);
bfilepath
=
Encoding
.
Unicode
.
GetBytes
(
filepath
);
bRemoteFilePath
=
Encoding
.
Unicode
.
GetBytes
(
RemoteFilePath
);
CallWithTimeout
(
ClientCopytoServer
,
5000
);
}
catch
(
TimeoutException
ex
)
{
bret
=
0
;
Log
.
Error
(
ex
.
Message
);
return
bret
;
}
return
bret
;
}
public
int
WtClientCopytoServerNoDelay
(
String
filename
,
String
filepath
,
String
RemoteFilePath
)
{
int
bret
=
1
;
try
{
bfilename
=
Encoding
.
Unicode
.
GetBytes
(
filename
);
bfilepath
=
Encoding
.
Unicode
.
GetBytes
(
filepath
);
bRemoteFilePath
=
Encoding
.
Unicode
.
GetBytes
(
RemoteFilePath
);
if
(
this
.
hFileServerHandle
!=
0
)
bret
=
fnWtClientCopytoServer
(
this
.
hFileServerHandle
,
bfilename
,
bfilepath
,
bRemoteFilePath
);
}
catch
(
TimeoutException
ex
)
{
bret
=
0
;
Log
.
Error
(
ex
.
Message
);
return
bret
;
}
return
bret
;
}
public
int
WtClientCopyfromServer
(
String
filename
,
String
filepath
,
String
RemoteFilePath
)
{
int
bret
;
byte
[]
bfilename
=
Encoding
.
Unicode
.
GetBytes
(
filename
);
byte
[]
bfilepath
=
Encoding
.
Unicode
.
GetBytes
(
filepath
);
byte
[]
bRemoteFilePath
=
Encoding
.
Unicode
.
GetBytes
(
RemoteFilePath
);
bret
=
fnWtClientCopyfromServer
(
this
.
hFileServerHandle
,
bfilename
,
bfilepath
,
bRemoteFilePath
);
int
bret
=
1
;
try
{
bfilename
=
Encoding
.
Unicode
.
GetBytes
(
filename
);
bfilepath
=
Encoding
.
Unicode
.
GetBytes
(
filepath
);
bRemoteFilePath
=
Encoding
.
Unicode
.
GetBytes
(
RemoteFilePath
);
CallWithTimeout
(
ClientCopyfromServer
,
5000
);
}
catch
(
TimeoutException
ex
)
{
bret
=
0
;
Log
.
Error
(
ex
.
Message
);
return
bret
;
}
return
bret
;
}
public
int
WtHMICloseRro
(
String
filename
)
{
int
bret
;
byte
[]
bfilename
=
Encoding
.
Unicode
.
GetBytes
(
filename
);
int
bret
=
0
;
try
{
bfilename
=
Encoding
.
Unicode
.
GetBytes
(
filename
);
if
(
this
.
hFileServerHandle
!=
0
)
bret
=
fnWtCloseCEPro
(
this
.
hFileServerHandle
,
bfilename
);
}
catch
(
Exception
ex
)
{
Log
.
Error
(
ex
.
Message
);
}
return
bret
;
}
public
int
WtHMIRunPro
(
String
filename
,
String
RemoteFilePath
)
{
int
bret
;
byte
[]
bfilename
=
Encoding
.
Unicode
.
GetBytes
(
filename
);
byte
[]
bRemoteFilePath
=
Encoding
.
Unicode
.
GetBytes
(
RemoteFilePath
);
int
bret
=
0
;
try
{
bfilename
=
Encoding
.
Unicode
.
GetBytes
(
filename
);
bRemoteFilePath
=
Encoding
.
Unicode
.
GetBytes
(
RemoteFilePath
);
if
(
this
.
hFileServerHandle
!=
0
)
bret
=
fnWtRunPro
(
this
.
hFileServerHandle
,
bfilename
,
bRemoteFilePath
);
}
catch
(
Exception
ex
)
{
Log
.
Error
(
ex
.
Message
);
}
return
bret
;
}
#
endregion
#
region
内部操作接口
void
ClientInit
()
{
int
bret
=
0
;
try
{
this
.
hFileServerHandle
=
fnWtClientInit
(
fIP
,
wport
);
}
catch
(
Exception
ex
)
{
Log
.
Error
(
ex
.
Message
);
Thread
.
Sleep
(
3000
);
}
}
void
ClientClose
()
{
int
bret
=
0
;
try
{
fnWtClientClose
(
this
.
hFileServerHandle
);
}
catch
(
Exception
ex
)
{
Log
.
Error
(
ex
.
Message
);
Thread
.
Sleep
(
3000
);
}
}
void
ClientCopytoServer
()
{
int
bret
=
0
;
try
{
if
(
this
.
hFileServerHandle
!=
0
)
bret
=
fnWtClientCopytoServer
(
this
.
hFileServerHandle
,
bfilename
,
bfilepath
,
bRemoteFilePath
);
}
catch
(
Exception
ex
)
{
Thread
.
Sleep
(
3000
);
Log
.
Error
(
ex
.
Message
);
}
}
void
ClientCopyfromServer
()
{
int
bret
=
0
;
try
{
if
(
this
.
hFileServerHandle
!=
0
)
bret
=
fnWtClientCopyfromServer
(
this
.
hFileServerHandle
,
bfilename
,
bfilepath
,
bRemoteFilePath
);
}
catch
(
Exception
ex
)
{
Thread
.
Sleep
(
3000
);
Log
.
Error
(
ex
.
Message
);
}
}
/// <summary>
/// 超时退出函数
/// </summary>
/// <param name="action">执行方法</param>
/// <param name="timeoutMilliseconds">毫秒</param>
void
CallWithTimeout
(
Action
action
,
int
timeoutMilliseconds
)
{
Thread
threadToKill
=
null
;
Action
wrappedAction
=
()
=>
{
threadToKill
=
Thread
.
CurrentThread
;
action
();
};
IAsyncResult
result
=
wrappedAction
.
BeginInvoke
(
null
,
null
);
if
(
result
.
AsyncWaitHandle
.
WaitOne
(
timeoutMilliseconds
))
{
wrappedAction
.
EndInvoke
(
result
);
}
else
{
threadToKill
.
Abort
();
throw
new
TimeoutException
();
}
}
#
endregion
}
}
GcDevicePc/MDIBase.cs
View file @
814b29ff
...
...
@@ -1171,60 +1171,71 @@ namespace GcDevicePc
hmiopt
.
FireUPWork
(
flag
,
time1
,
time2
);
}
/// <summary>
/// 调试运行表接口
/// </summary>
/// <param name="folder">批处理目录</param>
/// <param name="runtablename">批处理文件名(带.ini)</param>
private
void
RunTableOpt
(
String
folder
,
String
runtablename
)
/// <returns>0-失败 1-成功</returns>
private
int
RunTableOpt
(
String
folder
,
String
runtablename
)
{
//bool ret = false
;
RunTableHelper
runtable
=
new
RunTableHelper
(
folder
,
runtablename
)
;
int
initret
=
0
;
int
ret
=
0
;
if
(!
String
.
IsNullOrEmpty
(
globaldata
.
connection_ip
))
{
FileServerClient
rtclient
=
new
FileServerClient
();
rtclient
.
WtClientInit
(
globaldata
.
connection_ip
,
globaldata
.
fileserverport
);
initret
=
rtclient
.
WtClientInit
(
globaldata
.
connection_ip
,
globaldata
.
fileserverport
);
if
(
initret
==
1
)
{
if
(
File
.
Exists
(
Path
.
Combine
(
folder
,
runtablename
)))
{
rtclient
.
WtClientCopytoServer
(
"RunMethod.ini"
,
Path
.
Combine
(
folder
,
runtablename
),
globaldata
.
remoteFolder
+
"运行表\\"
);
ret
=
rtclient
.
WtClientCopytoServer
(
"RunMethod.ini"
,
Path
.
Combine
(
folder
,
runtablename
),
globaldata
.
remoteFolder
+
"运行表\\"
);
SendPCCMD
(
false
);
}
rtclient
.
WtClientClose
();
globaldata
.
m_pcbuffer
.
gcpcinfo
.
pcfileinfo
.
cur_RunTab
=
Path
.
Combine
(
folder
,
runtablename
);
//ret = true;
}
}
return
ret
;
}
/// <summary>
/// 调试运行表接口
/// </summary>
/// <param name="folder">批处理目录</param>
/// <param name="runtablename">批处理文件名(带.ini)</param>
/// <param name="count">批处理运行次数</param>
private
void
RunTableOptWithCount
(
String
folder
,
String
runtablename
,
ushort
count
)
/// <returns>0-失败 1-成功</returns>
private
int
RunTableOptWithCount
(
String
folder
,
String
runtablename
,
ushort
count
)
{
//bool ret = false
;
RunTableHelper
runtable
=
new
RunTableHelper
(
folder
,
runtablename
)
;
int
initret
=
0
;
int
ret
=
0
;
if
(!
String
.
IsNullOrEmpty
(
globaldata
.
connection_ip
))
{
FileServerClient
rtclient
=
new
FileServerClient
();
rtclient
.
WtClientInit
(
globaldata
.
connection_ip
,
globaldata
.
fileserverport
);
initret
=
rtclient
.
WtClientInit
(
globaldata
.
connection_ip
,
globaldata
.
fileserverport
);
if
(
initret
==
1
)
{
if
(
File
.
Exists
(
Path
.
Combine
(
folder
,
runtablename
)))
{
rtclient
.
WtClientCopytoServer
(
"RunMethodStd.ini"
,
Path
.
Combine
(
folder
,
runtablename
),
globaldata
.
remoteFolder
+
"运行表\\"
);
ret
=
rtclient
.
WtClientCopytoServer
(
"RunMethodStd.ini"
,
Path
.
Combine
(
folder
,
runtablename
),
globaldata
.
remoteFolder
+
"运行表\\"
);
hmiopt
.
SetBatCount
(
count
);
SendSTDCMD
();
}
rtclient
.
WtClientClose
();
globaldata
.
m_pcbuffer
.
gcpcinfo
.
pcfileinfo
.
cur_RunTab
=
Path
.
Combine
(
folder
,
runtablename
);
//ret = true;
}
}
return
ret
;
}
/// <summary>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment