public void SendTTCA(string terminalID)
        {
            var ttca = new CTTCAStruct();

            ttca.SenderID     = "1";   //  本机ID
            ttca.RecvAddr     = terminalID;
            ttca.Requirements = "1";   //  不保密
            ttca.ReceiptSign  = false; //  不回执
            ttca.MsgLength    = 75;    //  电文长度
            //  拼包
            var bytes = new List <byte>();

            for (int index = 0; index < this.BeidouStatus.Count; index = index + 8)
            {
                StringBuilder builder = new StringBuilder();
                builder.Append(this.BeidouStatus[index + 0] ? "1" : "0");
                builder.Append(this.BeidouStatus[index + 1] ? "1" : "0");
                builder.Append(this.BeidouStatus[index + 2] ? "1" : "0");
                builder.Append(this.BeidouStatus[index + 3] ? "1" : "0");
                builder.Append(this.BeidouStatus[index + 4] ? "1" : "0");
                builder.Append(this.BeidouStatus[index + 5] ? "1" : "0");
                builder.Append(this.BeidouStatus[index + 6] ? "1" : "0");
                builder.Append(this.BeidouStatus[index + 7] ? "1" : "0");
                byte byt = byte.Parse(builder.ToString());
                bytes.Add(byt);
            }
            ttca.MsgContent = System.Text.Encoding.Default.GetString(bytes.ToArray());//  电文内容
            SendTTCA(ttca);
        }
            /// <summary>
            /// 终端到终端通信申请,自发自收
            /// 解析自发自收返回后的结果
            /// $TTCA
            /// </summary>
            /// <param name="msg"></param>
            /// <returns></returns>
            public static CTTCAStruct GetTTCAInfo(String msg)
            {
                try
                {
                    String cmd = msg.Substring(0, 4);
                    if (cmd != CTTCAStruct.CMD_PREFIX)
                    {
                        throw new Exception("数据格式不对!");
                    }

                    msg = msg.Replace("$", "").Replace("\r", "").Replace("\n", "");
                    String[] segs = msg.Split(',');
                    if (segs.Length != 8)
                    {
                        throw new Exception("数据长度不对!");
                    }

                    CTTCAStruct result = new CTTCAStruct();
                    result.SenderID     = segs[1];
                    result.RecvAddr     = segs[2];
                    result.Requirements = segs[3];
                    result.ReceiptSign  = segs[4].Equals("1") ? true : false;
                    result.MsgLength    = int.Parse(segs[5]);
                    result.MsgContent   = segs[6];
                    result.CheckSum     = segs[7];
                    return(result);
                }
                catch (Exception exp) { Debug.WriteLine(exp); }
                return(null);
            }
 private void SendTTCA(CTTCAStruct param)
 {
     string text = GetTTCAStr(param);
     //   Debug.WriteLine("发送TTCA:" + text);
     // InvokeMessage("自发自收  " + text, "发送");
     // SendText(text);
 }
        public String SendTTCA(CTTCAStruct param)
        {
            string text = BeidouHelper.GetTTCAStr(param);

            Debug.WriteLine("发送TTCA:" + text);
            InvokeMessage("自发自收  " + text, "发送");
            SendText(text);
            //    return SendBackTTCA();
            return("");
        }
        //本地通信
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox_SendAddress.Text.Equals("") || textBox_Communicate.Text.Equals(""))
            {
                MessageBox.Show("发送地址或通讯报文不能为空!");
                return;
            }
            CTTCAStruct cTTCAStruct = new CTTCAStruct();

            cTTCAStruct.SenderID     = textBox_SendAddress.Text.ToString();
            cTTCAStruct.RecvAddr     = textBox_SendAddress.Text.ToString();
            cTTCAStruct.Requirements = "1";
            cTTCAStruct.ReceiptSign  = false;
            cTTCAStruct.MsgContent   = textBox_Communicate.Text.ToString();
            cTTCAStruct.MsgLength    = cTTCAStruct.MsgContent.Length;
            localCommunicateStr      = cTTCAStruct.SenderID;
            CPortDataMgr.Instance.SendBeidouTTCA(this.comboBox1.Text, cTTCAStruct);
        }
            /// <summary>
            /// 终端到终端通信申请,自发自收
            /// 获取自发自收查询字符串
            /// $TTCA
            /// </summary>
            public static String GetTTCAStr(CTTCAStruct param)
            {
                StringBuilder rawStr = new StringBuilder();

                rawStr.Append("$");
                rawStr.Append(CTTCAStruct.CMD_PREFIX);
                rawStr.Append(",");
                rawStr.Append(param.SenderID);                 // 发信方ID
                rawStr.Append(",");
                rawStr.Append(param.RecvAddr);                 // 收信方地址
                rawStr.Append(",");
                rawStr.Append(param.Requirements);             // 保密要求
                rawStr.Append(",");
                rawStr.Append(param.ReceiptSign ? "1" : "0");  // 回执标志
                rawStr.Append(",");
                rawStr.Append(param.MsgLength.ToString());     // 电文长度
                rawStr.Append(",");
                rawStr.Append(param.MsgContent);               // 电文内容
                rawStr.Append(",");
                rawStr.Append(GenerateCRC(rawStr.ToString())); // 校验和
                rawStr.Append("\r\n");
                return(rawStr.ToString());
            }