Commit d269da47 authored by wangjunqiang's avatar wangjunqiang

清理部分代码

parent a4d691be
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<startup>
<configSections>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
<runtime> <runtime>
<legacyUnhandledExceptionPolicy enabled="true"/> <legacyUnhandledExceptionPolicy enabled="true"/>
</runtime> </runtime>
<log4net>
<logger name="Log">
<level value="INFO" />
<appender-ref ref="RollingLog" />
</logger>
<logger name="Err">
<level value="ERROR" />
<appender-ref ref="RollingErr" />
</logger>
<appender name="RollingLog" type="log4net.Appender.RollingFileAppender">
<file value="Logs\InfoLog_" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd'.txt'" />
<staticLogFileName value="false" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="Record Time:%d Thread ID:[%thread]- Info:%m%n" />
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<param name="LevelMin" value="INFO" />
<param name="LevelMax" value="INFO" />
</filter>
</appender>
<appender name="RollingErr" type="log4net.Appender.RollingFileAppender">
<file value="Logs\ErrLog_" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd'.txt'" />
<staticLogFileName value="false" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="Record Time:%d Thread ID:[%thread]- Error:%m%n" />
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<param name="LevelMin" value="ERROR" />
<param name="LevelMax" value="ERROR" />
</filter>
</appender>
</log4net>
</configuration> </configuration>
This diff is collapsed.
...@@ -12,27 +12,27 @@ namespace GcDevicePc.Common ...@@ -12,27 +12,27 @@ namespace GcDevicePc.Common
[DllImport(@"LibModbus.dll", EntryPoint = "fnLibModbus", CharSet = CharSet.Unicode)] [DllImport(@"LibModbus.dll", EntryPoint = "fnLibModbus", CharSet = CharSet.Unicode)]
public static extern uint fnLibModbus(); public static extern uint fnLibModbus();
[DllImport(@"LibModbus.dll", EntryPoint = "fnReadCoilStatus")] [DllImport(@"LibModbus.dll", EntryPoint = "fnReadCoilStatus")]
public static extern int fnReadCoilStatus(uint handle, ushort address, ushort num, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.Byte[] dest, byte[] Ip, ushort wTcpPort); public static extern int fnReadCoilStatus(uint handle, byte slaveaddress, ushort address, ushort num, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.Byte[] dest, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnReadInputStatus")] [DllImport(@"LibModbus.dll", EntryPoint = "fnReadInputStatus")]
public static extern int fnReadInputStatus(uint handle, ushort address, ushort num, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.Char[] dest, byte[] Ip, ushort wTcpPort); public static extern int fnReadInputStatus(uint handle, byte slaveaddress, ushort address, ushort num, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.Char[] dest, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnReadHoldingReg")] [DllImport(@"LibModbus.dll", EntryPoint = "fnReadHoldingReg")]
public static extern int fnReadHoldingReg(uint handle, ushort address, ushort num, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.UInt16[] dest, byte[] Ip, ushort wTcpPort); public static extern int fnReadHoldingReg(uint handle, byte slaveaddress, ushort address, ushort num, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.UInt16[] dest, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnReadInputReg")] [DllImport(@"LibModbus.dll", EntryPoint = "fnReadInputReg")]
public static extern int fnReadInputReg(uint handle, ushort address, ushort num, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.UInt16[] dest, byte[] Ip, ushort wTcpPort); public static extern int fnReadInputReg(uint handle, byte slaveaddress, ushort address, ushort num, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.UInt16[] dest, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnWriteSingleCoil")] [DllImport(@"LibModbus.dll", EntryPoint = "fnWriteSingleCoil")]
public static extern int fnWriteSingleCoil(uint handle, ushort address, ushort state, byte[] Ip, ushort wTcpPort); public static extern int fnWriteSingleCoil(uint handle, byte slaveaddress, ushort address, ushort state, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnWriteHoldingReg")] [DllImport(@"LibModbus.dll", EntryPoint = "fnWriteHoldingReg")]
public static extern int fnWriteHoldingReg(uint handle, ushort address, ushort state, byte[] Ip, ushort wTcpPort); public static extern int fnWriteHoldingReg(uint handle, byte slaveaddress, ushort address, ushort state, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnWriteMultipleCoils")] [DllImport(@"LibModbus.dll", EntryPoint = "fnWriteMultipleCoils")]
public static extern int fnWriteMultipleCoils(uint handle, ushort address, ushort num, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.Char[] src, byte[] Ip, ushort wTcpPort); public static extern int fnWriteMultipleCoils(uint handle, byte slaveaddress, ushort address, ushort num, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.Char[] src, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnWriteMultipleRegs")] [DllImport(@"LibModbus.dll", EntryPoint = "fnWriteMultipleRegs")]
public static extern int fnWriteMultipleRegs(uint handle, ushort address, ushort num, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.UInt16[] src, byte[] Ip, ushort wTcpPort); public static extern int fnWriteMultipleRegs(uint handle, byte slaveaddress, ushort address, ushort num, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.UInt16[] src, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnReportSlaveID")] [DllImport(@"LibModbus.dll", EntryPoint = "fnReportSlaveID")]
public static extern int fnReportSlaveID(uint handle, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.Char[] src, byte[] Ip, ushort wTcpPort); public static extern int fnReportSlaveID(uint handle, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.Char[] src, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnMaskWriteReg")] [DllImport(@"LibModbus.dll", EntryPoint = "fnMaskWriteReg")]
public static extern int fnMaskWriteReg(uint handle, ushort address, ushort amask, ushort omask, byte[] Ip, ushort wTcpPort); public static extern int fnMaskWriteReg(uint handle, byte slaveaddress, ushort address, ushort amask, ushort omask, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnReadWriteMultipleRegs")] [DllImport(@"LibModbus.dll", EntryPoint = "fnReadWriteMultipleRegs")]
public static extern int fnReadWriteMultipleRegs(uint handle, ushort waddress, ushort wnum, ushort raddress, ushort rnum, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.UInt16[] dest, byte[] Ip, ushort wTcpPort); public static extern int fnReadWriteMultipleRegs(uint handle, byte slaveaddress, ushort waddress, ushort wnum, ushort raddress, ushort rnum, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.UInt16[] dest, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnLibModbusClose")] [DllImport(@"LibModbus.dll", EntryPoint = "fnLibModbusClose")]
public static extern void fnLibModbusClose(uint handle); public static extern void fnLibModbusClose(uint handle);
...@@ -53,7 +53,7 @@ namespace GcDevicePc.Common ...@@ -53,7 +53,7 @@ namespace GcDevicePc.Common
{ {
int ret; int ret;
byte[] bIp = Encoding.Unicode.GetBytes(ip); byte[] bIp = Encoding.Unicode.GetBytes(ip);
ret = fnReadCoilStatus(hModbusHandle, (ushort)(addr - 1), num, buf, bIp, wport); ret = fnReadCoilStatus(hModbusHandle,1, (ushort)(addr - 1), num, buf, bIp, wport);
return ret; return ret;
} }
...@@ -61,7 +61,7 @@ namespace GcDevicePc.Common ...@@ -61,7 +61,7 @@ namespace GcDevicePc.Common
{ {
int ret; int ret;
byte[] bIp = Encoding.Unicode.GetBytes(ip); byte[] bIp = Encoding.Unicode.GetBytes(ip);
ret = fnReadInputStatus(hModbusHandle, addr, 1, buf, bIp, 502); ret = fnReadInputStatus(hModbusHandle,1, addr, 1, buf, bIp, 502);
return ret; return ret;
} }
...@@ -69,7 +69,7 @@ namespace GcDevicePc.Common ...@@ -69,7 +69,7 @@ namespace GcDevicePc.Common
{ {
int ret; int ret;
byte[] bIp = Encoding.Unicode.GetBytes(ip); byte[] bIp = Encoding.Unicode.GetBytes(ip);
ret = fnReadHoldingReg(hModbusHandle, (ushort)(addr - 1), num, buf, bIp, wport); ret = fnReadHoldingReg(hModbusHandle,1, (ushort)(addr - 1), num, buf, bIp, wport);
return ret; return ret;
} }
...@@ -77,7 +77,7 @@ namespace GcDevicePc.Common ...@@ -77,7 +77,7 @@ namespace GcDevicePc.Common
{ {
int ret; int ret;
byte[] bIp = Encoding.Unicode.GetBytes(ip); byte[] bIp = Encoding.Unicode.GetBytes(ip);
ret = fnReadInputReg(hModbusHandle, addr, 1, dest, bIp, 502); ret = fnReadInputReg(hModbusHandle, 1,addr, 1, dest, bIp, 502);
buf[0] = dest[0]; buf[0] = dest[0];
return ret; return ret;
} }
...@@ -86,7 +86,7 @@ namespace GcDevicePc.Common ...@@ -86,7 +86,7 @@ namespace GcDevicePc.Common
{ {
int ret = 0; int ret = 0;
byte[] bIp = Encoding.Unicode.GetBytes(ip); byte[] bIp = Encoding.Unicode.GetBytes(ip);
ret = fnWriteSingleCoil(hModbusHandle, (ushort)(addr - 1), state, bIp, wport); ret = fnWriteSingleCoil(hModbusHandle, 1, (ushort)(addr - 1), state, bIp, wport);
return ret; return ret;
} }
...@@ -94,7 +94,7 @@ namespace GcDevicePc.Common ...@@ -94,7 +94,7 @@ namespace GcDevicePc.Common
{ {
int ret = 0; int ret = 0;
byte[] bIp = Encoding.Unicode.GetBytes(ip); byte[] bIp = Encoding.Unicode.GetBytes(ip);
ret = fnWriteHoldingReg(hModbusHandle, (ushort)(addr - 1), state, bIp, wport); ret = fnWriteHoldingReg(hModbusHandle,1, (ushort)(addr - 1), state, bIp, wport);
return ret; return ret;
} }
...@@ -102,7 +102,7 @@ namespace GcDevicePc.Common ...@@ -102,7 +102,7 @@ namespace GcDevicePc.Common
{ {
int ret; int ret;
byte[] bIp = Encoding.Unicode.GetBytes(ip); byte[] bIp = Encoding.Unicode.GetBytes(ip);
ret = fnWriteMultipleRegs(hModbusHandle, (ushort)(addr - 1), num, buf, bIp, wport); ret = fnWriteMultipleRegs(hModbusHandle,1, (ushort)(addr - 1), num, buf, bIp, wport);
return ret; return ret;
} }
...@@ -118,7 +118,7 @@ namespace GcDevicePc.Common ...@@ -118,7 +118,7 @@ namespace GcDevicePc.Common
{ {
int ret = 0; int ret = 0;
byte[] bIp = Encoding.Unicode.GetBytes(ip); byte[] bIp = Encoding.Unicode.GetBytes(ip);
ret = fnMaskWriteReg(hModbusHandle, addr, amask, omask, bIp, 502); ret = fnMaskWriteReg(hModbusHandle, 1, addr, amask, omask, bIp, 502);
return ret; return ret;
} }
...@@ -126,7 +126,7 @@ namespace GcDevicePc.Common ...@@ -126,7 +126,7 @@ namespace GcDevicePc.Common
{ {
int ret = 0; int ret = 0;
byte[] bIp = Encoding.Unicode.GetBytes(ip); byte[] bIp = Encoding.Unicode.GetBytes(ip);
ret = fnReadWriteMultipleRegs(hModbusHandle, waddr, wnum, raddr, rnum, buf, bIp, 502); ret = fnReadWriteMultipleRegs(hModbusHandle, 1, waddr, wnum, raddr, rnum, buf, bIp, 502);
return ret; return ret;
} }
......
...@@ -105,8 +105,6 @@ namespace GcDevicePc.Common ...@@ -105,8 +105,6 @@ namespace GcDevicePc.Common
value = s[(address - baseaddress)%2]; value = s[(address - baseaddress)%2];
}catch{ }catch{
}finally{
} }
//} //}
} }
...@@ -137,7 +135,7 @@ namespace GcDevicePc.Common ...@@ -137,7 +135,7 @@ namespace GcDevicePc.Common
break; break;
case 8: //HMI状态 case 8: //HMI状态
{ {
value = (ushort)(globaldata.m_hmibuffer.gcinfo.methodstatus); value = globaldata.m_hmibuffer.gcinfo.methodstatus;
} }
break; break;
case 9: //前进样口 case 9: //前进样口
......
using System;
using System.Runtime.InteropServices;
namespace GcDevicePc.Common
{
class GCModbusSlave485
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate ushort SlaveReadHoldingRegister(ushort address);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate void SlaveWriteHoldingRegister(ushort address, ushort value);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate ushort SlaveReadCoilsRegister(ushort address);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate void SlaveWriteCoilsRegister(ushort address, ushort value);
[DllImport(@"LibModbus.dll", EntryPoint = "fnLibModbusSlave485Init", CharSet = CharSet.Unicode)]
public static extern uint fnLibModbusSlave485Init(System.Byte port, System.Int32 BaudRate);
[DllImport(@"LibModbus.dll", EntryPoint = "fnLibModbusSlaveHoldingRegister", CallingConvention = CallingConvention.Cdecl)]
public static extern void fnLibModbusSlaveHoldingRegister(System.UInt32 handle, SlaveReadHoldingRegister callslavereadholdingreg, SlaveWriteHoldingRegister callslavewirteholdingreg, ushort startAddr, ushort NReg);
[DllImport(@"LibModbus.dll", EntryPoint = "fnLibModbusSlaveCoilsRegister", CallingConvention = CallingConvention.Cdecl)]
public static extern void fnLibModbusSlaveCoilsRegister(System.UInt32 handle, SlaveReadCoilsRegister callslavereadcoilsreg, SlaveWriteCoilsRegister callslavewirtecoilsreg, ushort startAddr, ushort NReg);
[DllImport(@"LibModbus.dll", EntryPoint = "fnLibModbusSlaveClose")]
public static extern uint fnLibModbusSlaveClose(uint handle);
private uint hModbusHandle;
public GCModbusSlave485(Byte port, int baudrate )
{
this.hModbusHandle = fnLibModbusSlave485Init(port, baudrate);
}
~GCModbusSlave485()
{
try
{
fnLibModbusSlaveClose(hModbusHandle);
}
catch
{
}
}
public uint CModbusSlave485Close()
{
uint ret = 0;
try
{
ret = fnLibModbusSlaveClose(hModbusHandle);
}
catch
{
Console.WriteLine("Slave 退出出现Bug");
}
return ret;
}
public void CModbusSlave485Init(ushort hstartaddr, ushort hnreg, ushort cstartaddr, ushort cnreg)
{
setHoldingRegisterFunc(hstartaddr, hnreg);
setCoilsRegisterFunc(cstartaddr, cnreg);
}
SlaveReadHoldingRegister MySlaveReadHoldingRegister;
SlaveWriteHoldingRegister MySlaveWriteHoldingRegister;
public void setHoldingRegisterFunc(ushort startaddr, ushort nreg)
{
MySlaveReadHoldingRegister = new SlaveReadHoldingRegister(slavereadhreg);
MySlaveWriteHoldingRegister = new SlaveWriteHoldingRegister(slavewirtehreg);
fnLibModbusSlaveHoldingRegister(hModbusHandle, MySlaveReadHoldingRegister, MySlaveWriteHoldingRegister, startaddr, nreg);
}
static ushort slavereadhreg(ushort address)
{
ushort value = 0;
ushort baseaddress = 20;
address = (ushort)(address - 1);
int listnum = CKVocAnalyzer.GlobalCKV.valueparamlist.Count;
int readnum = (address - baseaddress) / 2;
if (readnum <= listnum - 1 && listnum > 0 && address >= 20)
{
try
{
ushort[] s = new ushort[2];
float[] f = new float[2];
{
f[0] = float.Parse(CKVocAnalyzer.GlobalCKV.valueparamlist[(ushort)readnum].ToString());
Buffer.BlockCopy(f, 2, s, 0, 2);
Buffer.BlockCopy(f, 0, s, 2, 2);
}
value = s[(address - baseaddress) % 2];
}
catch
{
}
}
return value;
}
static void slavewirtehreg(ushort address, ushort value)
{
Console.WriteLine("MoudbusSlave Wirte adder:" + address.ToString() + " value:" + value.ToString());
}
SlaveReadCoilsRegister MySlaveReadCoilsRegister;
SlaveWriteCoilsRegister MySlaveWriteCoilsRegister;
public void setCoilsRegisterFunc(ushort startaddr, ushort nreg)
{
MySlaveReadCoilsRegister = new SlaveReadCoilsRegister(slavereadcreg);
MySlaveWriteCoilsRegister = new SlaveWriteCoilsRegister(slavewirtecreg);
fnLibModbusSlaveCoilsRegister(hModbusHandle, MySlaveReadCoilsRegister, MySlaveWriteCoilsRegister, startaddr, nreg);
}
public static ushort slavereadcreg(ushort address)
{
ushort value = 0;
// Console.WriteLine("MoudbusSlave Read Holding adder is " + CKVocAnalyzer.GlobalCKV.valueparamlist.ToString());
return value;
}
public static void slavewirtecreg(ushort address, ushort value)
{
//Console.WriteLine("MoudbusSlave Wirte adder:" + address.ToString() + " value:" + value.ToString());
}
}
}
using System.Diagnostics;
using log4net;
using System.Reflection;
namespace GcDevicePc.Common
{
public static class Log
{
private static readonly ILog logInfo = LogManager.GetLogger("Log");
private static readonly ILog logErr = LogManager.GetLogger("Err");
/// <summary>
/// 记录正常的消息
/// </summary>
/// <param name="msg">消息内容</param>
public static void Info(string msg)
{
logInfo.Info(msg);
}
/// <summary>
/// 记录异常信息
/// </summary>
/// <param name="msg">异常信息内容</param>
public static void Error(string msg)
{
StackTrace stackTrace = new StackTrace();
StackFrame stackFrame = stackTrace.GetFrame(1);
MethodBase methodBase = stackFrame.GetMethod();
logErr.Error("ClassName:" + methodBase.ReflectedType.Name + " Func Name:" + methodBase.Name + " Info:" + msg);
}
}
}
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ini.Net;
namespace GcDevicePc.Common
{
class RunTableHelper
{
private string _filename;
private string _asfilename;
public bool fileflag =false;
private IniFile RunTableFile;
private IniFile AsRunTableFile;
public List<String> _methodname = new List<String>();
public List<Int32> _runcount = new List<Int32>();
public List<Int32> _runtime = new List<Int32>();
private void RunTableInit()
{
_methodname.Add("开机");
_runcount.Add(1);
_runtime.Add(1);
}
public RunTableHelper(String folder, String filename)
{
_filename = folder+"\\"+filename;
try
{
if (!File.Exists(_filename))
{
StreamWriter sw = new StreamWriter(_filename, false, Encoding.Unicode);
sw.WriteLine("[Total]");
sw.WriteLine("[运行表]");
sw.WriteLine("[循环]");
sw.WriteLine("[运行时间]");
sw.Close();
fileflag = true;
RunTableInit();
}
else
{
fileflag = true;
}
}
catch (Exception e)
{
Log.Error(e.Message);
}
if (fileflag)
LoadRunTable();
}
public void LoadRunTable()
{
RunTableFile = new IniFile(_filename);
int num = 0;
int i = 0;
if (RunTableFile.KeyExists("Total", "count"))
{
num = RunTableFile.ReadInteger("Total", "count");
for (i = 0; i < num ; i++)
{
_methodname.Add(RunTableFile.ReadString("运行表",i.ToString()));
_runcount.Add(RunTableFile.ReadInteger("循环", i.ToString()));
_runtime.Add(RunTableFile.ReadInteger("运行时间", i.ToString()));
}
}
else
{
for (i = 0; i < 100; i++)
{
if ( RunTableFile.KeyExists("运行表", i.ToString()) && RunTableFile.KeyExists("循环", i.ToString()) && RunTableFile.KeyExists("运行时间", i.ToString()))
{
_methodname.Add(RunTableFile.ReadString("运行表", i.ToString()));
_runcount.Add(RunTableFile.ReadInteger("循环", i.ToString()));
_runtime.Add(RunTableFile.ReadInteger("运行时间", i.ToString()));
}
else
{
RunTableFile.WriteInteger("Total", "count", i);
break;
}
}
}
}
public void DelRunTable()
{
if(File.Exists(_filename))
File.Delete(_filename);
}
public void AddItem(String name, Int32 count, Int32 time)
{
_methodname.Add(name);
_runcount.Add(count);
_runtime.Add(time);
}
public void ModifyItem(Int32 index, String name, Int32 count, Int32 time)
{
_methodname[index] = name;
_runcount[index] = count;
_runtime[index] = time;
}
public bool RemoveItem(String name, Int32 count, Int32 time)
{
int indexno = 0;
if (_methodname.Contains(name))
{
indexno &= _methodname.IndexOf(name);
indexno &= _runcount.IndexOf(count);
indexno &= _runtime.IndexOf(time);
if (indexno == 0)
{
_methodname.RemoveAt(indexno);
_runcount.RemoveAt(indexno);
_runtime.RemoveAt(indexno);
return true;
}
}
return false;
}
private bool saveini(IniFile saveini)
{
int i;
int count = _methodname.Count & _runcount.Count & _runtime.Count;
for (i = 0; i < _methodname.Count; i++)
{
saveini.WriteString("运行表", i.ToString(), _methodname[i]);
}
for (i = 0; i < _runcount.Count; i++)
{
saveini.WriteInteger("循环", i.ToString(), _runcount[i]);
}
for (i = 0; i < _runtime.Count; i++)
{
saveini.WriteInteger("运行时间", i.ToString(), _runtime[i]);
}
saveini.WriteInteger("Total", "count", count);
return true;
}
public bool SaveRunTable()
{
return saveini(RunTableFile);
}
public bool SaveAsRunTable(String folder, String filename)
{
_asfilename = folder + "\\" + filename;
try
{
if (!File.Exists(_asfilename))
{
StreamWriter sw = new StreamWriter(_asfilename, false, Encoding.Unicode);
sw.WriteLine("[Total]");
sw.WriteLine("[运行表]");
sw.WriteLine("[循环]");
sw.WriteLine("[运行时间]");
sw.Close();
}
}
catch (Exception e)
{
Log.Error(e.Message);
}
AsRunTableFile = new IniFile(_asfilename);
return saveini(AsRunTableFile);
}
}
}
...@@ -89,6 +89,7 @@ ...@@ -89,6 +89,7 @@
this.Activated += new System.EventHandler(this.FormUser_Activated); this.Activated += new System.EventHandler(this.FormUser_Activated);
this.Deactivate += new System.EventHandler(this.FormUser_Deactivate); this.Deactivate += new System.EventHandler(this.FormUser_Deactivate);
this.Load += new System.EventHandler(this.FormUser_Load); this.Load += new System.EventHandler(this.FormUser_Load);
this.Resize += new System.EventHandler(this.FormUser_Resize);
this.ResumeLayout(false); this.ResumeLayout(false);
} }
......
...@@ -34,12 +34,19 @@ namespace GcDevicePc ...@@ -34,12 +34,19 @@ namespace GcDevicePc
// MessageBox.Show("停用"); // MessageBox.Show("停用");
// Console.WriteLine("停用"); // Console.WriteLine("停用");
} }
public event Fireport autofire; public event Fireport autofire;
private void buttonFID_Click(object sender, EventArgs e) private void buttonFID_Click(object sender, EventArgs e)
{ {
autofire(0,10,5); autofire(0,10,5);
} }
private void FormUser_Resize(object sender, EventArgs e)
{
this.buttonFID.Location = new Point(this.infoBarUser1.Width + 50, this.infoBarUser1.Location.Y + 10);
this.buttonauto.Location = new Point(this.infoBarUser1.Width + 50, this.infoBarUser1.Location.Y + 80);
}
} }
} }
...@@ -12,9 +12,12 @@ namespace GcDevicePc.GCBuffer ...@@ -12,9 +12,12 @@ namespace GcDevicePc.GCBuffer
public string DataFolder; //数据保存目录 public string DataFolder; //数据保存目录
public string RunFolder; //当前程序运行目录 public string RunFolder; //当前程序运行目录
public string MethodFolder; //当前方法目录 public string MethodFolder; //当前方法目录
public string StatusFolder; //当前状态目录 public string StatusFolder; //当前配置目录
public string subStatusFolder; //当前状态目录 public string SubStatusFolder; //当前配置子目录
public string RunTabFolder; //当前运行表目录 public string RunTabFolder; //当前运行表目录
public string FwFolder; //固件更新目录
public string TmpFolder; //TMPFile目录
public string LogFolder; //Log目录
} }
public struct GCFileInfo public struct GCFileInfo
...@@ -58,8 +61,11 @@ namespace GcDevicePc.GCBuffer ...@@ -58,8 +61,11 @@ namespace GcDevicePc.GCBuffer
gcpcinfo.pcfolderinfo.RunFolder = null; gcpcinfo.pcfolderinfo.RunFolder = null;
gcpcinfo.pcfolderinfo.MethodFolder = null; gcpcinfo.pcfolderinfo.MethodFolder = null;
gcpcinfo.pcfolderinfo.StatusFolder = null; gcpcinfo.pcfolderinfo.StatusFolder = null;
gcpcinfo.pcfolderinfo.subStatusFolder = null; gcpcinfo.pcfolderinfo.SubStatusFolder = null;
gcpcinfo.pcfolderinfo.RunTabFolder = null; gcpcinfo.pcfolderinfo.RunTabFolder = null;
gcpcinfo.pcfolderinfo.FwFolder = null;
gcpcinfo.pcfolderinfo.TmpFolder = null;
gcpcinfo.pcfolderinfo.LogFolder = null;
gcpcinfo.pcfileinfo.cur_MethodName = null; gcpcinfo.pcfileinfo.cur_MethodName = null;
gcpcinfo.pcfileinfo.cur_OpenMethodName = null; gcpcinfo.pcfileinfo.cur_OpenMethodName = null;
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>GcDevicePc</RootNamespace> <RootNamespace>GcDevicePc</RootNamespace>
<AssemblyName>GcDevicePc</AssemblyName> <AssemblyName>GcDevicePc</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<IsWebBootstrapper>false</IsWebBootstrapper> <IsWebBootstrapper>false</IsWebBootstrapper>
<TargetFrameworkProfile> <TargetFrameworkProfile>
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath> <OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DebugType>full</DebugType> <DebugType>full</DebugType>
...@@ -99,6 +99,12 @@ ...@@ -99,6 +99,12 @@
<Reference Include="CKVocAnalyzer"> <Reference Include="CKVocAnalyzer">
<HintPath>..\dll\CKVocAnalyzer.dll</HintPath> <HintPath>..\dll\CKVocAnalyzer.dll</HintPath>
</Reference> </Reference>
<Reference Include="Ini.Net, Version=1.0.5531.18665, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ini.net.1.1.0\lib\net20\Ini.Net.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
</Reference>
<Reference Include="LogOperate"> <Reference Include="LogOperate">
<HintPath>..\dll\LogOperate.dll</HintPath> <HintPath>..\dll\LogOperate.dll</HintPath>
</Reference> </Reference>
...@@ -138,6 +144,7 @@ ...@@ -138,6 +144,7 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="AppInit.cs" />
<Compile Include="auxtool.cs"> <Compile Include="auxtool.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
...@@ -183,7 +190,9 @@ ...@@ -183,7 +190,9 @@
<Compile Include="Common\GCModbus.cs" /> <Compile Include="Common\GCModbus.cs" />
<Compile Include="Common\GCModbusSlave.cs" /> <Compile Include="Common\GCModbusSlave.cs" />
<Compile Include="Common\FileHelper.cs" /> <Compile Include="Common\FileHelper.cs" />
<Compile Include="Common\LogHelper.cs" /> <Compile Include="Common\GCModbusSlave485.cs" />
<Compile Include="Common\Log.cs" />
<Compile Include="Common\RunTableHelper.cs" />
<Compile Include="Common\SendDataToHW.cs" /> <Compile Include="Common\SendDataToHW.cs" />
<Compile Include="ConfigDlg\ChromeDlg.cs"> <Compile Include="ConfigDlg\ChromeDlg.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
......
This diff is collapsed.
This diff is collapsed.
...@@ -136,6 +136,6 @@ ...@@ -136,6 +136,6 @@
<value>601, 17</value> <value>601, 17</value>
</metadata> </metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>175</value> <value>86</value>
</metadata> </metadata>
</root> </root>
\ No newline at end of file
...@@ -149,7 +149,7 @@ namespace GcDevicePc ...@@ -149,7 +149,7 @@ namespace GcDevicePc
//MainBase初始化 //MainBase初始化
InitializeComponent(); InitializeComponent();
//运行环境初始化 //运行环境初始化
MainBase_InitAppConfig(); // MainBase_InitAppConfig();
//标题初始化 //标题初始化
ManinBase_InitFormTitle(); ManinBase_InitFormTitle();
//菜单初始化 //菜单初始化
...@@ -735,11 +735,6 @@ namespace GcDevicePc ...@@ -735,11 +735,6 @@ namespace GcDevicePc
System.IO.File.Create(globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_StatusName).Dispose(); System.IO.File.Create(globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_StatusName).Dispose();
} }
globaldata.m_pcbuffer.gcpcinfo.pcfolderinfo.subStatusFolder = System.IO.Path.Combine(tmpFolder, "子状态");
if (System.IO.Directory.Exists(globaldata.m_pcbuffer.gcpcinfo.pcfolderinfo.subStatusFolder) == false)
{
System.IO.Directory.CreateDirectory(globaldata.m_pcbuffer.gcpcinfo.pcfolderinfo.subStatusFolder);
}
globaldata.m_profileMethod.SetStatusFullName(globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_StatusName); globaldata.m_profileMethod.SetStatusFullName(globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_StatusName);
...@@ -755,6 +750,7 @@ namespace GcDevicePc ...@@ -755,6 +750,7 @@ namespace GcDevicePc
{ {
System.IO.Directory.CreateDirectory(globaldata.m_pcbuffer.gcpcinfo.pcfolderinfo.RunTabFolder); System.IO.Directory.CreateDirectory(globaldata.m_pcbuffer.gcpcinfo.pcfolderinfo.RunTabFolder);
} }
if (System.IO.File.Exists(globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_RunTab) == false) if (System.IO.File.Exists(globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_RunTab) == false)
{ {
StreamWriter sw = new StreamWriter(globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_RunTab, false, System.Text.Encoding.Unicode); StreamWriter sw = new StreamWriter(globaldata.m_pcbuffer.gcpcinfo.pcfileinfo.cur_RunTab, false, System.Text.Encoding.Unicode);
......
...@@ -38,7 +38,7 @@ namespace GcDevicePc.ProThread ...@@ -38,7 +38,7 @@ namespace GcDevicePc.ProThread
{ {
try try
{ {
if (globaldata.connection_ip != null && globaldata.connection_ip != "") if (!String.IsNullOrEmpty(globaldata.connection_ip))
socket.Connect(globaldata.connection_ip, 8005); //配置服务器IP与端口 socket.Connect(globaldata.connection_ip, 8005); //配置服务器IP与端口
Console.WriteLine("连接服务器成功"); Console.WriteLine("连接服务器成功");
break; break;
......
...@@ -9,91 +9,109 @@ using System.Text.RegularExpressions; ...@@ -9,91 +9,109 @@ using System.Text.RegularExpressions;
using System.Collections; using System.Collections;
using System.Management; using System.Management;
using System.Net.NetworkInformation; using System.Net.NetworkInformation;
using GcDevicePc.Common;
namespace GcDevicePc.ProThread namespace GcDevicePc.ProThread
{ {
class HMISearch class HMISearch
{ {
public UdpClient client; private UdpClient client;
public IPEndPoint endpoint; private IPEndPoint endpoint;
Thread searchth; Thread searchth;
ManualResetEvent mre = new ManualResetEvent(false); ManualResetEvent mre = new ManualResetEvent(false);
public globaldata.DeviceInfo m_DeviceInfo; public globaldata.DeviceInfo m_DeviceInfo;
public ArrayList myHMIList = new ArrayList(); public ArrayList myHMIList = new ArrayList();
string FMAC =null; private string FMAC = null;
string file = System.Windows.Forms.Application.StartupPath + "\\startup.ini";
string localip = null; private string _localip = null;
/// <summary> /// <summary>
/// 构造函数 /// 构造函数
/// </summary> /// </summary>
public HMISearch() public HMISearch(String hmimac)
{ {
// globaldata.hHMIList.Clear(); this.FMAC = hmimac;
myHMIList.Clear(); myHMIList.Clear();
globaldata.DeviceList.Clear(); globaldata.DeviceList.Clear();
GetHmiIp();
}
INIOperation test = new INIOperation(file); public void ReGetHmiIp()
this.FMAC = test.INIGetStringValue("NetWorkConfig", "MAC地址", null); {
GetHmiIp();
}
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces(); private void GetHmiIp()
foreach (NetworkInterface adapter in nics) {
Log.Info("Start Get PC Local IP...");
try
{ {
if (adapter.Name == "本地连接") NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in nics)
{ {
bool Pd1 = (adapter.NetworkInterfaceType == NetworkInterfaceType.Ethernet); //判断是否是以太网连接 if (adapter.Name == "本地连接")
if (Pd1)
{ {
bool pd1 = (adapter.NetworkInterfaceType == NetworkInterfaceType.Ethernet); //判断是否是以太网连接
if (pd1)
{ {
IPInterfaceProperties ip = adapter.GetIPProperties(); //IP配置信息 IPInterfaceProperties ip = adapter.GetIPProperties(); //IP配置信息
UnicastIPAddressInformationCollection ipCollection = ip.UnicastAddresses; UnicastIPAddressInformationCollection ipCollection = ip.UnicastAddresses;
foreach (UnicastIPAddressInformation ipadd in ipCollection) foreach (UnicastIPAddressInformation ipadd in ipCollection)
{ {
if (ipadd.Address.AddressFamily == AddressFamily.InterNetwork) if (ipadd.Address.AddressFamily == AddressFamily.InterNetwork)
this.localip = ipadd.Address.ToString();//获取ip this._localip = ipadd.Address.ToString();//获取ip
} }
} }
} }
} }
}
} catch (Exception e)
{
Log.Error(e.Message);
}
} }
public void ThStart() public Boolean ThStart()
{ {
if (mre != null) if (String.IsNullOrEmpty(this._localip))
mre.Reset(); {
Console.WriteLine("搜索线程开始...."); return false;
searchth = new Thread(ThreadMethod); }
searchth.IsBackground = true; else
searchth.Start(); {
if (mre != null)
mre.Reset();
Log.Info("Start Search HMI...");
searchth = new Thread(ThreadMethod);
searchth.IsBackground = true;
searchth.Start();
return true;
}
} }
public void ThStop() public void ThStop()
{ {
Console.WriteLine("搜索线程结束...."); Log.Info("Stop Search HMI...");
mre.Set(); mre.Set();
// FMAC = null;
} }
public int HMICount() public int HMICount()
{ {
//return globaldata.hHMIList.Count;
return myHMIList.Count; return myHMIList.Count;
} }
private void ThreadMethod() private void ThreadMethod()
{ {
//byte[] sendBytes = new byte[] { 0x57, 0x54, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x55, 0xAA }; //byte[] sendBytes = new byte[] { 0x57, 0x54, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x55, 0xAA };
byte[] sendBytes = new byte[] { 0x57, 0x54, 0x04, 0x00, 0x00, 0x00, 0x03, 0x02, 0x00, 0x00, 0x55, 0xAA }; //脱机 byte[] sendBytes = new byte[] { 0x57, 0x54, 0x04, 0x00, 0x00, 0x00, 0x03, 0x02, 0x00, 0x00, 0x55, 0xAA };
int iReadBytes = 0; int iReadBytes = 0;
try try
{ {
// client = new UdpClient(new IPEndPoint(IPAddress.Any, 0)); client = new UdpClient(new IPEndPoint(IPAddress.Any, 0));
client = new UdpClient(new IPEndPoint(IPAddress.Parse(this.localip), 0)); // client = new UdpClient(new IPEndPoint(IPAddress.Parse(this._localip), 0));
endpoint = new IPEndPoint(IPAddress.Parse("255.255.255.255"), 233); endpoint = new IPEndPoint(IPAddress.Parse("255.255.255.255"), 233);
client.Send(sendBytes, sendBytes.Length, endpoint); client.Send(sendBytes, sendBytes.Length, endpoint);
Thread.Sleep(500); Thread.Sleep(500);
...@@ -112,14 +130,13 @@ namespace GcDevicePc.ProThread ...@@ -112,14 +130,13 @@ namespace GcDevicePc.ProThread
DoRecvDataCallBack(recvBytes, iReadBytes); DoRecvDataCallBack(recvBytes, iReadBytes);
} }
} }
}catch }catch (Exception e)
{ {
Console.WriteLine(e.Message);
} }
} }
public Boolean DoRecvDataCallBack(byte[] pcData, int iRecvLength) private Boolean DoRecvDataCallBack(byte[] pcData, int iRecvLength)
{ {
int i; int i;
int count = 0; int count = 0;
...@@ -138,7 +155,7 @@ namespace GcDevicePc.ProThread ...@@ -138,7 +155,7 @@ namespace GcDevicePc.ProThread
if ((iDataLength >= 4) && (iRecvLength == 8 + iDataLength)) if ((iDataLength >= 4) && (iRecvLength == 8 + iDataLength))
{ {
System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding(); ASCIIEncoding asciiEncoding = new ASCIIEncoding();
m_DeviceInfo.bActive = false; m_DeviceInfo.bActive = false;
for (i = 0; i < 100; i++ ) for (i = 0; i < 100; i++ )
......
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading; using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
using System.Net.NetworkInformation; using System.Net.NetworkInformation;
using System.Net.Sockets; using System.Net.Sockets;
using GcDevicePc.Common;
using GcDevicePc.ProThread;
namespace GcDevicePc namespace GcDevicePc
{ {
static class Program static class Program
{ {
/// <summary> private static void Isnetworkok()
/// The main entry point for the application.
/// </summary>
///
//static public string GetGW()
//{
// string strGateway = "192.168.10.1";
// try
// {
// NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
// //遍历数组
// foreach (NetworkInterface adapter in nics)
// {
// if (adapter.Name == "本地连接")
// {
// bool Pd1 = (adapter.NetworkInterfaceType == NetworkInterfaceType.Ethernet); //判断是否是以太网连接
// if (Pd1)
// {
// IPInterfaceProperties ip = adapter.GetIPProperties();
// GatewayIPAddressInformationCollection gateways = ip.GatewayAddresses;
// foreach (var gateWay in gateways)
// {
// strGateway = gateWay.Address.ToString();
// if (strGateway.Length > 0)
// {
// break;
// }
// }
// }
// }
// }
// return strGateway;
// }
// finally
// {
// }
// return strGateway;
//}
static public void isnetworkok()
{ {
string localip = ""; String localip = "";
while(true) while(true)
{ {
try try
...@@ -67,8 +23,8 @@ namespace GcDevicePc ...@@ -67,8 +23,8 @@ namespace GcDevicePc
{ {
if (adapter.Name == "本地连接") if (adapter.Name == "本地连接")
{ {
bool Pd1 = (adapter.NetworkInterfaceType == NetworkInterfaceType.Ethernet); //判断是否是以太网连接 bool pd1 = (adapter.NetworkInterfaceType == NetworkInterfaceType.Ethernet);
if (Pd1) if (pd1)
{ {
IPInterfaceProperties ip = adapter.GetIPProperties(); IPInterfaceProperties ip = adapter.GetIPProperties();
UnicastIPAddressInformationCollection ipCollection = ip.UnicastAddresses; UnicastIPAddressInformationCollection ipCollection = ip.UnicastAddresses;
...@@ -85,11 +41,10 @@ namespace GcDevicePc ...@@ -85,11 +41,10 @@ namespace GcDevicePc
} }
} }
} }
} }
finally catch (Exception e)
{ {
Log.Error(e.Message);
} }
if (globaldata.OffLinkMode || globaldata.StartNetwork) if (globaldata.OffLinkMode || globaldata.StartNetwork)
...@@ -103,23 +58,23 @@ namespace GcDevicePc ...@@ -103,23 +58,23 @@ namespace GcDevicePc
static public bool Ping(string ip) static public bool Ping(string ip)
{ {
System.Net.NetworkInformation.Ping p; Ping p;
System.Net.NetworkInformation.PingOptions options; PingOptions options;
System.Net.NetworkInformation.PingReply reply; PingReply reply;
string data; string data;
int timeout; int timeout;
try try
{ {
p = new System.Net.NetworkInformation.Ping(); p = new Ping();
options = new System.Net.NetworkInformation.PingOptions(); options = new PingOptions();
options.DontFragment = true; options.DontFragment = true;
data = "Test Data!"; data = "Test Data!";
byte[] buffer = System.Text.Encoding.ASCII.GetBytes(data); byte[] buffer = System.Text.Encoding.ASCII.GetBytes(data);
timeout = 1000; // Timeout 时间,单位:毫秒 timeout = 1000; // Timeout 时间,单位:毫秒
reply = p.Send(ip, timeout, buffer, options); reply = p.Send(ip, timeout, buffer, options);
if (reply.Status == System.Net.NetworkInformation.IPStatus.Success) if (reply.Status == IPStatus.Success)
{ {
globaldata.StartNetwork = true; globaldata.StartNetwork = true;
return true; return true;
...@@ -136,25 +91,35 @@ namespace GcDevicePc ...@@ -136,25 +91,35 @@ namespace GcDevicePc
} }
static string ip; static string ip;
static private void CheckHmi() private static void CheckHmi()
{ {
ProThread.HMISearch mysearch = new ProThread.HMISearch(); HMISearch mysearch = new HMISearch(null);
int hmicount = 0; int hmicount = 0;
bool ret = false;
while (true) while (true)
{ {
mysearch.ThStart(); ret = mysearch.ThStart();
Thread.Sleep(3000);
hmicount = mysearch.HMICount();
if (hmicount >= 1) if (ret)
{ {
ip = (((globaldata.DeviceInfo)(mysearch.myHMIList[0])).IpAddr); Thread.Sleep(3000);
globaldata.connection_ip = ip; hmicount = mysearch.HMICount();
break; if (hmicount >= 1)
} {
mysearch.ThStop(); ip = (((globaldata.DeviceInfo)(mysearch.myHMIList[0])).IpAddr);
globaldata.connection_ip = ip;
break;
}
mysearch.ThStop();
ret = false;
}
else
{
mysearch.ReGetHmiIp();
Thread.Sleep(2000);
}
if (globaldata.OffLinkMode) if (globaldata.OffLinkMode)
{ {
globaldata.connection_ip = ""; globaldata.connection_ip = "";
...@@ -162,16 +127,10 @@ namespace GcDevicePc ...@@ -162,16 +127,10 @@ namespace GcDevicePc
} }
} }
} }
static private System.Windows.Forms.DialogResult ShowStart() private static void RunStartWin()
{ {
return new StartWin().ShowDialog(); DialogResult dr = new StartWin().ShowDialog();
}
static private void runStartWin()
{
DialogResult dr;
dr = ShowStart();
} }
[STAThread] [STAThread]
...@@ -180,36 +139,16 @@ namespace GcDevicePc ...@@ -180,36 +139,16 @@ namespace GcDevicePc
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
//bool pingok = false;
bool createNew; bool createNew;
//string ipgw = "";
Thread t_StartWin;
t_StartWin = new Thread(runStartWin);
t_StartWin.IsBackground = true;
t_StartWin.Start();
//while (true) Thread tStartWin = new Thread(RunStartWin)
//{ {
// ipgw = GetGW(); IsBackground = true
// pingok = Ping(ipgw); };
tStartWin.Start();
// if (pingok)
// {
// break;
// }
// if(globaldata.OffLinkMode) Isnetworkok();
// {
// break;
// }
// Thread.Sleep(1000);
//}
isnetworkok();
CheckHmi(); CheckHmi();
{ {
using (System.Threading.Mutex mutex = new System.Threading.Mutex(true, Application.ProductName, out createNew)) using (System.Threading.Mutex mutex = new System.Threading.Mutex(true, Application.ProductName, out createNew))
{ {
...@@ -220,7 +159,6 @@ namespace GcDevicePc ...@@ -220,7 +159,6 @@ namespace GcDevicePc
else else
{ {
MessageBox.Show("应用程序已经在运行中..."); MessageBox.Show("应用程序已经在运行中...");
System.Threading.Thread.Sleep(1000); System.Threading.Thread.Sleep(1000);
System.Environment.Exit(1); System.Environment.Exit(1);
} }
......
...@@ -34,3 +34,4 @@ using System.Runtime.InteropServices; ...@@ -34,3 +34,4 @@ using System.Runtime.InteropServices;
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.1")] [assembly: AssemblyVersion("1.0.0.1")]
[assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
\ No newline at end of file
...@@ -19,7 +19,7 @@ namespace GcDevicePc.Properties { ...@@ -19,7 +19,7 @@ namespace GcDevicePc.Properties {
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。 // (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources { internal class Resources {
......
...@@ -12,7 +12,7 @@ namespace GcDevicePc.Properties { ...@@ -12,7 +12,7 @@ namespace GcDevicePc.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.6.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
......
...@@ -28,7 +28,7 @@ namespace GcDevicePc ...@@ -28,7 +28,7 @@ namespace GcDevicePc
bool VerifyName() bool VerifyName()
{ {
string strtmp; string strtmp;
DirectoryInfo MethodDir = new DirectoryInfo(globaldata.m_pcbuffer.gcpcinfo.pcfolderinfo.subStatusFolder); DirectoryInfo MethodDir = new DirectoryInfo(globaldata.m_pcbuffer.gcpcinfo.pcfolderinfo.SubStatusFolder);
foreach (FileInfo file in MethodDir.GetFiles("*.ini")) foreach (FileInfo file in MethodDir.GetFiles("*.ini"))
{ {
strtmp = this.newcfgname.Text + ".ini"; strtmp = this.newcfgname.Text + ".ini";
...@@ -64,7 +64,7 @@ namespace GcDevicePc ...@@ -64,7 +64,7 @@ namespace GcDevicePc
private void okbutton_Click(object sender, EventArgs e) private void okbutton_Click(object sender, EventArgs e)
{ {
string filename = this.newcfgname.Text +".ini"; string filename = this.newcfgname.Text +".ini";
filename = System.IO.Path.Combine(globaldata.m_pcbuffer.gcpcinfo.pcfolderinfo.subStatusFolder, filename); filename = System.IO.Path.Combine(globaldata.m_pcbuffer.gcpcinfo.pcfolderinfo.SubStatusFolder, filename);
SaveInI(filename); SaveInI(filename);
this.Close(); this.Close();
} }
......
...@@ -25,7 +25,7 @@ namespace GcDevicePc ...@@ -25,7 +25,7 @@ namespace GcDevicePc
private void SendConfig_Load(object sender, EventArgs e) private void SendConfig_Load(object sender, EventArgs e)
{ {
DirectoryInfo subStatusDir = new DirectoryInfo(globaldata.m_pcbuffer.gcpcinfo.pcfolderinfo.subStatusFolder); DirectoryInfo subStatusDir = new DirectoryInfo(globaldata.m_pcbuffer.gcpcinfo.pcfolderinfo.SubStatusFolder);
localStatusList.Items.Clear(); localStatusList.Items.Clear();
foreach (FileInfo file in subStatusDir.GetFiles("*.ini")) foreach (FileInfo file in subStatusDir.GetFiles("*.ini"))
...@@ -102,7 +102,7 @@ namespace GcDevicePc ...@@ -102,7 +102,7 @@ namespace GcDevicePc
if (localStatusList.GetItemChecked(i)) if (localStatusList.GetItemChecked(i))
{ {
checkfilename = localStatusList.GetItemText(localStatusList.Items[i]); checkfilename = localStatusList.GetItemText(localStatusList.Items[i]);
sendfilename = System.IO.Path.Combine(globaldata.m_pcbuffer.gcpcinfo.pcfolderinfo.subStatusFolder, checkfilename); sendfilename = System.IO.Path.Combine(globaldata.m_pcbuffer.gcpcinfo.pcfolderinfo.SubStatusFolder, checkfilename);
} }
} }
......
...@@ -17,14 +17,9 @@ namespace GcDevicePc ...@@ -17,14 +17,9 @@ namespace GcDevicePc
private const double OpacityInterval = 0.02; //0.02 private const double OpacityInterval = 0.02; //0.02
private const double StayTime = 2000; //5s private const double StayTime = 2000; //5s
//int count = 0;
System.Timers.Timer OpacityTimer;
Thread t_preload;
//Thread addhmi;
//ManualResetEvent mre = new ManualResetEvent(false);
System.Timers.Timer OpacityTimer;
static Thread t_preload;
MainForm m_mainform; MainForm m_mainform;
private void OpacityTimerProcOpen(object sender, System.Timers.ElapsedEventArgs e) private void OpacityTimerProcOpen(object sender, System.Timers.ElapsedEventArgs e)
...@@ -32,9 +27,7 @@ namespace GcDevicePc ...@@ -32,9 +27,7 @@ namespace GcDevicePc
if (this.m_CurrentOpacity < 1) if (this.m_CurrentOpacity < 1)
{ {
////如果当前的透明度小于1,则继续增加透明度 ////如果当前的透明度小于1,则继续增加透明度
this.m_CurrentOpacity += OpacityInterval; this.m_CurrentOpacity += OpacityInterval;
MethodInvoker mi = new MethodInvoker(UpdateFrmOpacity); MethodInvoker mi = new MethodInvoker(UpdateFrmOpacity);
this.BeginInvoke(mi); this.BeginInvoke(mi);
} }
...@@ -42,12 +35,9 @@ namespace GcDevicePc ...@@ -42,12 +35,9 @@ namespace GcDevicePc
{ {
//如果当前已经完全不透明,则停止timer //如果当前已经完全不透明,则停止timer
this.OpacityTimer.Stop(); this.OpacityTimer.Stop();
System.Timers.Timer t = new System.Timers.Timer(StayTime); //设置时间间隔为5秒 System.Timers.Timer t = new System.Timers.Timer(StayTime); //设置时间间隔为5秒
t.Elapsed += new System.Timers.ElapsedEventHandler(Timer_TimesUp); t.Elapsed += new System.Timers.ElapsedEventHandler(Timer_TimesUp);
t.AutoReset = false; //每到指定时间Elapsed事件是触发一次(false),还是一直触发(true) t.AutoReset = false; //每到指定时间Elapsed事件是触发一次(false),还是一直触发(true)
t.Start(); t.Start();
} }
} }
...@@ -56,9 +46,10 @@ namespace GcDevicePc ...@@ -56,9 +46,10 @@ namespace GcDevicePc
{ {
if (this.m_CurrentOpacity > 0) if (this.m_CurrentOpacity > 0)
{ {
t_preload.Join(); //拦截透明度下降请求
//如果当前的透明度>0,则降低透明度 //如果当前的透明度>0,则降低透明度
this.m_CurrentOpacity -= OpacityInterval; this.m_CurrentOpacity -= OpacityInterval;
MethodInvoker mi = new MethodInvoker(UpdateFrmOpacity); MethodInvoker mi = new MethodInvoker(UpdateFrmOpacity);
this.BeginInvoke(mi); this.BeginInvoke(mi);
} }
...@@ -87,17 +78,6 @@ namespace GcDevicePc ...@@ -87,17 +78,6 @@ namespace GcDevicePc
OpacityTimer.Interval = 30; OpacityTimer.Interval = 30;
OpacityTimer.Elapsed += new System.Timers.ElapsedEventHandler(OpacityTimerProcOpen); OpacityTimer.Elapsed += new System.Timers.ElapsedEventHandler(OpacityTimerProcOpen);
OpacityTimer.Start(); OpacityTimer.Start();
t_preload = new Thread(PreLoadingProc);
t_preload.IsBackground = true;
t_preload.Start();
}
private void PreLoadingProc()
{
//diagToolDevProxy.Instance.OpenDevice();
//AppCfg.Instance.Init();
//Frm_manager.Instance.Init();
} }
private void Timer_TimesUp(object sender, System.Timers.ElapsedEventArgs e) private void Timer_TimesUp(object sender, System.Timers.ElapsedEventArgs e)
...@@ -118,54 +98,33 @@ namespace GcDevicePc ...@@ -118,54 +98,33 @@ namespace GcDevicePc
m_mainform.Show(); m_mainform.Show();
} }
} }
/// <summary>
/// 窗口载入函数
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void StartForm_Load(object sender, EventArgs e) private void StartForm_Load(object sender, EventArgs e)
{ {
//if (mre != null) //载入时开启预载线程
// mre.Reset(); t_preload = new Thread(PreLoadingProc);
//addhmi = new Thread(searchhmi); t_preload.IsBackground = true;
//addhmi.IsBackground = true; t_preload.Start();
//addhmi.Start();
} }
//string ip; /// <summary>
//private void searchhmi() /// 预载操作
//{ /// </summary>
// ProThread.HMISearch mysearch = new ProThread.HMISearch(); private void PreLoadingProc()
// int hmicount = 0; {
globaldata.m_appinit.InitAppFolder();
// while (!mre.WaitOne(100)) globaldata.m_appinit.InitAppDefaultConfig();
// {
// mysearch.ThStart(); // globaldata.m_appinit.InitDB();
// Thread.Sleep(3000); // globaldata.m_appinit.InitAllGC();
// hmicount = mysearch.HMICount(); //globaldata.m_appinit.InitAllGCConfig();
//globaldata.m_appinit.InitGCThread();
// if (hmicount == 1) //globaldata.m_appinit.InitGCControl();
// { }
// mre.Set();
// break;
// }
// mysearch.ThStop();
// count++;
// if (count >= 10)
// {
// mre.Set();
// break;
// }
// }
// if (count < 10)
// {
// ip = (((globaldata.DeviceInfo)(mysearch.myHMIList[0])).IpAddr);
// globaldata.connection_ip = ip;
// mysearch.ThStop();
// }
// count = 0;
//}
} }
} }
...@@ -14,6 +14,8 @@ namespace GcDevicePc ...@@ -14,6 +14,8 @@ namespace GcDevicePc
{ {
private int searchsec = 0; private int searchsec = 0;
private int i = 0; private int i = 0;
public StartWin() public StartWin()
{ {
InitializeComponent(); InitializeComponent();
...@@ -22,9 +24,10 @@ namespace GcDevicePc ...@@ -22,9 +24,10 @@ namespace GcDevicePc
private void checkhmitimer_Tick(object sender, EventArgs e) private void checkhmitimer_Tick(object sender, EventArgs e)
{ {
searchsec++; searchsec++;
if(globaldata.StartNetwork) if(globaldata.StartNetwork)
{ {
if (globaldata.connection_ip != "" && globaldata.connection_ip != null ) if (!String.IsNullOrEmpty(globaldata.connection_ip))
{ {
this.Close(); this.Close();
} }
......
...@@ -286,7 +286,7 @@ namespace GcDevicePc ...@@ -286,7 +286,7 @@ namespace GcDevicePc
private void searchhmi() private void searchhmi()
{ {
ProThread.HMISearch mysearch = new ProThread.HMISearch(); ProThread.HMISearch mysearch = new ProThread.HMISearch(null);
int hmicount = 0 ; int hmicount = 0 ;
int i; int i;
mysearch.ThStart(); mysearch.ThStart();
......
...@@ -34,6 +34,8 @@ namespace GcDevicePc ...@@ -34,6 +34,8 @@ namespace GcDevicePc
public static int device_index =0; //总共探测出的设备数目 public static int device_index =0; //总共探测出的设备数目
public static int current_device; //当前使用的设备号 public static int current_device; //当前使用的设备号
public static AppInit m_appinit = new AppInit();
public const string remoteFolder = "\\Hard Disk2\\"; public const string remoteFolder = "\\Hard Disk2\\";
// public const string remoteFolder = "\\Storage Card\\"; // public const string remoteFolder = "\\Storage Card\\";
public const string exeremoteFolder = "\\Hard Disk\\"; public const string exeremoteFolder = "\\Hard Disk\\";
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="CircularProgressBar" version="2.5.6403.13419" targetFramework="net40" /> <package id="CircularProgressBar" version="2.5.6403.13419" targetFramework="net40" />
<package id="M2Mqtt" version="4.3.0.0" targetFramework="net45" requireReinstallation="True" /> <package id="ini.net" version="1.1.0" targetFramework="net45" />
<package id="log4net" version="2.0.8" targetFramework="net45" />
<package id="M2Mqtt" version="4.3.0.0" targetFramework="net45" />
<package id="WinFormAnimation" version="1.5.6298.3372" targetFramework="net40" /> <package id="WinFormAnimation" version="1.5.6298.3372" targetFramework="net40" />
</packages> </packages>
\ No newline at end of file
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