Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用于计算C中的块校验字符(BCC)的函数#_C# - Fatal编程技术网

C# 用于计算C中的块校验字符(BCC)的函数#

C# 用于计算C中的块校验字符(BCC)的函数#,c#,C#,块校验字符(BCC) 我需要一个函数来计算C#中的块校验字符(BCC)。 01 30 02 4D 21 20 03 这是字符串,如何计算该字符串的“块检查字符” BCC=从SOH到ETX的独占或 SOH ID STX代码ETX BCC 0x01 0x30 0x02 0x40 0x03 我需要添加密件抄送并将数据发送到COM。 如果可能,请给我一个函数,以便我可以发送“01 30 02 4D 21 20 20 03”并获得密件抄送 public static byte GetBCC(this b

块校验字符(BCC) 我需要一个函数来计算C#中的块校验字符(BCC)。 01 30 02 4D 21 20 03 这是字符串,如何计算该字符串的“块检查字符”

BCC=从SOH到ETX的独占或 SOH ID STX代码ETX BCC 0x01 0x30 0x02 0x40 0x03

我需要添加密件抄送并将数据发送到COM。 如果可能,请给我一个函数,以便我可以发送“01 30 02 4D 21 20 20 03”并获得密件抄送

 public static byte GetBCC(this byte[] inputStream)
    {
        byte bcc = 0;

        if (inputStream != null && inputStream.Length > 0)
        {
            // Exclude SOH during BCC calculation
            for (int i = 1; i < inputStream.Length; i++)
            {
                bcc ^= inputStream[i];
            }
        }

        return bcc;
    }

谢谢,据我所知,BCC是给定字节流中所有字节的异或,不包括第一个SOH或STX,直到第一个ETX或EOT。ETX包含在BCC中。在每个ETX之后分割字节流,并调用以下函数以获取BCC

 public static byte GetBCC(this byte[] inputStream)
    {
        byte bcc = 0;

        if (inputStream != null && inputStream.Length > 0)
        {
            // Exclude SOH during BCC calculation
            for (int i = 1; i < inputStream.Length; i++)
            {
                bcc ^= inputStream[i];
            }
        }

        return bcc;
    }
公共静态字节GetBCC(此字节[]inputStream)
{
字节bcc=0;
if(inputStream!=null&&inputStream.Length>0)
{
//BCC计算期间排除SOH
for(inti=1;i
发布一段简短但完整的代码,给出66而不是5c。@使用上面给出的值{0x01、0x30、0x02、0x4D、0x21、0x20、0x20、0x03}的wenkat62我得到0x5D。当我将上面的代码I=1更改为I=0时,结果是0x5C。这可能是你想要的。但是请验证您正在编程的COM设备的文档。对不起。。。你能再给我解释一下你是怎么得到0x5D的吗。在文档中,这就是他们提到的,没有别的。“BCC=Exclusive OR from SOH to ETX”如果可能的话,你能告诉我如何调用GetBCC函数的确切语法吗,因为早上我收到了一个错误,因为“GetBCC有一些无效的参数…”thanksbyte stt1=0;stt1=GetBCC(“30024D20212003”);这是调用并获取值的正确方法吗。。。感谢您是否将数据作为字符串“01 30 02 4D 21 20 20 03”或字节值序列new byte[]{0x01,0x30,0x02,0x4d,0x21,0x20,0x20,0x03}?先生,我有字符串“01 30 02 4D 21 20 03”感谢字节stt1=0;字符串stt2=“0130024D20212003”;byte[]arr=new System.Text.UTF8Encoding(true).GetBytes(stt2);列表字节列表=新列表(arr);stt1=clsExt.GetBCC(arr);这就是我所说的。。。????我得到66分了,谢谢