• 大小: 1.03M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2024-04-19
  • 语言: C/C++
  • 标签: 1500  西门子  00  通讯  C#  

资源简介


资源截图

代码片段和文件信息

using System;
using System.Globalization;

namespace S7.Net
{
    /// 
    /// Conversion methods to convert from Siemens numeric format to C# and back
    /// 

    public static class Conversion
    {
        /// 
        /// Converts a binary string to Int32 value
        /// 

        /// 
        /// 
        public static int BinStringToInt32(this string txt)
        {
            int ret = 0;

            for (int i = 0; i < txt.Length; i++)
            {
                ret = (ret << 1) | ((txt[i] == ‘1‘) ? 1 : 0);
            }
            return ret;
        }

        /// 
        /// Converts a binary string to a byte. Can return null.
        /// 

        /// 
        /// 
        public static byte? BinStringToByte(this string txt)
        {
            if (txt.Length == 8) return (byte)BinStringToInt32(txt);
            return null;
        }

        /// 
        /// Converts the value to a binary string
        /// 

        /// 
        /// 
        public static string ValToBinString(this object value)
        {
            int cnt = 0;
            int cnt2 = 0;
            int x = 0;
            string txt = ““;
            long longValue = 0;

            try
            {
                if (value.GetType().Name.IndexOf(“[]“) < 0)
                {
                    // ist nur ein Wert
                    switch (value.GetType().Name)
                    {
                        case “Byte“:
                            x = 7;
                            longValue = (long)((byte)value);
                            break;
                        case “Int16“:
                            x = 15;
                            longValue = (long)((Int16)value);
                            break;
                        case “Int32“:
                            x = 31;
                            longValue = (long)((Int32)value);
                            break;
                        case “Int64“:
                            x = 63;
                            longValue = (long)((Int64)value);
                            break;
                        default:
                            throw new Exception();
                    }

                    for (cnt = x; cnt >= 0; cnt += -1)
                    {
                        if (((Int64)longValue & (Int64)Math.Pow(2 cnt)) > 0)
                            txt += “1“;
                        else
                            txt += “0“;
                    }
                }
                else
                {
                    // ist ein Array
                    switch (value.GetType().Name)
                    {
                        case “Byte[]“:
                            x = 7;
                            byte[] ByteArr = (byte[])value;
             

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2021-01-05 21:14  s7netplus-develop\
     文件         158  2021-01-05 21:14  s7netplus-develop\.gitignore
     目录           0  2021-01-05 21:14  s7netplus-develop\Documentation\
     文件      191272  2021-01-05 21:14  s7netplus-develop\Documentation\Documentation.docx
     文件      573506  2021-01-05 21:14  s7netplus-develop\Documentation\Documentation.pdf
     文件      121055  2021-01-05 21:14  s7netplus-develop\Documentation\protection 2.png
     文件       17466  2021-01-05 21:14  s7netplus-develop\Documentation\protection.png
     文件        8392  2021-01-05 21:14  s7netplus-develop\Documentation\struct.png
     文件         436  2021-01-05 21:14  s7netplus-develop\GitVersion.yml
     文件        1082  2021-01-05 21:14  s7netplus-develop\License.txt
     文件        1520  2021-01-05 21:14  s7netplus-develop\README.md
     目录           0  2021-01-05 21:14  s7netplus-develop\S7.Net.UnitTest\
     文件        3541  2021-01-05 21:14  s7netplus-develop\S7.Net.UnitTest\ConnectionRequestTest.cs
     文件         791  2021-01-05 21:14  s7netplus-develop\S7.Net.UnitTest\ConvertersUnitTest.cs
     目录           0  2021-01-05 21:14  s7netplus-develop\S7.Net.UnitTest\Helpers\
     文件        2675  2021-01-05 21:14  s7netplus-develop\S7.Net.UnitTest\Helpers\ConsoleManager.cs
     文件        1218  2021-01-05 21:14  s7netplus-develop\S7.Net.UnitTest\Helpers\NativeMethods.cs
     文件        4188  2021-01-05 21:14  s7netplus-develop\S7.Net.UnitTest\Helpers\S7TestServer.cs
     文件        1557  2021-01-05 21:14  s7netplus-develop\S7.Net.UnitTest\Helpers\TestClass.cs
     文件         843  2021-01-05 21:14  s7netplus-develop\S7.Net.UnitTest\Helpers\TestClassWithArrays.cs
     文件         498  2021-01-05 21:14  s7netplus-develop\S7.Net.UnitTest\Helpers\TestClassWithCustomType.cs
     文件        1229  2021-01-05 21:14  s7netplus-develop\S7.Net.UnitTest\Helpers\TestClassWithNestedClass.cs
     文件        1145  2021-01-05 21:14  s7netplus-develop\S7.Net.UnitTest\Helpers\TestClassWithPrivateSetters.cs
     文件        6218  2021-01-05 21:14  s7netplus-develop\S7.Net.UnitTest\Helpers\TestLongClass.cs
     文件        4806  2021-01-05 21:14  s7netplus-develop\S7.Net.UnitTest\Helpers\TestLongStruct.cs
     文件         201  2021-01-05 21:14  s7netplus-develop\S7.Net.UnitTest\Helpers\TestSmallClass.cs
     文件        1360  2021-01-05 21:14  s7netplus-develop\S7.Net.UnitTest\Helpers\TestStruct.cs
     文件        6890  2021-01-05 21:14  s7netplus-develop\S7.Net.UnitTest\PLCAddressParsingTests.cs
     目录           0  2021-01-05 21:14  s7netplus-develop\S7.Net.UnitTest\Properties\
     文件         596  2021-01-05 21:14  s7netplus-develop\S7.Net.UnitTest\Properties\S7.Net.snk
     文件        3562  2021-01-05 21:14  s7netplus-develop\S7.Net.UnitTest\ProtocolTests.cs
............此处省略71个文件信息

评论

共有 条评论