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
d269da47
Commit
d269da47
authored
Mar 22, 2018
by
wangjunqiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
清理部分代码
parent
a4d691be
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
28 changed files
with
1495 additions
and
834 deletions
+1495
-834
App.config
GcDevicePc/App.config
+47
-3
AppInit.cs
GcDevicePc/AppInit.cs
+402
-0
GCModbus.cs
GcDevicePc/Common/GCModbus.cs
+19
-19
GCModbusSlave.cs
GcDevicePc/Common/GCModbusSlave.cs
+1
-3
GCModbusSlave485.cs
GcDevicePc/Common/GCModbusSlave485.cs
+138
-0
Log.cs
GcDevicePc/Common/Log.cs
+32
-0
RunTableHelper.cs
GcDevicePc/Common/RunTableHelper.cs
+199
-0
FormUser.Designer.cs
GcDevicePc/FormUser.Designer.cs
+1
-0
FormUser.cs
GcDevicePc/FormUser.cs
+8
-1
PCBuffer.cs
GcDevicePc/GCBuffer/PCBuffer.cs
+9
-3
GcDevicePc.csproj
GcDevicePc/GcDevicePc.csproj
+12
-3
MDIBase.Designer.cs
GcDevicePc/MDIBase.Designer.cs
+104
-104
MDIBase.cs
GcDevicePc/MDIBase.cs
+376
-469
MDIBase.resx
GcDevicePc/MDIBase.resx
+1
-1
MainBase.cs
GcDevicePc/MainBase.cs
+2
-6
DataRcv.cs
GcDevicePc/ProThread/DataRcv.cs
+1
-1
HMISearch.cs
GcDevicePc/ProThread/HMISearch.cs
+54
-37
Program.cs
GcDevicePc/Program.cs
+45
-107
AssemblyInfo.cs
GcDevicePc/Properties/AssemblyInfo.cs
+1
-0
Resources.Designer.cs
GcDevicePc/Properties/Resources.Designer.cs
+1
-1
Settings.Designer.cs
GcDevicePc/Properties/Settings.Designer.cs
+1
-1
SaveCfg.cs
GcDevicePc/SaveCfg.cs
+2
-2
SendConfig.cs
GcDevicePc/SendConfig.cs
+2
-2
StartForm.cs
GcDevicePc/StartForm.cs
+27
-68
StartWin.cs
GcDevicePc/StartWin.cs
+4
-1
auxtool.cs
GcDevicePc/auxtool.cs
+1
-1
globaldata.cs
GcDevicePc/globaldata.cs
+2
-0
packages.config
GcDevicePc/packages.config
+3
-1
No files found.
GcDevicePc/App.config
View file @
d269da47
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
configuration
>
<
startup
>
<
supportedRuntime
version
=
"v4.0"
sku
=
".NETFramework,Version=v4.0"
/></
startup
>
<
configSections
>
<
section
name
=
"log4net"
type
=
"log4net.Config.Log4NetConfigurationSectionHandler, log4net"
/>
</
configSections
>
<
startup
>
<
supportedRuntime
version
=
"v4.0"
sku
=
".NETFramework,Version=v4.5"
/>
</
startup
>
<
runtime
>
<
legacyUnhandledExceptionPolicy
enabled
=
"true"
/>
</
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
>
GcDevicePc/AppInit.cs
0 → 100644
View file @
d269da47
This diff is collapsed.
Click to expand it.
GcDevicePc/Common/GCModbus.cs
View file @
d269da47
...
...
@@ -12,27 +12,27 @@ namespace GcDevicePc.Common
[
DllImport
(
@"LibModbus.dll"
,
EntryPoint
=
"fnLibModbus"
,
CharSet
=
CharSet
.
Unicode
)]
public
static
extern
uint
fnLibModbus
();
[
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"
)]
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"
)]
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"
)]
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"
)]
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"
)]
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"
)]
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"
)]
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"
)]
public
static
extern
int
fnReportSlaveID
(
uint
handle
,
[
MarshalAs
(
UnmanagedType
.
LPArray
,
SizeParamIndex
=
1
)]
System
.
Char
[]
src
,
byte
[]
Ip
,
ushort
wTcpPort
);
[
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"
)]
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"
)]
public
static
extern
void
fnLibModbusClose
(
uint
handle
);
...
...
@@ -53,7 +53,7 @@ namespace GcDevicePc.Common
{
int
ret
;
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
;
}
...
...
@@ -61,7 +61,7 @@ namespace GcDevicePc.Common
{
int
ret
;
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
;
}
...
...
@@ -69,7 +69,7 @@ namespace GcDevicePc.Common
{
int
ret
;
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
;
}
...
...
@@ -77,7 +77,7 @@ namespace GcDevicePc.Common
{
int
ret
;
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
];
return
ret
;
}
...
...
@@ -86,7 +86,7 @@ namespace GcDevicePc.Common
{
int
ret
=
0
;
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
;
}
...
...
@@ -94,7 +94,7 @@ namespace GcDevicePc.Common
{
int
ret
=
0
;
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
;
}
...
...
@@ -102,7 +102,7 @@ namespace GcDevicePc.Common
{
int
ret
;
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
;
}
...
...
@@ -118,7 +118,7 @@ namespace GcDevicePc.Common
{
int
ret
=
0
;
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
;
}
...
...
@@ -126,7 +126,7 @@ namespace GcDevicePc.Common
{
int
ret
=
0
;
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
;
}
...
...
GcDevicePc/Common/GCModbusSlave.cs
View file @
d269da47
...
...
@@ -105,8 +105,6 @@ namespace GcDevicePc.Common
value
=
s
[(
address
-
baseaddress
)%
2
];
}
catch
{
}
finally
{
}
//}
}
...
...
@@ -137,7 +135,7 @@ namespace GcDevicePc.Common
break
;
case
8
:
//HMI状态
{
value
=
(
ushort
)(
globaldata
.
m_hmibuffer
.
gcinfo
.
methodstatus
)
;
value
=
globaldata
.
m_hmibuffer
.
gcinfo
.
methodstatus
;
}
break
;
case
9
:
//前进样口
...
...
GcDevicePc/Common/GCModbusSlave485.cs
0 → 100644
View file @
d269da47
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());
}
}
}
GcDevicePc/Common/Log.cs
0 → 100644
View file @
d269da47
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
);
}
}
}
GcDevicePc/Common/RunTableHelper.cs
0 → 100644
View file @
d269da47
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
);
}
}
}
GcDevicePc/FormUser.Designer.cs
View file @
d269da47
...
...
@@ -89,6 +89,7 @@
this
.
Activated
+=
new
System
.
EventHandler
(
this
.
FormUser_Activated
);
this
.
Deactivate
+=
new
System
.
EventHandler
(
this
.
FormUser_Deactivate
);
this
.
Load
+=
new
System
.
EventHandler
(
this
.
FormUser_Load
);
this
.
Resize
+=
new
System
.
EventHandler
(
this
.
FormUser_Resize
);
this
.
ResumeLayout
(
false
);
}
...
...
GcDevicePc/FormUser.cs
View file @
d269da47
...
...
@@ -34,12 +34,19 @@ namespace GcDevicePc
// MessageBox.Show("停用");
// Console.WriteLine("停用");
}
public
event
Fireport
autofire
;
private
void
buttonFID_Click
(
object
sender
,
EventArgs
e
)
{
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
);
}
}
}
GcDevicePc/GCBuffer/PCBuffer.cs
View file @
d269da47
...
...
@@ -12,9 +12,12 @@ namespace GcDevicePc.GCBuffer
public
string
DataFolder
;
//数据保存目录
public
string
RunFolder
;
//当前程序运行目录
public
string
MethodFolder
;
//当前方法目录
public
string
StatusFolder
;
//当前
状态
目录
public
string
subStatusFolder
;
//当前状态
目录
public
string
StatusFolder
;
//当前
配置
目录
public
string
SubStatusFolder
;
//当前配置子
目录
public
string
RunTabFolder
;
//当前运行表目录
public
string
FwFolder
;
//固件更新目录
public
string
TmpFolder
;
//TMPFile目录
public
string
LogFolder
;
//Log目录
}
public
struct
GCFileInfo
...
...
@@ -58,8 +61,11 @@ namespace GcDevicePc.GCBuffer
gcpcinfo
.
pcfolderinfo
.
RunFolder
=
null
;
gcpcinfo
.
pcfolderinfo
.
MethodFolder
=
null
;
gcpcinfo
.
pcfolderinfo
.
StatusFolder
=
null
;
gcpcinfo
.
pcfolderinfo
.
s
ubStatusFolder
=
null
;
gcpcinfo
.
pcfolderinfo
.
S
ubStatusFolder
=
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_OpenMethodName
=
null
;
...
...
GcDevicePc/GcDevicePc.csproj
View file @
d269da47
...
...
@@ -9,7 +9,7 @@
<AppDesignerFolder>
Properties
</AppDesignerFolder>
<RootNamespace>
GcDevicePc
</RootNamespace>
<AssemblyName>
GcDevicePc
</AssemblyName>
<TargetFrameworkVersion>
v4.
0
</TargetFrameworkVersion>
<TargetFrameworkVersion>
v4.
5
</TargetFrameworkVersion>
<FileAlignment>
512
</FileAlignment>
<IsWebBootstrapper>
false
</IsWebBootstrapper>
<TargetFrameworkProfile>
...
...
@@ -67,7 +67,7 @@
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)' == 'Debug|x86'"
>
<DebugSymbols>
true
</DebugSymbols>
<OutputPath>
bin\
x86\
Debug\
</OutputPath>
<OutputPath>
bin\Debug\
</OutputPath>
<DefineConstants>
DEBUG;TRACE
</DefineConstants>
<AllowUnsafeBlocks>
true
</AllowUnsafeBlocks>
<DebugType>
full
</DebugType>
...
...
@@ -99,6 +99,12 @@
<Reference
Include=
"CKVocAnalyzer"
>
<HintPath>
..\dll\CKVocAnalyzer.dll
</HintPath>
</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"
>
<HintPath>
..\dll\LogOperate.dll
</HintPath>
</Reference>
...
...
@@ -138,6 +144,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"AppInit.cs"
/>
<Compile
Include=
"auxtool.cs"
>
<SubType>
Form
</SubType>
</Compile>
...
...
@@ -183,7 +190,9 @@
<Compile
Include=
"Common\GCModbus.cs"
/>
<Compile
Include=
"Common\GCModbusSlave.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=
"ConfigDlg\ChromeDlg.cs"
>
<SubType>
Form
</SubType>
...
...
GcDevicePc/MDIBase.Designer.cs
View file @
d269da47
This diff is collapsed.
Click to expand it.
GcDevicePc/MDIBase.cs
View file @
d269da47
This diff is collapsed.
Click to expand it.
GcDevicePc/MDIBase.resx
View file @
d269da47
...
...
@@ -136,6 +136,6 @@
<value>
601, 17
</value>
</metadata>
<metadata
name=
"$this.TrayHeight"
type=
"System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
>
<value>
175
</value>
<value>
86
</value>
</metadata>
</root>
\ No newline at end of file
GcDevicePc/MainBase.cs
View file @
d269da47
...
...
@@ -149,7 +149,7 @@ namespace GcDevicePc
//MainBase初始化
InitializeComponent
();
//运行环境初始化
MainBase_InitAppConfig
();
//
MainBase_InitAppConfig();
//标题初始化
ManinBase_InitFormTitle
();
//菜单初始化
...
...
@@ -735,11 +735,6 @@ namespace GcDevicePc
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
);
...
...
@@ -755,6 +750,7 @@ namespace GcDevicePc
{
System
.
IO
.
Directory
.
CreateDirectory
(
globaldata
.
m_pcbuffer
.
gcpcinfo
.
pcfolderinfo
.
RunTabFolder
);
}
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
);
...
...
GcDevicePc/ProThread/DataRcv.cs
View file @
d269da47
...
...
@@ -38,7 +38,7 @@ namespace GcDevicePc.ProThread
{
try
{
if
(
globaldata
.
connection_ip
!=
null
&&
globaldata
.
connection_ip
!=
""
)
if
(
!
String
.
IsNullOrEmpty
(
globaldata
.
connection_ip
)
)
socket
.
Connect
(
globaldata
.
connection_ip
,
8005
);
//配置服务器IP与端口
Console
.
WriteLine
(
"连接服务器成功"
);
break
;
...
...
GcDevicePc/ProThread/HMISearch.cs
View file @
d269da47
...
...
@@ -9,91 +9,109 @@ using System.Text.RegularExpressions;
using
System.Collections
;
using
System.Management
;
using
System.Net.NetworkInformation
;
using
GcDevicePc.Common
;
namespace
GcDevicePc.ProThread
{
class
HMISearch
{
p
ublic
UdpClient
client
;
p
ublic
IPEndPoint
endpoint
;
p
rivate
UdpClient
client
;
p
rivate
IPEndPoint
endpoint
;
Thread
searchth
;
ManualResetEvent
mre
=
new
ManualResetEvent
(
false
);
public
globaldata
.
DeviceInfo
m_DeviceInfo
;
public
ArrayList
myHMIList
=
new
ArrayList
();
string
FMAC
=
null
;
string
file
=
System
.
Windows
.
Forms
.
Application
.
StartupPath
+
"\\startup.ini"
;
string
localip
=
null
;
private
string
FMAC
=
null
;
private
string
_
localip
=
null
;
/// <summary>
/// 构造函数
/// </summary>
public
HMISearch
()
public
HMISearch
(
String
hmimac
)
{
// globaldata.hHMIList.Clear()
;
this
.
FMAC
=
hmimac
;
myHMIList
.
Clear
();
globaldata
.
DeviceList
.
Clear
();
GetHmiIp
();
}
INIOperation
test
=
new
INIOperation
(
file
);
this
.
FMAC
=
test
.
INIGetStringValue
(
"NetWorkConfig"
,
"MAC地址"
,
null
);
public
void
ReGetHmiIp
()
{
GetHmiIp
();
}
NetworkInterface
[]
nics
=
NetworkInterface
.
GetAllNetworkInterfaces
();
foreach
(
NetworkInterface
adapter
in
nics
)
private
void
GetHmiIp
()
{
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
(
Pd1
)
if
(
adapter
.
Name
==
"本地连接"
)
{
bool
pd1
=
(
adapter
.
NetworkInterfaceType
==
NetworkInterfaceType
.
Ethernet
);
//判断是否是以太网连接
if
(
pd1
)
{
IPInterfaceProperties
ip
=
adapter
.
GetIPProperties
();
//IP配置信息
UnicastIPAddressInformationCollection
ipCollection
=
ip
.
UnicastAddresses
;
foreach
(
UnicastIPAddressInformation
ipadd
in
ipCollection
)
{
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
)
mre
.
Reset
();
Console
.
WriteLine
(
"搜索线程开始...."
);
searchth
=
new
Thread
(
ThreadMethod
);
searchth
.
IsBackground
=
true
;
searchth
.
Start
();
if
(
String
.
IsNullOrEmpty
(
this
.
_localip
))
{
return
false
;
}
else
{
if
(
mre
!=
null
)
mre
.
Reset
();
Log
.
Info
(
"Start Search HMI..."
);
searchth
=
new
Thread
(
ThreadMethod
);
searchth
.
IsBackground
=
true
;
searchth
.
Start
();
return
true
;
}
}
public
void
ThStop
()
{
Console
.
WriteLine
(
"搜索线程结束.
..."
);
Log
.
Info
(
"Stop Search HMI
..."
);
mre
.
Set
();
// FMAC = null;
}
public
int
HMICount
()
{
//return globaldata.hHMIList.Count;
return
myHMIList
.
Count
;
}
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
,
0x02
,
0x00
,
0x00
,
0x55
,
0xAA
};
//脱机
byte
[]
sendBytes
=
new
byte
[]
{
0x57
,
0x54
,
0x04
,
0x00
,
0x00
,
0x00
,
0x03
,
0x02
,
0x00
,
0x00
,
0x55
,
0xAA
};
int
iReadBytes
=
0
;
try
{
//
client = new UdpClient(new IPEndPoint(IPAddress.Any, 0));
client
=
new
UdpClient
(
new
IPEndPoint
(
IPAddress
.
Parse
(
this
.
localip
),
0
));
client
=
new
UdpClient
(
new
IPEndPoint
(
IPAddress
.
Any
,
0
));
// client = new UdpClient(new IPEndPoint(IPAddress.Parse(this._
localip), 0));
endpoint
=
new
IPEndPoint
(
IPAddress
.
Parse
(
"255.255.255.255"
),
233
);
client
.
Send
(
sendBytes
,
sendBytes
.
Length
,
endpoint
);
Thread
.
Sleep
(
500
);
...
...
@@ -112,14 +130,13 @@ namespace GcDevicePc.ProThread
DoRecvDataCallBack
(
recvBytes
,
iReadBytes
);
}
}
}
catch
}
catch
(
Exception
e
)
{
}
Console
.
WriteLine
(
e
.
Message
);
}
}
p
ublic
Boolean
DoRecvDataCallBack
(
byte
[]
pcData
,
int
iRecvLength
)
p
rivate
Boolean
DoRecvDataCallBack
(
byte
[]
pcData
,
int
iRecvLength
)
{
int
i
;
int
count
=
0
;
...
...
@@ -138,7 +155,7 @@ namespace GcDevicePc.ProThread
if
((
iDataLength
>=
4
)
&&
(
iRecvLength
==
8
+
iDataLength
))
{
System
.
Text
.
ASCIIEncoding
asciiEncoding
=
new
System
.
Text
.
ASCIIEncoding
();
ASCIIEncoding
asciiEncoding
=
new
ASCIIEncoding
();
m_DeviceInfo
.
bActive
=
false
;
for
(
i
=
0
;
i
<
100
;
i
++
)
...
...
GcDevicePc/Program.cs
View file @
d269da47
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading
;
using
System.Windows.Forms
;
using
System.Net.NetworkInformation
;
using
System.Net.Sockets
;
using
GcDevicePc.Common
;
using
GcDevicePc.ProThread
;
namespace
GcDevicePc
{
static
class
Program
{
/// <summary>
/// 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
()
private
static
void
Isnetworkok
()
{
string
localip
=
""
;
String
localip
=
""
;
while
(
true
)
{
try
...
...
@@ -67,8 +23,8 @@ namespace GcDevicePc
{
if
(
adapter
.
Name
==
"本地连接"
)
{
bool
Pd1
=
(
adapter
.
NetworkInterfaceType
==
NetworkInterfaceType
.
Ethernet
);
//判断是否是以太网连接
if
(
P
d1
)
bool
pd1
=
(
adapter
.
NetworkInterfaceType
==
NetworkInterfaceType
.
Ethernet
);
if
(
p
d1
)
{
IPInterfaceProperties
ip
=
adapter
.
GetIPProperties
();
UnicastIPAddressInformationCollection
ipCollection
=
ip
.
UnicastAddresses
;
...
...
@@ -85,11 +41,10 @@ namespace GcDevicePc
}
}
}
}
finally
catch
(
Exception
e
)
{
Log
.
Error
(
e
.
Message
);
}
if
(
globaldata
.
OffLinkMode
||
globaldata
.
StartNetwork
)
...
...
@@ -103,23 +58,23 @@ namespace GcDevicePc
static
public
bool
Ping
(
string
ip
)
{
System
.
Net
.
NetworkInformation
.
Ping
p
;
System
.
Net
.
NetworkInformation
.
PingOptions
options
;
System
.
Net
.
NetworkInformation
.
PingReply
reply
;
Ping
p
;
PingOptions
options
;
PingReply
reply
;
string
data
;
int
timeout
;
try
{
p
=
new
System
.
Net
.
NetworkInformation
.
Ping
();
options
=
new
System
.
Net
.
NetworkInformation
.
PingOptions
();
p
=
new
Ping
();
options
=
new
PingOptions
();
options
.
DontFragment
=
true
;
data
=
"Test Data!"
;
byte
[]
buffer
=
System
.
Text
.
Encoding
.
ASCII
.
GetBytes
(
data
);
timeout
=
1000
;
// Timeout 时间,单位:毫秒
reply
=
p
.
Send
(
ip
,
timeout
,
buffer
,
options
);
if
(
reply
.
Status
==
System
.
Net
.
NetworkInformation
.
IPStatus
.
Success
)
if
(
reply
.
Status
==
IPStatus
.
Success
)
{
globaldata
.
StartNetwork
=
true
;
return
true
;
...
...
@@ -136,25 +91,35 @@ namespace GcDevicePc
}
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
;
bool
ret
=
false
;
while
(
true
)
{
mysearch
.
ThStart
();
Thread
.
Sleep
(
3000
);
hmicount
=
mysearch
.
HMICount
();
ret
=
mysearch
.
ThStart
();
if
(
hmicount
>=
1
)
if
(
ret
)
{
ip
=
(((
globaldata
.
DeviceInfo
)(
mysearch
.
myHMIList
[
0
])).
IpAddr
);
globaldata
.
connection_ip
=
ip
;
break
;
}
mysearch
.
ThStop
();
Thread
.
Sleep
(
3000
);
hmicount
=
mysearch
.
HMICount
();
if
(
hmicount
>=
1
)
{
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
)
{
globaldata
.
connection_ip
=
""
;
...
...
@@ -162,16 +127,10 @@ namespace GcDevicePc
}
}
}
static
private
System
.
Windows
.
Forms
.
DialogResult
ShowStart
()
private
static
void
RunStartWin
()
{
return
new
StartWin
().
ShowDialog
();
}
static
private
void
runStartWin
()
{
DialogResult
dr
;
dr
=
ShowStart
();
DialogResult
dr
=
new
StartWin
().
ShowDialog
();
}
[
STAThread
]
...
...
@@ -180,36 +139,16 @@ namespace GcDevicePc
Application
.
EnableVisualStyles
();
Application
.
SetCompatibleTextRenderingDefault
(
false
);
//bool pingok = false;
bool
createNew
;
//string ipgw = "";
Thread
t_StartWin
;
t_StartWin
=
new
Thread
(
runStartWin
);
t_StartWin
.
IsBackground
=
true
;
t_StartWin
.
Start
();
//while (true)
//{
// ipgw = GetGW();
// pingok = Ping(ipgw);
// if (pingok)
// {
// break;
// }
Thread
tStartWin
=
new
Thread
(
RunStartWin
)
{
IsBackground
=
true
};
tStartWin
.
Start
();
// if(globaldata.OffLinkMode)
// {
// break;
// }
// Thread.Sleep(1000);
//}
isnetworkok
();
Isnetworkok
();
CheckHmi
();
{
using
(
System
.
Threading
.
Mutex
mutex
=
new
System
.
Threading
.
Mutex
(
true
,
Application
.
ProductName
,
out
createNew
))
{
...
...
@@ -220,7 +159,6 @@ namespace GcDevicePc
else
{
MessageBox
.
Show
(
"应用程序已经在运行中..."
);
System
.
Threading
.
Thread
.
Sleep
(
1000
);
System
.
Environment
.
Exit
(
1
);
}
...
...
GcDevicePc/Properties/AssemblyInfo.cs
View file @
d269da47
...
...
@@ -34,3 +34,4 @@ using System.Runtime.InteropServices;
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.1")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
\ No newline at end of file
GcDevicePc/Properties/Resources.Designer.cs
View file @
d269da47
...
...
@@ -19,7 +19,7 @@ namespace GcDevicePc.Properties {
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /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
.
Runtime
.
CompilerServices
.
CompilerGeneratedAttribute
()]
internal
class
Resources
{
...
...
GcDevicePc/Properties/Settings.Designer.cs
View file @
d269da47
...
...
@@ -12,7 +12,7 @@ namespace GcDevicePc.Properties {
[
global
::
System
.
Runtime
.
CompilerServices
.
CompilerGeneratedAttribute
()]
[
global
::
System
.
CodeDom
.
Compiler
.
GeneratedCodeAttribute
(
"Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator"
,
"1
2.0
.0.0"
)]
[
global
::
System
.
CodeDom
.
Compiler
.
GeneratedCodeAttribute
(
"Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator"
,
"1
5.6
.0.0"
)]
internal
sealed
partial
class
Settings
:
global
::
System
.
Configuration
.
ApplicationSettingsBase
{
private
static
Settings
defaultInstance
=
((
Settings
)(
global
::
System
.
Configuration
.
ApplicationSettingsBase
.
Synchronized
(
new
Settings
())));
...
...
GcDevicePc/SaveCfg.cs
View file @
d269da47
...
...
@@ -28,7 +28,7 @@ namespace GcDevicePc
bool
VerifyName
()
{
string
strtmp
;
DirectoryInfo
MethodDir
=
new
DirectoryInfo
(
globaldata
.
m_pcbuffer
.
gcpcinfo
.
pcfolderinfo
.
s
ubStatusFolder
);
DirectoryInfo
MethodDir
=
new
DirectoryInfo
(
globaldata
.
m_pcbuffer
.
gcpcinfo
.
pcfolderinfo
.
S
ubStatusFolder
);
foreach
(
FileInfo
file
in
MethodDir
.
GetFiles
(
"*.ini"
))
{
strtmp
=
this
.
newcfgname
.
Text
+
".ini"
;
...
...
@@ -64,7 +64,7 @@ namespace GcDevicePc
private
void
okbutton_Click
(
object
sender
,
EventArgs
e
)
{
string
filename
=
this
.
newcfgname
.
Text
+
".ini"
;
filename
=
System
.
IO
.
Path
.
Combine
(
globaldata
.
m_pcbuffer
.
gcpcinfo
.
pcfolderinfo
.
s
ubStatusFolder
,
filename
);
filename
=
System
.
IO
.
Path
.
Combine
(
globaldata
.
m_pcbuffer
.
gcpcinfo
.
pcfolderinfo
.
S
ubStatusFolder
,
filename
);
SaveInI
(
filename
);
this
.
Close
();
}
...
...
GcDevicePc/SendConfig.cs
View file @
d269da47
...
...
@@ -25,7 +25,7 @@ namespace GcDevicePc
private
void
SendConfig_Load
(
object
sender
,
EventArgs
e
)
{
DirectoryInfo
subStatusDir
=
new
DirectoryInfo
(
globaldata
.
m_pcbuffer
.
gcpcinfo
.
pcfolderinfo
.
s
ubStatusFolder
);
DirectoryInfo
subStatusDir
=
new
DirectoryInfo
(
globaldata
.
m_pcbuffer
.
gcpcinfo
.
pcfolderinfo
.
S
ubStatusFolder
);
localStatusList
.
Items
.
Clear
();
foreach
(
FileInfo
file
in
subStatusDir
.
GetFiles
(
"*.ini"
))
...
...
@@ -102,7 +102,7 @@ namespace GcDevicePc
if
(
localStatusList
.
GetItemChecked
(
i
))
{
checkfilename
=
localStatusList
.
GetItemText
(
localStatusList
.
Items
[
i
]);
sendfilename
=
System
.
IO
.
Path
.
Combine
(
globaldata
.
m_pcbuffer
.
gcpcinfo
.
pcfolderinfo
.
s
ubStatusFolder
,
checkfilename
);
sendfilename
=
System
.
IO
.
Path
.
Combine
(
globaldata
.
m_pcbuffer
.
gcpcinfo
.
pcfolderinfo
.
S
ubStatusFolder
,
checkfilename
);
}
}
...
...
GcDevicePc/StartForm.cs
View file @
d269da47
...
...
@@ -17,14 +17,9 @@ namespace GcDevicePc
private
const
double
OpacityInterval
=
0.02
;
//0.02
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
;
private
void
OpacityTimerProcOpen
(
object
sender
,
System
.
Timers
.
ElapsedEventArgs
e
)
...
...
@@ -32,9 +27,7 @@ namespace GcDevicePc
if
(
this
.
m_CurrentOpacity
<
1
)
{
////如果当前的透明度小于1,则继续增加透明度
this
.
m_CurrentOpacity
+=
OpacityInterval
;
MethodInvoker
mi
=
new
MethodInvoker
(
UpdateFrmOpacity
);
this
.
BeginInvoke
(
mi
);
}
...
...
@@ -42,12 +35,9 @@ namespace GcDevicePc
{
//如果当前已经完全不透明,则停止timer
this
.
OpacityTimer
.
Stop
();
System
.
Timers
.
Timer
t
=
new
System
.
Timers
.
Timer
(
StayTime
);
//设置时间间隔为5秒
t
.
Elapsed
+=
new
System
.
Timers
.
ElapsedEventHandler
(
Timer_TimesUp
);
t
.
AutoReset
=
false
;
//每到指定时间Elapsed事件是触发一次(false),还是一直触发(true)
t
.
Start
();
}
}
...
...
@@ -56,9 +46,10 @@ namespace GcDevicePc
{
if
(
this
.
m_CurrentOpacity
>
0
)
{
t_preload
.
Join
();
//拦截透明度下降请求
//如果当前的透明度>0,则降低透明度
this
.
m_CurrentOpacity
-=
OpacityInterval
;
MethodInvoker
mi
=
new
MethodInvoker
(
UpdateFrmOpacity
);
this
.
BeginInvoke
(
mi
);
}
...
...
@@ -87,17 +78,6 @@ namespace GcDevicePc
OpacityTimer
.
Interval
=
30
;
OpacityTimer
.
Elapsed
+=
new
System
.
Timers
.
ElapsedEventHandler
(
OpacityTimerProcOpen
);
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
)
...
...
@@ -118,54 +98,33 @@ namespace GcDevicePc
m_mainform
.
Show
();
}
}
/// <summary>
/// 窗口载入函数
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
void
StartForm_Load
(
object
sender
,
EventArgs
e
)
{
//if (mre != null)
// mre.Reset();
//addhmi = new Thread(searchhmi);
//addhmi.IsBackground = true;
//addhmi.Start();
//载入时开启预载线程
t_preload
=
new
Thread
(
PreLoadingProc
);
t_preload
.
IsBackground
=
true
;
t_preload
.
Start
();
}
//string ip;
//private void searchhmi()
//{
// ProThread.HMISearch mysearch = new ProThread.HMISearch();
// int hmicount = 0;
// while (!mre.WaitOne(100))
// {
// mysearch.ThStart();
// Thread.Sleep(3000);
// hmicount = mysearch.HMICount();
// if (hmicount == 1)
// {
// 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;
//}
/// <summary>
/// 预载操作
/// </summary>
private
void
PreLoadingProc
()
{
globaldata
.
m_appinit
.
InitAppFolder
();
globaldata
.
m_appinit
.
InitAppDefaultConfig
();
// globaldata.m_appinit.InitDB();
// globaldata.m_appinit.InitAllGC();
//globaldata.m_appinit.InitAllGCConfig();
//globaldata.m_appinit.InitGCThread();
//globaldata.m_appinit.InitGCControl();
}
}
}
GcDevicePc/StartWin.cs
View file @
d269da47
...
...
@@ -14,6 +14,8 @@ namespace GcDevicePc
{
private
int
searchsec
=
0
;
private
int
i
=
0
;
public
StartWin
()
{
InitializeComponent
();
...
...
@@ -22,9 +24,10 @@ namespace GcDevicePc
private
void
checkhmitimer_Tick
(
object
sender
,
EventArgs
e
)
{
searchsec
++;
if
(
globaldata
.
StartNetwork
)
{
if
(
globaldata
.
connection_ip
!=
""
&&
globaldata
.
connection_ip
!=
null
)
if
(
!
String
.
IsNullOrEmpty
(
globaldata
.
connection_ip
)
)
{
this
.
Close
();
}
...
...
GcDevicePc/auxtool.cs
View file @
d269da47
...
...
@@ -286,7 +286,7 @@ namespace GcDevicePc
private
void
searchhmi
()
{
ProThread
.
HMISearch
mysearch
=
new
ProThread
.
HMISearch
();
ProThread
.
HMISearch
mysearch
=
new
ProThread
.
HMISearch
(
null
);
int
hmicount
=
0
;
int
i
;
mysearch
.
ThStart
();
...
...
GcDevicePc/globaldata.cs
View file @
d269da47
...
...
@@ -34,6 +34,8 @@ namespace GcDevicePc
public
static
int
device_index
=
0
;
//总共探测出的设备数目
public
static
int
current_device
;
//当前使用的设备号
public
static
AppInit
m_appinit
=
new
AppInit
();
public
const
string
remoteFolder
=
"\\Hard Disk2\\"
;
// public const string remoteFolder = "\\Storage Card\\";
public
const
string
exeremoteFolder
=
"\\Hard Disk\\"
;
...
...
GcDevicePc/packages.config
View file @
d269da47
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
packages
>
<
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"
/>
</
packages
>
\ No newline at end of file
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