diff --git a/DianBiao/.vs/DianBiao/v16/.suo b/DianBiao/.vs/DianBiao/v16/.suo new file mode 100644 index 0000000..f77a87a Binary files /dev/null and b/DianBiao/.vs/DianBiao/v16/.suo differ diff --git a/DianBiao/App.config b/DianBiao/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/DianBiao/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/DianBiao/DianBiao.csproj b/DianBiao/DianBiao.csproj new file mode 100644 index 0000000..adcf537 --- /dev/null +++ b/DianBiao/DianBiao.csproj @@ -0,0 +1,54 @@ + + + + + Debug + AnyCPU + {CA663F4F-3D66-454E-9C4A-1C1ED2A7B8C0} + Exe + DianBiao + DianBiao + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DianBiao/DianBiao.sln b/DianBiao/DianBiao.sln new file mode 100644 index 0000000..15b73e6 --- /dev/null +++ b/DianBiao/DianBiao.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.32929.386 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DianBiao", "DianBiao.csproj", "{CA663F4F-3D66-454E-9C4A-1C1ED2A7B8C0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CA663F4F-3D66-454E-9C4A-1C1ED2A7B8C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CA663F4F-3D66-454E-9C4A-1C1ED2A7B8C0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CA663F4F-3D66-454E-9C4A-1C1ED2A7B8C0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CA663F4F-3D66-454E-9C4A-1C1ED2A7B8C0}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {CD5CE7DD-0001-4A60-AE34-8E91E74534F4} + EndGlobalSection +EndGlobal diff --git a/DianBiao/Properties/AssemblyInfo.cs b/DianBiao/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..271cee3 --- /dev/null +++ b/DianBiao/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("DianBiao")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("DianBiao")] +[assembly: AssemblyCopyright("Copyright © 2023")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("ca663f4f-3d66-454e-9c4a-1c1ed2a7b8c0")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 +//通过使用 "*",如下所示: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/DianBiao/ToolKit.cs b/DianBiao/ToolKit.cs new file mode 100644 index 0000000..cac3d3b --- /dev/null +++ b/DianBiao/ToolKit.cs @@ -0,0 +1,382 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace ToolKitlib +{ + #region 转换工具包【ToolKit】 + + /// + /// 转换工具包 + /// + internal class ToolKit + { + /// + /// 16进制转字符串(十进制)** + /// + /// + /// + public static string hexStr2Str(String hexStr) + { + String str = "0123456789ABCDEF"; + char[] hexs = hexStr.ToCharArray(); + byte[] bytes = new byte[hexStr.Length / 2]; + int n; + + for (int i = 0; i < bytes.Length; i++) + { + n = str.IndexOf(hexs[2 * i]) * 16; + n += str.IndexOf(hexs[2 * i + 1]); + bytes[i] = (byte)(n & 0xff); + } + StringBuilder stringBuilder = new StringBuilder(""); + for (int i = 0; i < bytes.Length; i++) + { + stringBuilder.Append(bytes[i]); + } + return stringBuilder.ToString(); + } + + /// + /// 16进制转ASCII码** + /// + /// 16进制字符 + /// + public static StringBuilder hexToASCII(string hexStr) + { + String str = "0123456789ABCDEF"; + char[] hexs = hexStr.ToCharArray(); + byte[] bytes = new byte[hexStr.Length / 2]; + int n; + + for (int i = 0; i < bytes.Length; i++) + { + n = str.IndexOf(hexs[2 * i]) * 16; + n += str.IndexOf(hexs[2 * i + 1]); + bytes[i] = (byte)(n & 0xff); + } + StringBuilder VersionNumber = new StringBuilder(""); + for (int i = 0; i < bytes.Length; i++) + { + VersionNumber.Append((char)bytes[i]); + } + return VersionNumber; + } + + /// + /// 获取高四位** + /// + /// + /// + public static int getHeight4(byte data) + { + int height; + height = ((data & 0xf0) >> 4); + return height; + } + + /// + /// 获取低四位** + /// + /// + /// + public static int getLow4(byte data) + { + int low; + low = (data & 0x0f); + return low; + } + + /// + /// byte数组转string + /// + /// + /// + public static string byteArrayToString(byte[] data, Encoding encoding) + { + return encoding.GetString(data); + } + + /// + /// 将列表 转为byte[] + /// + /// + /// + public static byte[] listToBytes(List matrix) + { + if (matrix == null) + { + return new byte[0]; + } + using (MemoryStream stream = new MemoryStream()) + { + BinaryWriter bw = new BinaryWriter(stream); + foreach (var item in matrix) + { + bw.Write(item); + } + return stream.ToArray(); + } + + } + + /// + /// string转 byte数组 + /// + /// + /// 传入数据进制 + /// + public static byte[] stringToByteArray(string data, int fromBase) + { + if (data.Length < 2 || data.Length % 2 != 0) return null; + byte[] bytes = new byte[(data.Length) / 2]; + for (int i = 0; i < data.Length; i++) + { + if (i != 0 && i % 2 != 0) + { + ushort a = (ushort)Convert.ToInt16((data[i - 1].ToString() + data[i].ToString()).ToString(), fromBase); + + bytes[(i - 1) / 2] = (byte)(a); + } + } + + return bytes; + } + + /// + /// string转byte数组--针对校验位 + /// + /// + /// [0]--高位;[1]地位-- + public static byte[] stringToByteArray(string str) + { + //var a = "332A"; + ushort u = (ushort)Convert.ToInt16(str, 16);//0x332A + byte g = (byte)(u / 256);//0x33 高位 + byte d = (byte)(u % 256);//0x2A 地位 + return new byte[] { g, d }; + } + + /// + /// byte数组转16进制字符串 + /// + /// + /// + public static string byteArrayToHexString(byte[] data) + { + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < data.Length; i++) + { + builder.Append(string.Format("{0:X2} ", data[i])); + } + return builder.ToString().Trim(); + } + + /// + /// byte数组转16进制字符串--接收 + /// + /// + /// + public static string byteArrayToHexString(byte[] data, int length = 0) + { + int dataLength = 0; + if (length != 0) dataLength = length; + else dataLength = data.Length; + + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < dataLength; i++) + { + builder.Append(string.Format("{0:X2} ", data[i])); + } + return builder.ToString().Trim(); + } + + /// + /// 16进制字符串转byte数组 + /// + /// + /// + public static byte[] hexStringToByteArray(string data) + { + string[] chars = data.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + byte[] returnBytes = new byte[chars.Length]; + //逐个字符变为16进制字节数据 + for (int i = 0; i < chars.Length; i++) + { + returnBytes[i] = Convert.ToByte(chars[i], 16); + } + return returnBytes; + } + + /// + /// byte数组转10进制字符串 + /// + /// + /// + public static string byteArrayToDecString(byte[] data) + { + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < data.Length; i++) + { + builder.Append(data[i] + " "); + } + return builder.ToString().Trim(); + } + + /// + /// 10进制字符串转byte数组 + /// + /// + /// + public static byte[] decStringToByteArray(string data) + { + string[] chars = data.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + byte[] returnBytes = new byte[chars.Length]; + //逐个字符变为10进制字节数据 + for (int i = 0; i < chars.Length; i++) + { + returnBytes[i] = Convert.ToByte(chars[i], 10); + } + return returnBytes; + } + + /// + /// byte数组转八进制字符串 + /// + /// + /// + public static string byteArrayToOtcString(byte[] data) + { + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < data.Length; i++) + { + builder.Append(Convert.ToString(data[i], 8) + " "); + } + return builder.ToString().Trim(); + } + + /// + /// 八进制字符串转byte数组 + /// + /// + /// + public static byte[] otcStringToByteArray(string data) + { + string[] chars = data.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + byte[] returnBytes = new byte[chars.Length]; + //逐个字符变为8进制字节数据 + for (int i = 0; i < chars.Length; i++) + { + returnBytes[i] = Convert.ToByte(chars[i], 8); + } + return returnBytes; + } + + /// + /// 二进制字符串转byte数组 + /// + /// + /// + public static byte[] binStringToByteArray(string data) + { + string[] chars = data.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + byte[] returnBytes = new byte[chars.Length]; + //逐个字符变为2进制字节数据 + for (int i = 0; i < chars.Length; i++) + { + returnBytes[i] = Convert.ToByte(chars[i], 2); + } + return returnBytes; + } + + /// + /// byte数组转二进制字符串 + /// + /// + /// + public static string byteArrayToBinString(byte[] data) + { + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < data.Length; i++) + { + builder.Append(Convert.ToString(data[i], 2) + " "); + } + return builder.ToString().Trim(); + } + + /// + /// 每8bit高低位互换 + /// + /// 起始 + /// 终止 + /// 需要转换的16进制数据 + /// 新的16进制数据 + public static string interconvert(int j, int k, string message, bool exchange = true) + { + StringBuilder parityBitCS = new StringBuilder("");//互换后的值 + + string[] strings = new string[4] { message[0].ToString() + message[1].ToString(), message[2].ToString() + message[3].ToString(), message[4].ToString() + message[5].ToString(), message[6].ToString() + message[7].ToString() }; + for (int i = strings.Length - 1; i >= 0; i--) + { + parityBitCS.Append(strings[i].ToString()); + } + return Convert.ToInt32(parityBitCS.ToString(), 16).ToString(); + } + + /// + /// byte[]直接转Float** + /// + /// + /// + public static float byteToFloat(string message) + { + byte[] bFxianOrg = new byte[4]; + var a = Encoding.Default.GetBytes(message); + StringBuilder zz = new StringBuilder(""); + StringBuilder _zz = new StringBuilder(""); + string[] s = new string[4]; + int x = 0; + for (int i = 0; i < a.Length; i++) + { + if (x != 0 && i % 2 == 0) + { + zz.Append(int.Parse(hexStr2Str(_zz.ToString())).ToString()).Append("-"); + _zz.Clear(); + x = 0; + } + _zz.Append(((char)a[i]).ToString()); + if (i == a.Length - 1) + { + zz.Append(int.Parse(hexStr2Str(_zz.ToString())).ToString()).Append("-"); + _zz.Clear(); + } + x++; + } + s = zz.ToString().Split('-'); + byte a0 = byte.Parse(s[0].ToString()); + byte a1 = byte.Parse(s[1].ToString()); + byte a2 = byte.Parse(s[2].ToString()); + byte a3 = byte.Parse(s[3].ToString()); + bFxianOrg = new byte[4] { a0, a1, a2, a3 }; + var b = BitConverter.ToSingle(bFxianOrg, 0); + return b; + } + + /// + /// string[]转string** + /// + /// + /// + public static string strsTostring(string[] vs) + { + return String.Join("", vs);//引号中可加字符串分隔符 + } + + + } + #endregion +} diff --git a/DianBiao/dianbiao.cs b/DianBiao/dianbiao.cs new file mode 100644 index 0000000..dfffa54 --- /dev/null +++ b/DianBiao/dianbiao.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ToolKitlib; + +namespace DianBiao +{ + class dianbiao + { + static void Main(string[] args) + { + } + } +} diff --git a/DianBiao/obj/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs b/DianBiao/obj/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs new file mode 100644 index 0000000..3871b18 --- /dev/null +++ b/DianBiao/obj/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs @@ -0,0 +1,4 @@ +// +using System; +using System.Reflection; +[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] diff --git a/DianBiao/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/DianBiao/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 0000000..26c71a5 Binary files /dev/null and b/DianBiao/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/DianBiao/obj/Debug/DianBiao.csproj.AssemblyReference.cache b/DianBiao/obj/Debug/DianBiao.csproj.AssemblyReference.cache new file mode 100644 index 0000000..0f91a91 Binary files /dev/null and b/DianBiao/obj/Debug/DianBiao.csproj.AssemblyReference.cache differ