Commit 814b29ff authored by wangjunqiang's avatar wangjunqiang

优化文件提交接口和自动批处理接口

parent b4191e67
...@@ -3,6 +3,8 @@ using System.Collections.Generic; ...@@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading;
using GcDevicePc.Common;
namespace GcDevicePc namespace GcDevicePc
{ {
...@@ -32,69 +34,233 @@ namespace GcDevicePc ...@@ -32,69 +34,233 @@ namespace GcDevicePc
private uint hFileServerHandle; 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 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 try
{ {
byte[] fIP = Encoding.Unicode.GetBytes(RemoteIP); CallWithTimeout(ClientClose, 5000);
this.hFileServerHandle = fnWtClientInit(fIP, wport);
} }
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) public int WtClientCopytoServer(String filename, String filepath, String RemoteFilePath)
{ {
int bret; int bret = 1;
byte[] bfilename = Encoding.Unicode.GetBytes(filename);
byte[] bfilepath = Encoding.Unicode.GetBytes(filepath); try
byte[] bRemoteFilePath = Encoding.Unicode.GetBytes(RemoteFilePath); {
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); bret = fnWtClientCopytoServer(this.hFileServerHandle, bfilename, bfilepath, bRemoteFilePath);
}
catch (TimeoutException ex)
{
bret = 0;
Log.Error(ex.Message);
return bret;
}
return bret; return bret;
} }
public int WtClientCopyfromServer(String filename, String filepath, String RemoteFilePath) public int WtClientCopyfromServer(String filename, String filepath, String RemoteFilePath)
{ {
int bret; int bret = 1;
byte[] bfilename = Encoding.Unicode.GetBytes(filename); try
byte[] bfilepath = Encoding.Unicode.GetBytes(filepath); {
byte[] bRemoteFilePath = Encoding.Unicode.GetBytes(RemoteFilePath); bfilename = Encoding.Unicode.GetBytes(filename);
bret = fnWtClientCopyfromServer(this.hFileServerHandle, bfilename, bfilepath, bRemoteFilePath); 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; return bret;
} }
public int WtHMICloseRro(String filename) public int WtHMICloseRro(String filename)
{ {
int bret; int bret = 0;
byte[] bfilename = Encoding.Unicode.GetBytes(filename); try
{
bfilename = Encoding.Unicode.GetBytes(filename);
if (this.hFileServerHandle != 0)
bret = fnWtCloseCEPro(this.hFileServerHandle, bfilename); bret = fnWtCloseCEPro(this.hFileServerHandle, bfilename);
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return bret; return bret;
} }
public int WtHMIRunPro(String filename, String RemoteFilePath) public int WtHMIRunPro(String filename, String RemoteFilePath)
{ {
int bret; int bret = 0;
byte[] bfilename = Encoding.Unicode.GetBytes(filename); try
byte[] bRemoteFilePath = Encoding.Unicode.GetBytes(RemoteFilePath); {
bfilename = Encoding.Unicode.GetBytes(filename);
bRemoteFilePath = Encoding.Unicode.GetBytes(RemoteFilePath);
if (this.hFileServerHandle != 0)
bret = fnWtRunPro(this.hFileServerHandle, bfilename, bRemoteFilePath); bret = fnWtRunPro(this.hFileServerHandle, bfilename, bRemoteFilePath);
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return bret; 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
} }
} }
...@@ -1171,60 +1171,71 @@ namespace GcDevicePc ...@@ -1171,60 +1171,71 @@ namespace GcDevicePc
hmiopt.FireUPWork(flag, time1, time2); hmiopt.FireUPWork(flag, time1, time2);
} }
/// <summary> /// <summary>
/// 调试运行表接口 /// 调试运行表接口
/// </summary> /// </summary>
/// <param name="folder">批处理目录</param> /// <param name="folder">批处理目录</param>
/// <param name="runtablename">批处理文件名(带.ini)</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; int initret = 0;
RunTableHelper runtable = new RunTableHelper(folder, runtablename); int ret = 0;
if (!String.IsNullOrEmpty(globaldata.connection_ip)) if (!String.IsNullOrEmpty(globaldata.connection_ip))
{ {
FileServerClient rtclient = new FileServerClient(); 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))) 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); SendPCCMD(false);
} }
rtclient.WtClientClose(); rtclient.WtClientClose();
globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_RunTab = Path.Combine(folder, runtablename); globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_RunTab = Path.Combine(folder, runtablename);
//ret = true;
} }
} }
return ret;
}
/// <summary> /// <summary>
/// 调试运行表接口 /// 调试运行表接口
/// </summary> /// </summary>
/// <param name="folder">批处理目录</param> /// <param name="folder">批处理目录</param>
/// <param name="runtablename">批处理文件名(带.ini)</param> /// <param name="runtablename">批处理文件名(带.ini)</param>
/// <param name="count">批处理运行次数</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; int initret = 0;
RunTableHelper runtable = new RunTableHelper(folder, runtablename); int ret = 0;
if (!String.IsNullOrEmpty(globaldata.connection_ip)) if (!String.IsNullOrEmpty(globaldata.connection_ip))
{ {
FileServerClient rtclient = new FileServerClient(); 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))) 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); hmiopt.SetBatCount(count);
SendSTDCMD(); SendSTDCMD();
} }
rtclient.WtClientClose(); rtclient.WtClientClose();
globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_RunTab = Path.Combine(folder, runtablename); globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_RunTab = Path.Combine(folder, runtablename);
//ret = true;
} }
}
return ret;
} }
/// <summary> /// <summary>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment