Compare commits
No commits in common. "master" and "main" have entirely different histories.
63
.gitattributes
vendored
63
.gitattributes
vendored
@ -1,63 +0,0 @@
|
||||
###############################################################################
|
||||
# Set default behavior to automatically normalize line endings.
|
||||
###############################################################################
|
||||
* text=auto
|
||||
|
||||
###############################################################################
|
||||
# Set default behavior for command prompt diff.
|
||||
#
|
||||
# This is need for earlier builds of msysgit that does not have it on by
|
||||
# default for csharp files.
|
||||
# Note: This is only used by command line
|
||||
###############################################################################
|
||||
#*.cs diff=csharp
|
||||
|
||||
###############################################################################
|
||||
# Set the merge driver for project and solution files
|
||||
#
|
||||
# Merging from the command prompt will add diff markers to the files if there
|
||||
# are conflicts (Merging from VS is not affected by the settings below, in VS
|
||||
# the diff markers are never inserted). Diff markers may cause the following
|
||||
# file extensions to fail to load in VS. An alternative would be to treat
|
||||
# these files as binary and thus will always conflict and require user
|
||||
# intervention with every merge. To do so, just uncomment the entries below
|
||||
###############################################################################
|
||||
#*.sln merge=binary
|
||||
#*.csproj merge=binary
|
||||
#*.vbproj merge=binary
|
||||
#*.vcxproj merge=binary
|
||||
#*.vcproj merge=binary
|
||||
#*.dbproj merge=binary
|
||||
#*.fsproj merge=binary
|
||||
#*.lsproj merge=binary
|
||||
#*.wixproj merge=binary
|
||||
#*.modelproj merge=binary
|
||||
#*.sqlproj merge=binary
|
||||
#*.wwaproj merge=binary
|
||||
|
||||
###############################################################################
|
||||
# behavior for image files
|
||||
#
|
||||
# image files are treated as binary by default.
|
||||
###############################################################################
|
||||
#*.jpg binary
|
||||
#*.png binary
|
||||
#*.gif binary
|
||||
|
||||
###############################################################################
|
||||
# diff behavior for common document formats
|
||||
#
|
||||
# Convert binary document formats to text before diffing them. This feature
|
||||
# is only available from the command line. Turn it on by uncommenting the
|
||||
# entries below.
|
||||
###############################################################################
|
||||
#*.doc diff=astextplain
|
||||
#*.DOC diff=astextplain
|
||||
#*.docx diff=astextplain
|
||||
#*.DOCX diff=astextplain
|
||||
#*.dot diff=astextplain
|
||||
#*.DOT diff=astextplain
|
||||
#*.pdf diff=astextplain
|
||||
#*.PDF diff=astextplain
|
||||
#*.rtf diff=astextplain
|
||||
#*.RTF diff=astextplain
|
||||
363
.gitignore
vendored
363
.gitignore
vendored
@ -1,363 +0,0 @@
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
##
|
||||
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||
|
||||
# User-specific files
|
||||
*.rsuser
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Mono auto generated files
|
||||
mono_crash.*
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
[Ww][Ii][Nn]32/
|
||||
[Aa][Rr][Mm]/
|
||||
[Aa][Rr][Mm]64/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Oo]ut/
|
||||
[Ll]og/
|
||||
[Ll]ogs/
|
||||
|
||||
# Visual Studio 2015/2017 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# Visual Studio 2017 auto generated files
|
||||
Generated\ Files/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUnit
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
nunit-*.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# Benchmark Results
|
||||
BenchmarkDotNet.Artifacts/
|
||||
|
||||
# .NET Core
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
|
||||
# ASP.NET Scaffolding
|
||||
ScaffoldingReadMe.txt
|
||||
|
||||
# StyleCop
|
||||
StyleCopReport.xml
|
||||
|
||||
# Files built by Visual Studio
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_h.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.iobj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.ipdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*_wpftmp.csproj
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# Visual Studio Trace Files
|
||||
*.e2e
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# AxoCover is a Code Coverage Tool
|
||||
.axoCover/*
|
||||
!.axoCover/settings.json
|
||||
|
||||
# Coverlet is a free, cross platform Code Coverage Tool
|
||||
coverage*.json
|
||||
coverage*.xml
|
||||
coverage*.info
|
||||
|
||||
# Visual Studio code coverage results
|
||||
*.coverage
|
||||
*.coveragexml
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# NuGet Symbol Packages
|
||||
*.snupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/[Pp]ackages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/[Pp]ackages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/[Pp]ackages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignorable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
*.appx
|
||||
*.appxbundle
|
||||
*.appxupload
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!?*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.jfm
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
orleans.codegen.cs
|
||||
|
||||
# Including strong name files can present a security risk
|
||||
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||
#*.snk
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
ServiceFabricBackup/
|
||||
*.rptproj.bak
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
*.ndf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
*.rptproj.rsuser
|
||||
*- [Bb]ackup.rdl
|
||||
*- [Bb]ackup ([0-9]).rdl
|
||||
*- [Bb]ackup ([0-9][0-9]).rdl
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
node_modules/
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||
*.vbw
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# CodeRush personal settings
|
||||
.cr/personal
|
||||
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Cake - Uncomment if you are using it
|
||||
# tools/**
|
||||
# !tools/packages.config
|
||||
|
||||
# Tabs Studio
|
||||
*.tss
|
||||
|
||||
# Telerik's JustMock configuration file
|
||||
*.jmconfig
|
||||
|
||||
# BizTalk build output
|
||||
*.btp.cs
|
||||
*.btm.cs
|
||||
*.odx.cs
|
||||
*.xsd.cs
|
||||
|
||||
# OpenCover UI analysis results
|
||||
OpenCover/
|
||||
|
||||
# Azure Stream Analytics local run output
|
||||
ASALocalRun/
|
||||
|
||||
# MSBuild Binary and Structured Log
|
||||
*.binlog
|
||||
|
||||
# NVidia Nsight GPU debugger configuration file
|
||||
*.nvuser
|
||||
|
||||
# MFractors (Xamarin productivity tool) working folder
|
||||
.mfractor/
|
||||
|
||||
# Local History for Visual Studio
|
||||
.localhistory/
|
||||
|
||||
# BeatPulse healthcheck temp database
|
||||
healthchecksdb
|
||||
|
||||
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
||||
MigrationBackup/
|
||||
|
||||
# Ionide (cross platform F# VS Code tools) working folder
|
||||
.ionide/
|
||||
|
||||
# Fody - auto-generated XML schema
|
||||
FodyWeavers.xsd
|
||||
25
NTADCP.sln
25
NTADCP.sln
@ -1,25 +0,0 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.5.33627.172
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NTADCP", "NTADCP\NTADCP.csproj", "{7A568997-17BA-415C-B80D-85D6DD81117E}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{7A568997-17BA-415C-B80D-85D6DD81117E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7A568997-17BA-415C-B80D-85D6DD81117E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7A568997-17BA-415C-B80D-85D6DD81117E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7A568997-17BA-415C-B80D-85D6DD81117E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {076B51EF-D96B-4EB0-A705-6284A3431D6B}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@ -1,21 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NTADCP
|
||||
{
|
||||
public class ADCP
|
||||
{
|
||||
/// <summary>
|
||||
/// 表面流速
|
||||
/// </summary>
|
||||
public float SurfaceVelocity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 流速方向 0- 顺水 1 -迎水
|
||||
/// </summary>
|
||||
public float FlowDirection { get; set; } = 3;
|
||||
}
|
||||
}
|
||||
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
|
||||
</startup>
|
||||
</configuration>
|
||||
197
NTADCP/Client.cs
197
NTADCP/Client.cs
@ -1,197 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using static NTADCP.Sockets;
|
||||
|
||||
namespace NTADCP
|
||||
{
|
||||
public class Client : SocketObject
|
||||
{
|
||||
public PushSockets pushSockets;
|
||||
|
||||
bool IsClose = false;
|
||||
/// <summary>
|
||||
/// 当前管理对象
|
||||
/// </summary>
|
||||
Sockets sk;
|
||||
/// <summary>
|
||||
/// 客户端
|
||||
/// </summary>
|
||||
TcpClient client;
|
||||
/// <summary>
|
||||
/// 当前连接服务端地址
|
||||
/// </summary>
|
||||
IPAddress Ipaddress;
|
||||
/// <summary>
|
||||
/// 当前连接服务端端口号
|
||||
/// </summary>
|
||||
int Port;
|
||||
/// <summary>
|
||||
/// 服务端IP+端口
|
||||
/// </summary>
|
||||
IPEndPoint ip;
|
||||
/// <summary>
|
||||
/// 发送与接收使用的流
|
||||
/// </summary>
|
||||
NetworkStream nStream;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化Socket
|
||||
/// </summary>
|
||||
/// <param name="ipaddress"></param>
|
||||
/// <param name="port"></param>
|
||||
public override void InitSocket(IPAddress ipaddress, int port)
|
||||
{
|
||||
Ipaddress = ipaddress;
|
||||
Port = port;
|
||||
ip = new IPEndPoint(Ipaddress, Port);
|
||||
client = new TcpClient();
|
||||
}
|
||||
/// <summary>
|
||||
/// 初始化Socket
|
||||
/// </summary>
|
||||
/// <param name="ipaddress">ipd地址</param>
|
||||
/// <param name="port">端口</param>
|
||||
public override void InitSocket(string ipaddress, int port)
|
||||
{
|
||||
Ipaddress = IPAddress.Parse(ipaddress);
|
||||
Port = port;
|
||||
ip = new IPEndPoint(Ipaddress, Port);
|
||||
client = new TcpClient();
|
||||
}
|
||||
/// <summary>
|
||||
/// 重写Start方法,其实就是连接服务端
|
||||
/// </summary>
|
||||
public override void Start()
|
||||
{
|
||||
Connect();
|
||||
}
|
||||
/// <summary>
|
||||
/// 连接
|
||||
/// </summary>
|
||||
public bool Connect()
|
||||
{
|
||||
try
|
||||
{
|
||||
client.Connect(ip);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
nStream = new NetworkStream(client.Client, true);
|
||||
sk = new Sockets(ip, client, nStream);
|
||||
sk.nStream.BeginRead(sk.RecBuffer, 0, sk.RecBuffer.Length, new AsyncCallback(EndReader), sk);
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// 读取
|
||||
/// </summary>
|
||||
private void EndReader(IAsyncResult ir)
|
||||
{
|
||||
Sockets s = ir.AsyncState as Sockets;
|
||||
try
|
||||
{
|
||||
if (s != null)
|
||||
{
|
||||
if (IsClose && client == null)
|
||||
{
|
||||
sk.nStream.Close();
|
||||
sk.nStream.Dispose();
|
||||
return;
|
||||
}
|
||||
s.Offset = s.nStream.EndRead(ir);
|
||||
if (pushSockets != null)
|
||||
pushSockets.Invoke(s);//推送至UI
|
||||
sk.nStream.BeginRead(sk.RecBuffer, 0, sk.RecBuffer.Length, new AsyncCallback(EndReader), sk);
|
||||
}
|
||||
}
|
||||
catch (Exception skex)
|
||||
{
|
||||
Sockets sks = s;
|
||||
sks.ex = skex;
|
||||
sks.ClientDispose = true;
|
||||
if (pushSockets != null)
|
||||
pushSockets.Invoke(sks);//推送至UI
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 停止
|
||||
/// </summary>
|
||||
public override void Stop()
|
||||
{
|
||||
Sockets sks = new Sockets();
|
||||
try
|
||||
{
|
||||
if (client != null)
|
||||
{
|
||||
client.Client.Shutdown(SocketShutdown.Both);
|
||||
Thread.Sleep(10);
|
||||
client.Close();
|
||||
IsClose = true;
|
||||
client = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
sks.ex = new Exception("客户端没有初始化.!");
|
||||
}
|
||||
if (pushSockets != null)
|
||||
pushSockets.Invoke(sks);//推送至UI
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
sks.ex = ex;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 发送消息
|
||||
/// </summary>
|
||||
public void SendData(byte[] SendData)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (client == null || !client.Connected)
|
||||
{
|
||||
Sockets sks = new Sockets();
|
||||
sks.ex = new Exception("客户端无连接..");
|
||||
sks.ClientDispose = true;
|
||||
if (pushSockets != null)
|
||||
pushSockets.Invoke(sks);//推送至UI
|
||||
}
|
||||
if (client.Connected) //如果连接则发送
|
||||
{
|
||||
if (nStream == null)
|
||||
{
|
||||
nStream = client.GetStream();
|
||||
}
|
||||
nStream.Write(SendData, 0, SendData.Length);
|
||||
}
|
||||
}
|
||||
catch (Exception skex)
|
||||
{
|
||||
Sockets sks = new Sockets();
|
||||
sks.ex = skex;
|
||||
sks.ClientDispose = true;
|
||||
if (pushSockets != null)
|
||||
pushSockets.Invoke(sks);//推送至UI
|
||||
}
|
||||
}
|
||||
|
||||
public bool Is_Connected()
|
||||
{
|
||||
return client.Connected;
|
||||
}
|
||||
|
||||
public bool IsOnline()
|
||||
{
|
||||
if (client == null)
|
||||
return false;
|
||||
return !((client.Client.Poll(1000, SelectMode.SelectRead) && (client.Client.Available == 0)) || !client.Client.Connected);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,64 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NTADCP
|
||||
{
|
||||
//文件及文件夹管理器
|
||||
public class FileManager
|
||||
{
|
||||
//检测并创建文件存储路径
|
||||
public static bool Path_Create(string path, string filename)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!System.IO.Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(filename))
|
||||
return true;
|
||||
|
||||
if (!path.EndsWith(@"\"))
|
||||
path += @"\";
|
||||
|
||||
if (!System.IO.File.Exists(path + filename))
|
||||
{
|
||||
FileStream stream = System.IO.File.Create(path + filename);
|
||||
stream.Close();
|
||||
stream.Dispose();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//文件读取
|
||||
|
||||
|
||||
//文件写入
|
||||
/// <summary>
|
||||
/// txt文档自动保存
|
||||
/// </summary>
|
||||
/// <param name="logstring"></param>
|
||||
public static void AddLgoToTXT(string _file_name, string path, string logstring)
|
||||
{
|
||||
Path_Create(path, _file_name);
|
||||
if (!path.EndsWith(@"\"))
|
||||
path += @"\";
|
||||
using (StreamWriter writer = new StreamWriter(path + _file_name, true))
|
||||
{
|
||||
writer.WriteLine(logstring);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
275
NTADCP/Form1.Designer.cs
generated
275
NTADCP/Form1.Designer.cs
generated
@ -1,275 +0,0 @@
|
||||
namespace NTADCP
|
||||
{
|
||||
partial class Form1
|
||||
{
|
||||
/// <summary>
|
||||
/// 必需的设计器变量。
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// 清理所有正在使用的资源。
|
||||
/// </summary>
|
||||
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows 窗体设计器生成的代码
|
||||
|
||||
/// <summary>
|
||||
/// 设计器支持所需的方法 - 不要修改
|
||||
/// 使用代码编辑器修改此方法的内容。
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.textBox2 = new System.Windows.Forms.TextBox();
|
||||
this.label10 = new System.Windows.Forms.Label();
|
||||
this.textBox1 = new System.Windows.Forms.TextBox();
|
||||
this.label9 = new System.Windows.Forms.Label();
|
||||
this.button2 = new System.Windows.Forms.Button();
|
||||
this.label8 = new System.Windows.Forms.Label();
|
||||
this.label7 = new System.Windows.Forms.Label();
|
||||
this.label6 = new System.Windows.Forms.Label();
|
||||
this.label5 = new System.Windows.Forms.Label();
|
||||
this.comboBox2 = new System.Windows.Forms.ComboBox();
|
||||
this.comboBox1 = new System.Windows.Forms.ComboBox();
|
||||
this.button1 = new System.Windows.Forms.Button();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.label4 = new System.Windows.Forms.Label();
|
||||
this.serialPort1 = new System.IO.Ports.SerialPort(this.components);
|
||||
this.button3 = new System.Windows.Forms.Button();
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Controls.Add(this.button3);
|
||||
this.groupBox1.Controls.Add(this.textBox2);
|
||||
this.groupBox1.Controls.Add(this.label10);
|
||||
this.groupBox1.Controls.Add(this.textBox1);
|
||||
this.groupBox1.Controls.Add(this.label9);
|
||||
this.groupBox1.Controls.Add(this.button2);
|
||||
this.groupBox1.Controls.Add(this.label8);
|
||||
this.groupBox1.Controls.Add(this.label7);
|
||||
this.groupBox1.Controls.Add(this.label6);
|
||||
this.groupBox1.Controls.Add(this.label5);
|
||||
this.groupBox1.Controls.Add(this.comboBox2);
|
||||
this.groupBox1.Controls.Add(this.comboBox1);
|
||||
this.groupBox1.Controls.Add(this.button1);
|
||||
this.groupBox1.Controls.Add(this.label2);
|
||||
this.groupBox1.Controls.Add(this.label1);
|
||||
this.groupBox1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.groupBox1.Location = new System.Drawing.Point(12, 35);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(687, 219);
|
||||
this.groupBox1.TabIndex = 0;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "系统控制";
|
||||
//
|
||||
// textBox2
|
||||
//
|
||||
this.textBox2.Location = new System.Drawing.Point(337, 94);
|
||||
this.textBox2.Name = "textBox2";
|
||||
this.textBox2.Size = new System.Drawing.Size(152, 26);
|
||||
this.textBox2.TabIndex = 13;
|
||||
//
|
||||
// label10
|
||||
//
|
||||
this.label10.AutoSize = true;
|
||||
this.label10.Location = new System.Drawing.Point(263, 100);
|
||||
this.label10.Name = "label10";
|
||||
this.label10.Size = new System.Drawing.Size(71, 16);
|
||||
this.label10.TabIndex = 12;
|
||||
this.label10.Text = "端口号:";
|
||||
//
|
||||
// textBox1
|
||||
//
|
||||
this.textBox1.Location = new System.Drawing.Point(108, 93);
|
||||
this.textBox1.Name = "textBox1";
|
||||
this.textBox1.Size = new System.Drawing.Size(137, 26);
|
||||
this.textBox1.TabIndex = 11;
|
||||
//
|
||||
// label9
|
||||
//
|
||||
this.label9.AutoSize = true;
|
||||
this.label9.Location = new System.Drawing.Point(9, 97);
|
||||
this.label9.Name = "label9";
|
||||
this.label9.Size = new System.Drawing.Size(95, 16);
|
||||
this.label9.TabIndex = 10;
|
||||
this.label9.Text = "数据转发IP:";
|
||||
//
|
||||
// button2
|
||||
//
|
||||
this.button2.Location = new System.Drawing.Point(556, 160);
|
||||
this.button2.Name = "button2";
|
||||
this.button2.Size = new System.Drawing.Size(90, 29);
|
||||
this.button2.TabIndex = 9;
|
||||
this.button2.Text = "开始测量";
|
||||
this.button2.UseVisualStyleBackColor = true;
|
||||
this.button2.Click += new System.EventHandler(this.button2_Click);
|
||||
//
|
||||
// label8
|
||||
//
|
||||
this.label8.AutoSize = true;
|
||||
this.label8.Location = new System.Drawing.Point(353, 164);
|
||||
this.label8.Name = "label8";
|
||||
this.label8.Size = new System.Drawing.Size(55, 16);
|
||||
this.label8.TabIndex = 8;
|
||||
this.label8.Text = "label8";
|
||||
//
|
||||
// label7
|
||||
//
|
||||
this.label7.AutoSize = true;
|
||||
this.label7.Location = new System.Drawing.Point(260, 164);
|
||||
this.label7.Name = "label7";
|
||||
this.label7.Size = new System.Drawing.Size(87, 16);
|
||||
this.label7.TabIndex = 7;
|
||||
this.label7.Text = "流速方向:";
|
||||
//
|
||||
// label6
|
||||
//
|
||||
this.label6.AutoSize = true;
|
||||
this.label6.Location = new System.Drawing.Point(113, 164);
|
||||
this.label6.Name = "label6";
|
||||
this.label6.Size = new System.Drawing.Size(71, 16);
|
||||
this.label6.TabIndex = 6;
|
||||
this.label6.Text = "0.00 m/s";
|
||||
//
|
||||
// label5
|
||||
//
|
||||
this.label5.AutoSize = true;
|
||||
this.label5.Location = new System.Drawing.Point(20, 164);
|
||||
this.label5.Name = "label5";
|
||||
this.label5.Size = new System.Drawing.Size(87, 16);
|
||||
this.label5.TabIndex = 5;
|
||||
this.label5.Text = "表面流速:";
|
||||
//
|
||||
// comboBox2
|
||||
//
|
||||
this.comboBox2.FormattingEnabled = true;
|
||||
this.comboBox2.Location = new System.Drawing.Point(337, 30);
|
||||
this.comboBox2.Name = "comboBox2";
|
||||
this.comboBox2.Size = new System.Drawing.Size(152, 24);
|
||||
this.comboBox2.TabIndex = 4;
|
||||
//
|
||||
// comboBox1
|
||||
//
|
||||
this.comboBox1.FormattingEnabled = true;
|
||||
this.comboBox1.Location = new System.Drawing.Point(107, 30);
|
||||
this.comboBox1.Name = "comboBox1";
|
||||
this.comboBox1.Size = new System.Drawing.Size(137, 24);
|
||||
this.comboBox1.TabIndex = 3;
|
||||
this.comboBox1.DropDown += new System.EventHandler(this.comboBox1_DropDown);
|
||||
//
|
||||
// button1
|
||||
//
|
||||
this.button1.Location = new System.Drawing.Point(556, 30);
|
||||
this.button1.Name = "button1";
|
||||
this.button1.Size = new System.Drawing.Size(90, 29);
|
||||
this.button1.TabIndex = 2;
|
||||
this.button1.Text = "打开串口";
|
||||
this.button1.UseVisualStyleBackColor = true;
|
||||
this.button1.Click += new System.EventHandler(this.button1_Click);
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(260, 33);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(71, 16);
|
||||
this.label2.TabIndex = 1;
|
||||
this.label2.Text = "波特率:";
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(32, 33);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(71, 16);
|
||||
this.label1.TabIndex = 0;
|
||||
this.label1.Text = "串口号:";
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.label3.Location = new System.Drawing.Point(391, 16);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(119, 16);
|
||||
this.label3.TabIndex = 1;
|
||||
this.label3.Text = "当前系统时间:";
|
||||
//
|
||||
// label4
|
||||
//
|
||||
this.label4.AutoSize = true;
|
||||
this.label4.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.label4.Location = new System.Drawing.Point(525, 16);
|
||||
this.label4.Name = "label4";
|
||||
this.label4.Size = new System.Drawing.Size(159, 16);
|
||||
this.label4.TabIndex = 2;
|
||||
this.label4.Text = "0000-00-00 00:00:00";
|
||||
//
|
||||
// button3
|
||||
//
|
||||
this.button3.Location = new System.Drawing.Point(556, 91);
|
||||
this.button3.Name = "button3";
|
||||
this.button3.Size = new System.Drawing.Size(90, 29);
|
||||
this.button3.TabIndex = 14;
|
||||
this.button3.Text = "连接";
|
||||
this.button3.UseVisualStyleBackColor = true;
|
||||
this.button3.Click += new System.EventHandler(this.button3_Click);
|
||||
//
|
||||
// Form1
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(711, 264);
|
||||
this.Controls.Add(this.label4);
|
||||
this.Controls.Add(this.label3);
|
||||
this.Controls.Add(this.groupBox1);
|
||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||
this.Name = "Form1";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "NTADCP";
|
||||
this.groupBox1.ResumeLayout(false);
|
||||
this.groupBox1.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.GroupBox groupBox1;
|
||||
private System.Windows.Forms.ComboBox comboBox2;
|
||||
private System.Windows.Forms.ComboBox comboBox1;
|
||||
private System.Windows.Forms.Button button1;
|
||||
private System.Windows.Forms.Label label2;
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.Label label3;
|
||||
private System.Windows.Forms.Label label4;
|
||||
private System.IO.Ports.SerialPort serialPort1;
|
||||
private System.Windows.Forms.Label label6;
|
||||
private System.Windows.Forms.Label label5;
|
||||
private System.Windows.Forms.Label label7;
|
||||
private System.Windows.Forms.Label label8;
|
||||
private System.Windows.Forms.Button button2;
|
||||
private System.Windows.Forms.Label label10;
|
||||
private System.Windows.Forms.TextBox textBox1;
|
||||
private System.Windows.Forms.Label label9;
|
||||
private System.Windows.Forms.TextBox textBox2;
|
||||
private System.Windows.Forms.Button button3;
|
||||
}
|
||||
}
|
||||
|
||||
678
NTADCP/Form1.cs
678
NTADCP/Form1.cs
@ -1,678 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Reflection.Emit;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Button;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||
using System.IO.Ports;
|
||||
using System.Security.Cryptography;
|
||||
using System.Threading;
|
||||
using System.IO;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ToolBar;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
using System.Net;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
|
||||
namespace NTADCP
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
ADCP adcp = new ADCP();
|
||||
//获取当前程序运行路径
|
||||
private string Save_Path = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"数据采集\";
|
||||
|
||||
//单线程
|
||||
private System.Threading.Timer _flash_page;
|
||||
|
||||
private System.Threading.Timer timer_beckoff_01;
|
||||
DateTime dateTime;
|
||||
|
||||
//定义全局变量,接收数据返回字段
|
||||
private static string MessageAll = "";
|
||||
|
||||
//定义全局变量,存储上一个数据来源时间节点
|
||||
private static DateTime TimeOld = System.DateTime.Now;
|
||||
|
||||
|
||||
//218.91.223.39:19001
|
||||
private string main_ip = "218.91.223.39";
|
||||
private int main_port = 19001;
|
||||
private Client _client = new Client(); //主板客户端
|
||||
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
textBox1.Text = main_ip;
|
||||
textBox2.Text = main_port.ToString();
|
||||
|
||||
//波特率
|
||||
string[] btl = new string[] { "110", "300", "600", "1200", "2400", "4800", "9600", "14400", "19200", "38400", "56000", "57600", "115200", "128000", "256000" };
|
||||
for (int i = 0; i < btl.Length; i++)
|
||||
{
|
||||
comboBox2.Items.Add(btl[i]);
|
||||
}
|
||||
comboBox2.Text = "9600";
|
||||
|
||||
//刷新界面的线程
|
||||
_flash_page = new System.Threading.Timer(new System.Threading.TimerCallback(WritetoPage), null, 2000, 1000);
|
||||
|
||||
button2.Enabled = false;
|
||||
button3.Enabled = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取本机串口号
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void comboBox1_DropDown(object sender, EventArgs e)
|
||||
{
|
||||
comboBox1.Items.Clear();
|
||||
//获取当前设备所有的串口号
|
||||
string[] portsname = tools.GetSerialPort();
|
||||
for (int i = 0; i < portsname.Length; i++)
|
||||
{
|
||||
comboBox1.Items.Add(portsname[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 打开串口
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (button1.Text == "打开串口")
|
||||
{
|
||||
open_port();
|
||||
if (serialPort1.IsOpen)
|
||||
{
|
||||
button1.Text = "关闭串口";
|
||||
comboBox1.Enabled = false;
|
||||
this.comboBox2.Enabled = false;
|
||||
button2.Enabled = true;
|
||||
button3.Enabled = true;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("串口未打开,请检查串口是已经被占用!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (button2.Text == "停止测量")
|
||||
{
|
||||
MessageBox.Show("请先停止测量,后关闭串口!");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
serialPort1.Close();
|
||||
if (serialPort1.IsOpen == false)
|
||||
{
|
||||
button1.Text = "打开串口";
|
||||
comboBox1.Enabled = true;
|
||||
button2.Text = "开始测量";
|
||||
button2.Enabled = false;
|
||||
button3.Enabled = false;
|
||||
this.comboBox2.Enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
serialPort1.Dispose();
|
||||
MessageBox.Show("串口未正常关闭,已释放串口的所有资源!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Socket连接
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void button3_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (button3.Text == "连接")
|
||||
{
|
||||
//连接Socket
|
||||
_client.InitSocket(textBox1.Text, Convert.ToInt32(textBox2.Text));
|
||||
bool isConnected = _client.Connect();
|
||||
if (isConnected)
|
||||
{
|
||||
_client.pushSockets = ReceiveMess;//注册推送器
|
||||
button3.Text = "断开";
|
||||
textBox1.Enabled = false;
|
||||
textBox2.Enabled = false;
|
||||
|
||||
}
|
||||
}
|
||||
else if (button3.Text == "断开")
|
||||
{
|
||||
_client.Stop();
|
||||
button3.Text = "连接";
|
||||
textBox1.Enabled = true;
|
||||
textBox2.Enabled = true;
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// socket 重连
|
||||
/// </summary>
|
||||
/// <param name="o"></param>
|
||||
public void DoSocket1Connect(object o)
|
||||
{
|
||||
if (button3.Text == "连接")
|
||||
{
|
||||
Task.Run(new Action(async () =>
|
||||
{
|
||||
await Task.Delay(150);
|
||||
|
||||
//连接Socket
|
||||
_client.InitSocket(textBox1.Text, Convert.ToInt32(textBox2.Text));
|
||||
bool isConnected = _client.Connect();
|
||||
if (isConnected)
|
||||
{
|
||||
_client.pushSockets = ReceiveMess;//注册推送器
|
||||
button3.Text = "断开";
|
||||
textBox1.Enabled = false;
|
||||
textBox2.Enabled = false;
|
||||
|
||||
}
|
||||
}));
|
||||
}
|
||||
else if (button3.Text == "断开")
|
||||
{
|
||||
Task.Run(new Action(async () =>
|
||||
{
|
||||
await Task.Delay(100);
|
||||
|
||||
_client.Stop();
|
||||
button3.Text = "连接";
|
||||
textBox1.Enabled = true;
|
||||
textBox2.Enabled = true;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 客户端数据接收
|
||||
/// </summary>
|
||||
/// <param name="sks"></param>
|
||||
private void ReceiveMess(Sockets sks)
|
||||
{
|
||||
if (sks.ex != null)
|
||||
{
|
||||
if (sks.ClientDispose == true)
|
||||
{
|
||||
//由于未知原因引发异常.导致客户端下线. 比如网络故障.或服务器断开连接.
|
||||
//wirte_textbox(string.Format("客户端下线.!异常消息:{0}\r\n", sks.ex));
|
||||
}
|
||||
else
|
||||
{
|
||||
//SetClientState(string.Format("异常消息:{0}\r\n", sks.ex));
|
||||
}
|
||||
//timerConnect.Enabled = true;
|
||||
}
|
||||
else if (sks.Offset == 0)
|
||||
{
|
||||
//客户端主动下线
|
||||
//wirte_textbox("客户端下线!");
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] buffer = new byte[sks.Offset];
|
||||
Array.Copy(sks.RecBuffer, buffer, sks.Offset);
|
||||
string str = Encoding.UTF8.GetString(buffer);
|
||||
|
||||
try
|
||||
{
|
||||
ParsingSocketData(new List<byte>(buffer));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 开始测量
|
||||
/// 流速方向 -> 表面流速
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void button2_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (button2.Text == "开始测量")
|
||||
{
|
||||
timer_beckoff_01 = new System.Threading.Timer(new System.Threading.TimerCallback(receive_timer_01), null, 1000, 30000);
|
||||
button2.Text = "停止测量";
|
||||
}
|
||||
else if (button2.Text == "停止测量")
|
||||
{
|
||||
timer_beckoff_01.Dispose();
|
||||
timer_beckoff_01 = null;
|
||||
button2.Text = "开始测量";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送数据
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
|
||||
private void receive_timer_01(object sender)
|
||||
{
|
||||
string Direction = "3403000C000141AC";
|
||||
byte[] bytea = tools.ConvertHexStringToBytes(Direction);
|
||||
tools.Logging_data(Direction);
|
||||
serialPort1.Write(bytea, 0, bytea.Length);
|
||||
|
||||
Thread.Sleep(1000);
|
||||
string FaceVelocity = "3403000F0002F1AD";
|
||||
byte[] FaceVelocitybyte = tools.ConvertHexStringToBytes(FaceVelocity);
|
||||
tools.Logging_data(FaceVelocity);
|
||||
serialPort1.Write(FaceVelocitybyte, 0, FaceVelocitybyte.Length);
|
||||
}
|
||||
|
||||
|
||||
//数据写入界面
|
||||
private void WritetoPage(object sender)
|
||||
{
|
||||
Invoke((EventHandler)(delegate
|
||||
{
|
||||
label4.Text = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
label6.Text = adcp.SurfaceVelocity.ToString() + " " + "m/s";
|
||||
if (adcp.FlowDirection == 1)
|
||||
{
|
||||
label8.Text = "正向";
|
||||
}
|
||||
else if (adcp.FlowDirection == 0)
|
||||
{
|
||||
label8.Text = "逆向";
|
||||
}
|
||||
else
|
||||
{
|
||||
label8.Text = "";
|
||||
}
|
||||
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 打开串口前检查及数据获取
|
||||
/// </summary>
|
||||
public void open_port()
|
||||
{
|
||||
if (string.IsNullOrEmpty(comboBox1.Text))
|
||||
{
|
||||
Invoke((EventHandler)(delegate
|
||||
{
|
||||
MessageBox.Show("请检查串口名称!!!");
|
||||
}));
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(comboBox2.Text))
|
||||
{
|
||||
Invoke((EventHandler)(delegate
|
||||
{
|
||||
MessageBox.Show("请检查波特率!!!");
|
||||
}));
|
||||
return;
|
||||
}
|
||||
serialPort1.PortName = comboBox1.Text;
|
||||
serialPort1.BaudRate = int.Parse(comboBox2.Text);
|
||||
serialPort1.Parity = Parity.None;
|
||||
serialPort1.DataBits = 8;
|
||||
serialPort1.StopBits = StopBits.One;
|
||||
serialPort1.ReceivedBytesThreshold = 1;
|
||||
serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);
|
||||
try
|
||||
{
|
||||
serialPort1.Open();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Invoke((EventHandler)(delegate
|
||||
{
|
||||
MessageBox.Show("串口打开失败!请检查串口配置!");
|
||||
}));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 串口数据接收
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
|
||||
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
//将两秒接收的数据作为1组
|
||||
System.Threading.Thread.Sleep(1000);
|
||||
//将缓冲区内字节数大小设置为数组大小
|
||||
byte[] byteRead = new byte[serialPort1.BytesToRead];
|
||||
//将缓冲区内数据写入字节数组中
|
||||
serialPort1.Read(byteRead, 0, byteRead.Length);
|
||||
//清除串口缓冲区
|
||||
serialPort1.DiscardInBuffer();
|
||||
if (byteRead.Length == 0)
|
||||
return;
|
||||
//数据解析
|
||||
ParsingData(new List<byte>(byteRead));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
string diretion;
|
||||
string SurfaceVelocity;
|
||||
float total = 0;
|
||||
|
||||
// 定义一个List存储流速
|
||||
List<float> SurfaceVelocityList = new List<float>();
|
||||
|
||||
/// <summary>
|
||||
/// 串口数据解析及平台发送
|
||||
/// </summary>
|
||||
/// <param name="byteList"></param>
|
||||
private void ParsingData(List<byte> byteList)
|
||||
{
|
||||
string rec_16 = null;
|
||||
for (int i = 0; i < byteList.Count; i++)
|
||||
{
|
||||
rec_16 += byteList[i].ToString("X2"); //16进制显示
|
||||
}
|
||||
//校验当前List是否为空或者长度
|
||||
if (byteList == null || byteList.Count == 0)
|
||||
return;
|
||||
//获取当前系统时间
|
||||
DateTime time_DataBase = System.DateTime.Now;
|
||||
//帧头
|
||||
byte[] _header = new byte[] { 0X34 };
|
||||
//功能码
|
||||
byte _fun_code = 0;
|
||||
|
||||
//校验帧头
|
||||
if (byteList[0] != _header[0])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//功能码
|
||||
_fun_code = byteList[2];
|
||||
|
||||
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 当地时区
|
||||
DateTime dt = new DateTime();
|
||||
|
||||
switch (_fun_code)
|
||||
{
|
||||
//读取流向 -- 00 01 流速方向为迎水;若为 00 00 则流速方向为顺水
|
||||
case 0x02:
|
||||
if (byteList[3] == 0x00 && byteList[4] == 0x01)
|
||||
{
|
||||
adcp.FlowDirection = 1;
|
||||
diretion = "正向";
|
||||
|
||||
}
|
||||
else if (byteList[3] == 0x00 && byteList[4] == 0x00)
|
||||
{
|
||||
adcp.FlowDirection = 0;
|
||||
diretion = "逆向";
|
||||
}
|
||||
break;
|
||||
|
||||
//读取流速
|
||||
case 0x04:
|
||||
adcp.SurfaceVelocity = BitConverter.ToSingle(new byte[] { byteList[3], byteList[4], byteList[5], byteList[6] }, 0);
|
||||
SurfaceVelocity = adcp.SurfaceVelocity.ToString();
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine("未能识别功能码!");
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
if (SurfaceVelocity != "" && diretion != "" && SurfaceVelocity != null)
|
||||
{
|
||||
var text = "测量时间:" + time_DataBase + "," + "流速:" + SurfaceVelocity + "," + "方向:" + diretion;
|
||||
//数据存入
|
||||
tools.AddLgoToTXT("测量结果.txt", Save_Path + System.DateTime.Now.ToString("yyyy_MM_dd") + @"\", System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ---- " + text + "\r\n");
|
||||
|
||||
SurfaceVelocityList.Add(adcp.SurfaceVelocity);
|
||||
|
||||
if ((SurfaceVelocityList.Count != 0) && (time_DataBase.Hour != TimeOld.Hour))
|
||||
{
|
||||
foreach (var item in SurfaceVelocityList)
|
||||
{
|
||||
if (SurfaceVelocityList.Count == 1)
|
||||
{
|
||||
total = item;
|
||||
}
|
||||
else
|
||||
{
|
||||
total += item;
|
||||
}
|
||||
}
|
||||
adcp.SurfaceVelocity = total / SurfaceVelocityList.Count();
|
||||
SurfaceVelocityList.Clear();
|
||||
|
||||
tools.Logging(time_DataBase + ": " + "本地开始向平台上发送数据!");
|
||||
SendMessage(adcp.SurfaceVelocity, adcp.FlowDirection);
|
||||
DoConnect();
|
||||
|
||||
}
|
||||
TimeOld = time_DataBase;
|
||||
|
||||
|
||||
//判断当前时间是否为整点,如果为整点,就向平台上发送数据
|
||||
//if (time_DataBase.ToString("mm:ss") == "00:00")
|
||||
//{
|
||||
// tools.Logging(time_DataBase + ": " + "本地开始向平台上发送数据!");
|
||||
// SendMessage(adcp.SurfaceVelocity, adcp.FlowDirection);
|
||||
// DoConnect();
|
||||
|
||||
//}
|
||||
|
||||
diretion = "";
|
||||
SurfaceVelocity = "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Socket数据解析
|
||||
/// </summary>
|
||||
/// <param name="byteList"></param>
|
||||
private void ParsingSocketData(List<byte> byteList)
|
||||
{
|
||||
string rec_16 = null;
|
||||
for (int i = 0; i < byteList.Count; i++)
|
||||
{
|
||||
rec_16 += byteList[i].ToString("X2"); //16进制显示
|
||||
}
|
||||
|
||||
//校验当前List是否为空或者长度
|
||||
if (byteList == null || byteList.Count == 0)
|
||||
return;
|
||||
|
||||
|
||||
MessageAll = rec_16;
|
||||
|
||||
//232330303737514E3D323032333036323 如果是以这个开头的,说明数据正常反馈
|
||||
if (rec_16.StartsWith("2323"))
|
||||
{
|
||||
var text = System.DateTime.Now + " " + "接收到一条回复";
|
||||
tools.Logging(text);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 数据平台发送流速及流向
|
||||
/// </summary>
|
||||
/// <param name="SurfaceVelocity">流速</param>
|
||||
/// <param name="direction">流向</param>
|
||||
private void SendMessage(float SurfaceVelocity, float direction)
|
||||
{
|
||||
//包头
|
||||
string Head = "##";
|
||||
//数据域长度
|
||||
string date_length = "";
|
||||
|
||||
//请求编码
|
||||
string RequestEncoding = "QN=" + DateTime.Now.ToString("yyy-MM-dd HH.mm.ss.fff").Replace("-", "").Replace(" ", "").Replace(".", "") + ";";
|
||||
|
||||
//系统编码
|
||||
string SystemCoding = "ST=21;";
|
||||
|
||||
//命令编码
|
||||
string CommandCode = "CN=2061;";
|
||||
|
||||
//访问密码
|
||||
string AccessPassword = "PW=123456;";
|
||||
|
||||
//设备唯一辨识
|
||||
string DeviceIdentification = "MN=32060020200003;";
|
||||
|
||||
//拆分包及应答标志
|
||||
string Response = "Flag=9;";
|
||||
|
||||
//指令参数
|
||||
string CP = "CP=&&DataTime=" + DateTime.Now.ToString("yyyy-MM-dd HH:00:00").Replace("-", "").Replace(" ", "").Replace(":", "") + ";";
|
||||
|
||||
//流速
|
||||
string Velocity = "w21112-Avg=" + SurfaceVelocity + ",w21112-Flag=N;";
|
||||
|
||||
//流向
|
||||
string dir = "e01205-Avg=" + direction + ",e01205-Flag=N" + "&&";
|
||||
|
||||
//数据域
|
||||
string Data = RequestEncoding + SystemCoding + CommandCode + AccessPassword + DeviceIdentification + Response + CP + Velocity + dir;
|
||||
|
||||
//更新数据域长度
|
||||
date_length = "0" + Data.Length;
|
||||
|
||||
//数据域转化为byte数组
|
||||
byte[] ByteData = System.Text.Encoding.Default.GetBytes(Data);
|
||||
|
||||
//计算crc
|
||||
byte[] crc = CRC16_CheckOut(ByteData);
|
||||
string crc1 = crc[0].ToString("X2");
|
||||
string crc2 = crc[1].ToString("X2");
|
||||
|
||||
//完整的数据字符串
|
||||
string FullData = Head + date_length + Data + crc1 + crc2;
|
||||
|
||||
//将完整的数据转化为byte数组
|
||||
byte[] FullByteData = System.Text.Encoding.Default.GetBytes(FullData);
|
||||
|
||||
//包尾 (回车、换行)
|
||||
byte[] rn = new byte[2];
|
||||
rn[0] = 0x0D;
|
||||
rn[1] = 0x0A;
|
||||
|
||||
|
||||
List<byte> data = FullByteData.ToList();
|
||||
data.AddRange(rn);
|
||||
string list = tools.byteToHexStr(data.ToArray());
|
||||
byte[] bytea = tools.ConvertHexStringToBytes(list);
|
||||
_client.SendData(bytea);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// CRC16 循环冗余校验算法
|
||||
/// </summary>
|
||||
/// <param name="pushMsg"></param>
|
||||
/// <returns></returns>
|
||||
private byte[] CRC16_CheckOut(byte[] pushMsg)
|
||||
{
|
||||
int crc_reg, check;
|
||||
crc_reg = 0xFFFF;
|
||||
for (int i = 0; i < pushMsg.Length; i++)
|
||||
{
|
||||
crc_reg = (crc_reg >> 8) ^ pushMsg[i];
|
||||
for (int j = 0; j < 8; j++)
|
||||
{
|
||||
check = crc_reg & 0x0001;
|
||||
crc_reg >>= 1;
|
||||
if (check == 0x0001)
|
||||
{
|
||||
crc_reg ^= 0xA001;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
byte[] returnMsg = new byte[2];
|
||||
returnMsg[0] = (byte)(crc_reg >> 8);
|
||||
returnMsg[1] = (byte)(crc_reg & 0xFF);
|
||||
return returnMsg;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 检查连接状态
|
||||
/// </summary>
|
||||
/// <param name="Message"></param>
|
||||
private async void DoConnect()
|
||||
{
|
||||
int i = 0;
|
||||
await Task.Run(() =>
|
||||
{
|
||||
Thread.Sleep(2000);
|
||||
|
||||
while (i < 3)
|
||||
{
|
||||
Thread.Sleep(2000);
|
||||
if (MessageAll == null || MessageAll == "" || (!MessageAll.StartsWith("2323")))
|
||||
{
|
||||
tools.Logging("未收到IP:" + main_ip + "端口号:" + main_port + " 回复的信息,开始重新连接");
|
||||
Thread.Sleep(10000);
|
||||
DoSocket1Connect("连接");
|
||||
Thread.Sleep(1000);
|
||||
SendMessage(adcp.SurfaceVelocity, adcp.FlowDirection);
|
||||
i++;
|
||||
}
|
||||
else if (MessageAll.StartsWith("2323"))
|
||||
{
|
||||
tools.Logging("收到IP:" + main_ip + "端口号:" + main_port + " 回复的信息,连接成功");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
MessageAll = "";
|
||||
i = 0;
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
1256
NTADCP/Form1.resx
1256
NTADCP/Form1.resx
File diff suppressed because it is too large
Load Diff
@ -1,93 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{7A568997-17BA-415C-B80D-85D6DD81117E}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<RootNamespace>NTADCP</RootNamespace>
|
||||
<AssemblyName>NTADCP</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Deployment" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ADCP.cs" />
|
||||
<Compile Include="Client.cs" />
|
||||
<Compile Include="FileManager.cs" />
|
||||
<Compile Include="Form1.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Form1.Designer.cs">
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Sockets.cs" />
|
||||
<Compile Include="tools.cs" />
|
||||
<EmbeddedResource Include="Form1.resx">
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Resource Include="bitbug_favicon.ico">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Resource>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@ -1,22 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace NTADCP
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// 应用程序的主入口点。
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new Form1());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,36 +0,0 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的一般信息由以下
|
||||
// 控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("NTADCP")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("ZTT")]
|
||||
[assembly: AssemblyProduct("NTADCP")]
|
||||
[assembly: AssemblyCopyright("Copyright © ZTT 2023")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 将 ComVisible 设置为 false 会使此程序集中的类型
|
||||
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
|
||||
//请将此类型的 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||
[assembly: Guid("7a568997-17ba-415c-b80d-85d6dd81117e")]
|
||||
|
||||
// 程序集的版本信息由下列四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 生成号
|
||||
// 修订号
|
||||
//
|
||||
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
|
||||
//通过使用 "*",如下所示:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
71
NTADCP/Properties/Resources.Designer.cs
generated
71
NTADCP/Properties/Resources.Designer.cs
generated
@ -1,71 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 此代码由工具生成。
|
||||
// 运行时版本: 4.0.30319.42000
|
||||
//
|
||||
// 对此文件的更改可能导致不正确的行为,如果
|
||||
// 重新生成代码,则所做更改将丢失。
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace NTADCP.Properties
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 强类型资源类,用于查找本地化字符串等。
|
||||
/// </summary>
|
||||
// 此类是由 StronglyTypedResourceBuilder
|
||||
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
|
||||
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
|
||||
// (以 /str 作为命令选项),或重新生成 VS 项目。
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources
|
||||
{
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回此类使用的缓存 ResourceManager 实例。
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager
|
||||
{
|
||||
get
|
||||
{
|
||||
if ((resourceMan == null))
|
||||
{
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("NTADCP.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写当前线程的 CurrentUICulture 属性,对
|
||||
/// 使用此强类型资源类的所有资源查找执行重写。
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture
|
||||
{
|
||||
get
|
||||
{
|
||||
return resourceCulture;
|
||||
}
|
||||
set
|
||||
{
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,117 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
30
NTADCP/Properties/Settings.Designer.cs
generated
30
NTADCP/Properties/Settings.Designer.cs
generated
@ -1,30 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace NTADCP.Properties
|
||||
{
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
|
||||
{
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default
|
||||
{
|
||||
get
|
||||
{
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
|
||||
<Profiles>
|
||||
<Profile Name="(Default)" />
|
||||
</Profiles>
|
||||
<Settings />
|
||||
</SettingsFile>
|
||||
@ -1,109 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NTADCP
|
||||
{
|
||||
public class Sockets
|
||||
{
|
||||
public delegate void PushSockets(Sockets sockets);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Sockets()
|
||||
{
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 创建Sockets对象
|
||||
/// </summary>
|
||||
/// <param name="ip">Ip地址</param>
|
||||
/// <param name="client">TcpClient</param>
|
||||
/// <param name="ns">承载客户端Socket的网络流</param>
|
||||
public Sockets(IPEndPoint ip, TcpClient client, NetworkStream ns)
|
||||
{
|
||||
Ip = ip;
|
||||
Client = client;
|
||||
nStream = ns;
|
||||
}
|
||||
/// <summary>
|
||||
/// 创建Sockets对象
|
||||
/// </summary>
|
||||
/// <param name="name">用户名</param>
|
||||
/// <param name="pass">密码</param>
|
||||
/// <param name="ip">Ip地址</param>
|
||||
/// <param name="client">TcpClient</param>
|
||||
/// <param name="ns">承载客户端Socket的网络流</param>
|
||||
public Sockets(string name, string pass, IPEndPoint ip, TcpClient client, NetworkStream ns)
|
||||
{
|
||||
UserName = name;
|
||||
Password = pass;
|
||||
Ip = ip;
|
||||
Client = client;
|
||||
nStream = ns;
|
||||
}
|
||||
/// <summary>
|
||||
/// 接收缓冲区
|
||||
/// </summary>
|
||||
public byte[] RecBuffer = new byte[8 * 1024];
|
||||
/// <summary>
|
||||
/// 发送缓冲区
|
||||
/// </summary>
|
||||
public byte[] SendBuffer = new byte[8 * 1024];
|
||||
/// <summary>
|
||||
/// 异步接收后包的大小
|
||||
/// </summary>
|
||||
public int Offset { get; set; }
|
||||
/// <summary>
|
||||
/// 用户名
|
||||
/// </summary>
|
||||
public string UserName { get; set; }
|
||||
/// <summary>
|
||||
/// 密码
|
||||
/// </summary>
|
||||
public string Password { get; set; }
|
||||
/// <summary>
|
||||
/// 当前IP地址,端口号
|
||||
/// </summary>
|
||||
public IPEndPoint Ip { get; set; }
|
||||
/// <summary>
|
||||
/// 客户端主通信程序
|
||||
/// </summary>
|
||||
public TcpClient Client { get; set; }
|
||||
/// <summary>
|
||||
/// 承载客户端Socket的网络流
|
||||
/// </summary>
|
||||
public NetworkStream nStream { get; set; }
|
||||
/// <summary>
|
||||
/// 发生异常时不为null
|
||||
/// </summary>
|
||||
public Exception ex { get; set; }
|
||||
/// <summary>
|
||||
/// 新客户端标识.如果推送器发现此标识为true,那么认为是客户端上线 仅服务端有效
|
||||
/// </summary>
|
||||
public bool NewClientFlag { get; set; }
|
||||
/// <summary>
|
||||
/// 客户端退出标识.如果服务端发现此标识为true,那么认为客户端下线
|
||||
/// 客户端接收此标识时,认为客户端异常.
|
||||
/// </summary>
|
||||
public bool ClientDispose { get; set; }
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Socket基类(抽象类)
|
||||
/// 抽象3个方法,初始化Socket(含一个构造),停止,启动方法.
|
||||
/// 此抽象类为TcpServer与TcpClient的基类,前者实现后者抽象方法
|
||||
/// </summary>
|
||||
public abstract class SocketObject
|
||||
{
|
||||
public abstract void InitSocket(IPAddress ipaddress, int port);
|
||||
public abstract void InitSocket(string ipaddress, int port);
|
||||
public abstract void Start();
|
||||
public abstract void Stop();
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 66 KiB |
331
NTADCP/tools.cs
331
NTADCP/tools.cs
@ -1,331 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NTADCP
|
||||
{
|
||||
class tools
|
||||
{
|
||||
//获取当前设备的所有端口号
|
||||
public static string[] GetSerialPort()
|
||||
{
|
||||
string[] ports = null;
|
||||
ports = System.IO.Ports.SerialPort.GetPortNames();
|
||||
return ports;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// 16进制原码字符串转字节数组
|
||||
/// </summary>
|
||||
/// <param name="hexString">"AABBCC"或"AA BB CC"格式的字符串</param>
|
||||
/// <returns></returns>
|
||||
public static byte[] ConvertHexStringToBytes(string hexString)
|
||||
{
|
||||
hexString = hexString.Replace(" ", "");
|
||||
if (hexString.Length % 2 != 0)
|
||||
{
|
||||
throw new ArgumentException("参数长度不正确");
|
||||
}
|
||||
|
||||
byte[] returnBytes = new byte[hexString.Length / 2];
|
||||
for (int i = 0; i < returnBytes.Length; i++)
|
||||
{
|
||||
returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
|
||||
}
|
||||
|
||||
return returnBytes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// //16转2方法
|
||||
/// </summary>
|
||||
/// <param name="hexString"></param>
|
||||
/// <returns></returns>
|
||||
public static string HexString2BinString(string hexString)
|
||||
{
|
||||
try
|
||||
{
|
||||
string result = string.Empty;
|
||||
foreach (char c in hexString)
|
||||
{
|
||||
int v = Convert.ToInt32(c.ToString(), 16);
|
||||
int v2 = int.Parse(Convert.ToString(v, 2));
|
||||
// 去掉格式串中的空格,即可去掉每个4位二进制数之间的空格,
|
||||
result += string.Format("{0:d4} ", v2);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 字节数组转16进制字符串
|
||||
/// </summary>
|
||||
/// <param name="bytes"></param>
|
||||
/// <returns></returns>
|
||||
public static string byteToHexStr(byte[] bytes)
|
||||
{
|
||||
string returnStr = "";
|
||||
if (bytes != null)
|
||||
{
|
||||
for (int i = 0; i < bytes.Length; i++)
|
||||
{
|
||||
returnStr += bytes[i].ToString("X2");
|
||||
}
|
||||
}
|
||||
return returnStr;
|
||||
}
|
||||
|
||||
|
||||
public static string HexStringToString(string hs, Encoding encode)
|
||||
{
|
||||
StringBuilder strTemp = new StringBuilder();
|
||||
byte[] b = new byte[hs.Length / 2];
|
||||
for (int i = 0; i < hs.Length / 2; i++)
|
||||
{
|
||||
strTemp.Clear();
|
||||
strTemp.Append(hs.Substring(i * 2, 2));
|
||||
b[i] = Convert.ToByte(strTemp.ToString(), 16);
|
||||
}
|
||||
return encode.GetString(b);
|
||||
}
|
||||
|
||||
#region 生成并保存本地文件
|
||||
|
||||
static Dictionary<string, bool> Txt_Used = new Dictionary<string, bool>();
|
||||
|
||||
/// <summary>
|
||||
/// 文件自动保存
|
||||
/// </summary>
|
||||
/// <param name="_file_name">文件名称</param>
|
||||
/// <param name="path">保存路径</param>
|
||||
/// <param name="logstring">文件内容</param>
|
||||
public static void AddLgoToTXT(string _file_name, string path, string logstring)
|
||||
{
|
||||
//检查是否存在该路径
|
||||
if (!System.IO.Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
|
||||
path = path + _file_name;
|
||||
//检查该路径下是否存在该文件
|
||||
if (!System.IO.File.Exists(path))
|
||||
{
|
||||
FileStream stream = System.IO.File.Create(path);
|
||||
stream.Close();
|
||||
stream.Dispose();
|
||||
}
|
||||
if (!Txt_Used.ContainsKey(path))
|
||||
{
|
||||
Txt_Used.Add(path, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Txt_Used[path])
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Txt_Used[path] = true;
|
||||
}
|
||||
}
|
||||
//[1]创建文件流 文件路径 和枚举类型的文件操作类型
|
||||
FileStream fs = new FileStream(path, FileMode.Append);
|
||||
//[2]创建写入器
|
||||
StreamWriter sw = new StreamWriter(fs);
|
||||
//[3]以流的方式写入数据
|
||||
sw.Write(logstring);
|
||||
//[4]关闭写入器
|
||||
sw.Close();
|
||||
//[5]关闭文件流
|
||||
fs.Close();
|
||||
Txt_Used[path] = false;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
//十六进制转字符串
|
||||
public string ConvertHexToString(string HexValue, string separator = null)
|
||||
{
|
||||
HexValue = string.IsNullOrEmpty(separator) ? HexValue : HexValue.Replace(string.Empty, separator);
|
||||
StringBuilder sbStrValue = new StringBuilder();
|
||||
while (HexValue.Length > 0)
|
||||
{
|
||||
sbStrValue.Append(Convert.ToChar(Convert.ToUInt32(HexValue.Substring(0, 2), 16)).ToString());
|
||||
HexValue = HexValue.Substring(2);
|
||||
}
|
||||
return sbStrValue.ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// 将传入的byte数组 从指定位置倒置
|
||||
/// </summary>
|
||||
/// <param name="b"></param>
|
||||
/// <returns></returns>
|
||||
public static float bytetofloat(List<byte> b, int start)
|
||||
{
|
||||
return BitConverter.ToSingle(new byte[] { b[start + 3], b[start + 2], b[start + 1], b[start] }, 0);
|
||||
}
|
||||
|
||||
public static int bytetoint(List<byte> b, int start, int len)
|
||||
{
|
||||
string a = "";
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
a += b[start + i].ToString("X2");
|
||||
}
|
||||
return Convert.ToInt32(a, 16);
|
||||
}
|
||||
|
||||
public static int ByteToInt16(List<byte> b, int start, int len)
|
||||
{
|
||||
string a = "";
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
a += b[start + i].ToString("X2");
|
||||
}
|
||||
return Convert.ToInt16(a, 16);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将一条十六进制字符串转换为ASCII
|
||||
/// </summary>
|
||||
/// <param name="hexstring">一条十六进制字符串</param>
|
||||
/// <returns>返回一条ASCII码</returns>
|
||||
public static string HexStringToASCII(string hexstring)
|
||||
{
|
||||
byte[] bt = HexStringToBinary(hexstring);
|
||||
string lin = "";
|
||||
for (int i = 0; i < bt.Length; i++)
|
||||
{
|
||||
lin = lin + bt[i] + " ";
|
||||
}
|
||||
|
||||
|
||||
string[] ss = lin.Trim().Split(new char[] { ' ' });
|
||||
char[] c = new char[ss.Length];
|
||||
int a;
|
||||
for (int i = 0; i < c.Length; i++)
|
||||
{
|
||||
a = Convert.ToInt32(ss[i]);
|
||||
c[i] = Convert.ToChar(a);
|
||||
}
|
||||
|
||||
string b = new string(c);
|
||||
return b;
|
||||
}
|
||||
|
||||
/**/
|
||||
/// <summary>
|
||||
/// 16进制字符串转换为二进制数组
|
||||
/// </summary>
|
||||
/// <param name="hexstring">用空格切割字符串</param>
|
||||
/// <returns>返回一个二进制字符串</returns>
|
||||
public static byte[] HexStringToBinary(string hexstring)
|
||||
{
|
||||
|
||||
string[] tmpary = hexstring.Trim().Split(' ');
|
||||
byte[] buff = new byte[tmpary.Length];
|
||||
for (int i = 0; i < buff.Length; i++)
|
||||
{
|
||||
buff[i] = Convert.ToByte(tmpary[i], 16);
|
||||
}
|
||||
return buff;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region CRC校验
|
||||
private static readonly byte[] aucCRCHi = {
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
|
||||
0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
|
||||
0x00, 0xC1, 0x81, 0x40
|
||||
};
|
||||
private static readonly byte[] aucCRCLo = {
|
||||
0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7,
|
||||
0x05, 0xC5, 0xC4, 0x04, 0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E,
|
||||
0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, 0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9,
|
||||
0x1B, 0xDB, 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC,
|
||||
0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3,
|
||||
0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, 0xF2, 0x32,
|
||||
0x36, 0xF6, 0xF7, 0x37, 0xF5, 0x35, 0x34, 0xF4, 0x3C, 0xFC, 0xFD, 0x3D,
|
||||
0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A, 0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38,
|
||||
0x28, 0xE8, 0xE9, 0x29, 0xEB, 0x2B, 0x2A, 0xEA, 0xEE, 0x2E, 0x2F, 0xEF,
|
||||
0x2D, 0xED, 0xEC, 0x2C, 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26,
|
||||
0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60, 0x61, 0xA1,
|
||||
0x63, 0xA3, 0xA2, 0x62, 0x66, 0xA6, 0xA7, 0x67, 0xA5, 0x65, 0x64, 0xA4,
|
||||
0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F, 0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB,
|
||||
0x69, 0xA9, 0xA8, 0x68, 0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA,
|
||||
0xBE, 0x7E, 0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5,
|
||||
0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71, 0x70, 0xB0,
|
||||
0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92, 0x96, 0x56, 0x57, 0x97,
|
||||
0x55, 0x95, 0x94, 0x54, 0x9C, 0x5C, 0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E,
|
||||
0x5A, 0x9A, 0x9B, 0x5B, 0x99, 0x59, 0x58, 0x98, 0x88, 0x48, 0x49, 0x89,
|
||||
0x4B, 0x8B, 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C,
|
||||
0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83,
|
||||
0x41, 0x81, 0x80, 0x40
|
||||
};
|
||||
private static byte[] Crc16(byte[] pucFrame, int usLen)
|
||||
{
|
||||
int i = 0;
|
||||
byte crcHi = 0xFF;
|
||||
byte crcLo = 0xFF;
|
||||
UInt16 iIndex = 0x0000;
|
||||
|
||||
while (usLen-- > 0)
|
||||
{
|
||||
iIndex = (UInt16)(crcLo ^ pucFrame[i++]);
|
||||
crcLo = (byte)(crcHi ^ aucCRCHi[iIndex]);
|
||||
crcHi = aucCRCLo[iIndex];
|
||||
}
|
||||
|
||||
return new byte[] { crcLo, crcHi };
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
//获取当前程序运行路径
|
||||
private static string Save_Path = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"数据采集\";
|
||||
public static void Logging(string message)
|
||||
{
|
||||
AddLgoToTXT("Log.txt", Save_Path + System.DateTime.Now.ToString("yyyy_MM_dd") + @"\", System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ---- " + message + "\r\n");
|
||||
}
|
||||
|
||||
public static void Logging_data(string message)
|
||||
{
|
||||
AddLgoToTXT("原始报文.txt", Save_Path + System.DateTime.Now.ToString("yyyy_MM_dd") + @"\", System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ---- " + message + "\r\n");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user