Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Cfet2NewVacuum
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
JiangYixing
Cfet2NewVacuum
Commits
299e1672
Commit
299e1672
authored
May 13, 2021
by
JiangYixing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
e8c4b816
Pipeline
#118
canceled with stages
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
124 additions
and
0 deletions
+124
-0
Vacuum.cs
Vacuum.cs
+124
-0
No files found.
Vacuum.cs
0 → 100644
View file @
299e1672
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
using
System.IO.Ports
;
using
Newtonsoft.Json
;
using
System.IO
;
using
Jtext103.CFET2.Core
;
using
Jtext103.CFET2.Core.Attributes
;
using
Jtext103.CFET2.Core.Log
;
using
Jtext103.CFET2.Core.Event
;
using
HslCommunication.Serial
;
using
System.Threading
;
using
System.Threading.Tasks
;
namespace
Cfet2Vacuun
{
public
class
Vacuum
:
Thing
{
public
ComConfig
comconfig
{
get
;
set
;
}
public
SerialPort
port
{
get
;
set
;
}
public
uint
PresureValue
;
//压强数值4
public
uint
NegetiveExpValue
;
//压强负指数值
public
double
RealPressureValue
;
public
bool
PortRunningNormal
=
false
;
public
Thread
QueryThread
;
[
Cfet2Status
]
public
uint
GetPresureValue
()
{
return
PresureValue
;
}
[
Cfet2Status
]
public
uint
GetNegetiveExpValue
()
{
return
NegetiveExpValue
;
}
public
override
void
TryInit
(
object
path
)
{
comconfig
=
new
ComConfig
(
getConfigFilePath
((
string
)
path
));
}
public
override
void
Start
()
{
InitSerialPort
();
PortRunningNormal
=
true
;
QueryThread
=
new
Thread
(
RollPollingQuery
);
QueryThread
.
Start
();
}
public
void
RollPollingQuery
()
{
while
(
true
)
{
try
{
Thread
.
Sleep
(
2000
);
Query
();
PortRunningNormal
=
true
;
}
catch
(
Exception
e
)
//如果报错了
{
PortRunningNormal
=
false
;
continue
;
}
}
}
public
void
InitSerialPort
()
{
port
=
new
SerialPort
(
comconfig
.
com
)
{
BaudRate
=
comconfig
.
baudrate
,
Parity
=
comconfig
.
parity
,
StopBits
=
comconfig
.
stopbits
,
DataBits
=
comconfig
.
databits
,
Handshake
=
comconfig
.
handshake
,
//不加这个有些带串口的板子用不了,但是有时候加了下面这一句又可能导致一些神秘的问题。
RtsEnable
=
true
};
port
.
DataReceived
+=
new
SerialDataReceivedEventHandler
(
DataReceived
);
port
.
Open
();
}
public
void
DataReceived
(
object
sender
,
SerialDataReceivedEventArgs
e
)
{
int
n
=
port
.
BytesToRead
;
byte
[]
RecData
=
new
byte
[
n
];
port
.
Read
(
RecData
,
0
,
n
);
double
newvalue
;
if
(
SoftCRC16
.
CheckCRC16
(
RecData
))
{
PresureValue
=
(
uint
)(
RecData
[
3
]
*
256
+
RecData
[
4
]);
NegetiveExpValue
=
(
uint
)(
RecData
[
5
]
*
256
+
RecData
[
6
]);
newvalue
=
(
PresureValue
/
10
)
*
Math
.
Pow
(
10
,
-
NegetiveExpValue
);
if
(
newvalue
!=
RealPressureValue
)
{
VacuumChangedPayload
payload
=
new
VacuumChangedPayload
();
payload
.
NewValue
=
newvalue
;
//产生一个事件,表示真空值发生了改变
MyHub
.
EventHub
.
Publish
(
Path
,
"VacuumChanged"
,
payload
);
}
RealPressureValue
=
newvalue
;
}
}
[
Cfet2Method
]
public
void
Query
()
{
byte
[]
QueryCmd
=
new
byte
[]
{
0x07
,
0x04
,
0x00
,
0x00
,
0x00
,
0x02
};
byte
[]
QueryCmdAddCRC
=
SoftCRC16
.
CRC16
(
QueryCmd
);
port
.
Write
(
QueryCmdAddCRC
,
0
,
QueryCmdAddCRC
.
Length
);
}
[
Cfet2Status
]
public
double
VaccuumValue
()
{
return
RealPressureValue
;
}
[
Cfet2Status
]
public
bool
PortState
()
{
return
PortRunningNormal
;
}
}
}
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