Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Thick-Common
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
潘栩锋
Thick-Common
Commits
549e2ec5
Commit
549e2ec5
authored
Mar 21, 2022
by
潘栩锋
🚴
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化 LCUS1 改为用定时器1s 写入一次状态。 就是LCUS1 模块有问题,多次写入应该能提高执行性。
parent
1a412bc1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
40 deletions
+53
-40
LCUS1_dependOn.cs
...Y.Thick.Base/FLY.Thick.Base.UI/DependOn/LCUS1_dependOn.cs
+1
-2
LCUS1.cs
Project.FLY.Thick.Base/FLY.Thick.Base.UI/LCUS1.cs
+50
-36
OnInitLcus1_Multi.cs
....Thick.Base/FLY.Thick.Base.UI/OnInit/OnInitLcus1_Multi.cs
+1
-1
OnInitLcus1_One.cs
...LY.Thick.Base/FLY.Thick.Base.UI/OnInit/OnInitLcus1_One.cs
+1
-1
No files found.
Project.FLY.Thick.Base/FLY.Thick.Base.UI/DependOn/LCUS1_dependOn.cs
View file @
549e2ec5
...
...
@@ -19,8 +19,7 @@ namespace FLY.Thick.Base.UI
this
.
paramDictionary
=
paramDictionary
;
//绑定 this.PortName 与 this.paramDictionary.LCUS1_PortName
this
.
paramDictionary
.
SetBinding
(
this
,
nameof
(
PortName
),
ParamDistItemKeys
.
LCUS1_PortName
,
"COM1"
);
Off
();
this
.
paramDictionary
.
SetBinding
(
this
,
nameof
(
Enable
),
ParamDistItemKeys
.
LCUS1_Enable
,
false
);
}
}
}
Project.FLY.Thick.Base/FLY.Thick.Base.UI/LCUS1.cs
View file @
549e2ec5
...
...
@@ -5,6 +5,7 @@ using System.IO.Ports;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.Windows.Threading
;
namespace
FLY.Thick.Base.UI
{
...
...
@@ -14,48 +15,61 @@ namespace FLY.Thick.Base.UI
public
string
ErrMsg
{
get
;
set
;
}
public
event
PropertyChangedEventHandler
PropertyChanged
;
DispatcherTimer
timer
;
public
void
On
()
public
bool
IsOn
{
get
;
set
;
}
private
bool
enable
;
public
bool
Enable
{
Task
.
Factory
.
StartNew
(()
=>
{
try
{
SerialPort
serial
=
new
SerialPort
();
serial
.
PortName
=
PortName
;
serial
.
BaudRate
=
9600
;
serial
.
Open
();
byte
[]
buf
=
new
byte
[]
{
0xa0
,
0x01
,
0x01
,
0xa2
};
serial
.
Write
(
buf
,
0
,
buf
.
Length
);
serial
.
Close
();
ErrMsg
=
$"
{
DateTime
.
Now
}
ON"
;
get
{
return
enable
;
}
set
{
if
(
enable
!=
value
)
{
enable
=
value
;
timer
.
IsEnabled
=
enable
;
}
catch
(
Exception
e
)
{
ErrMsg
=
e
.
Message
;
}
});
}
}
public
void
Off
()
public
LCUS1
()
{
timer
=
new
DispatcherTimer
();
timer
.
Interval
=
TimeSpan
.
FromSeconds
(
1
);
timer
.
Tick
+=
Timer_Tick
;
}
private
void
Timer_Tick
(
object
sender
,
EventArgs
e
)
{
Task
.
Factory
.
StartNew
(()
=>
//每1秒都写状态。 避免通讯不上
try
{
try
{
SerialPort
serial
=
new
SerialPort
();
serial
.
PortName
=
PortName
;
serial
.
BaudRate
=
9600
;
serial
.
Open
();
byte
[]
buf
=
new
byte
[]
{
0xa0
,
0x01
,
0x00
,
0xa1
};
serial
.
Write
(
buf
,
0
,
buf
.
Length
);
serial
.
Close
();
ErrMsg
=
$"
{
DateTime
.
Now
}
OFF"
;
}
catch
(
Exception
e
)
{
ErrMsg
=
e
.
Message
;
}
});
SerialPort
serial
=
new
SerialPort
();
serial
.
PortName
=
PortName
;
serial
.
BaudRate
=
9600
;
serial
.
Open
();
byte
[]
buf
;
if
(
IsOn
)
buf
=
new
byte
[]
{
0xa0
,
0x01
,
0x01
,
0xa2
};
else
buf
=
new
byte
[]
{
0xa0
,
0x01
,
0x00
,
0xa1
};
serial
.
Write
(
buf
,
0
,
buf
.
Length
);
serial
.
Close
();
string
msg
=
IsOn
?
"On"
:
"Off"
;
ErrMsg
=
$"
{
DateTime
.
Now
}
{
msg
}
"
;
}
catch
(
Exception
_e
)
{
ErrMsg
=
_e
.
Message
;
}
}
public
void
On
()
{
IsOn
=
true
;
}
public
void
Off
()
{
IsOn
=
false
;
}
}
}
Project.FLY.Thick.Base/FLY.Thick.Base.UI/OnInit/OnInitLcus1_Multi.cs
View file @
549e2ec5
...
...
@@ -37,7 +37,7 @@ namespace FLY.Thick.Base.UI.OnInit
{
if
(
e
.
PropertyName
==
nameof
(
warningSystemManager
.
IsRinging
))
{
if
(
this
.
paramDictionary
.
GetValue
(
ParamDistItemKeys
.
LCUS1_Enable
,
false
)
)
if
(
lcus1
.
Enable
)
{
if
(
warningSystemManager
.
IsRinging
)
lcus1
.
On
();
...
...
Project.FLY.Thick.Base/FLY.Thick.Base.UI/OnInit/OnInitLcus1_One.cs
View file @
549e2ec5
...
...
@@ -37,7 +37,7 @@ namespace FLY.Thick.Base.UI.OnInit
{
if
(
e
.
PropertyName
==
nameof
(
warningService
.
IsRinging
))
{
if
(
this
.
paramDictionary
.
GetValue
(
ParamDistItemKeys
.
LCUS1_Enable
,
false
)
)
if
(
lcus1
.
Enable
)
{
if
(
warningService
.
IsRinging
)
lcus1
.
On
();
...
...
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