Example #1
0
        public sendData GetData(string data)
        {
            sendData sendData = new sendData();
            //str = "";
            string czType  = data.Substring(2, 2);
            int    typeNum = Int32.Parse(tools.Tool.HexToDec(czType));

            switch (typeNum)
            {
            case 208:
            {
                dcSendData dcSendData = new dcSendData();
                sendData = dcSendData.DataInit(data);
                break;
            }

            case 203:
            {
                xhdSendData xhdSendData = new xhdSendData();
                sendData = xhdSendData.DataInit(data);
                break;
            }

            case 1:
            {
                jcSendData jcSendData = new jcSendData();
                sendData = jcSendData.DataInit(data);
                break;
            }
            }
            return(sendData);
        }
Example #2
0
        public sendData DataInit(string data)
        {
            StringBuilder data1 = new StringBuilder();
            StringBuilder data2 = new StringBuilder();
            StringBuilder str1 = new StringBuilder();
            sendData sendData = new sendData();
            sendData.dataList = new List<string>();
            //str = "";
            try
            {
                if (data.Length != 8)
                {
                    Exception e1 = new Exception("数据长度不是8位");
                    throw e1;
                }

                czData czData = new czData();

                subStr subStr=new subStr();
                
                string idstring = tools.Tool.HexToDec(data.Substring(4, 2));
                int Id = Int32.Parse(idstring);
                czData.Id = this.GetStringDouByte(idstring);
                //判断前进或后退
                czData.flag = data.Substring(6, 1);
                switch (czData.flag)
                {
                    //前进(最小速度)
                    case "f":
                    case "F":
                    {
                        subStr = this.GetjcData("jcSendFMin");
                        data1.AppendFormat("{0}{1}{2}{3}", subStr.strBegin,
                            czData.Id,"8", subStr.strEnd);
                        str1.AppendFormat("机车[{0}] 状态[前进]", Id);
                        sendData.dataList.Add(data1.ToString());
                        sendData.msg = str1.ToString();
                        sendData.error = false;
                        break;
                    }
                    //后退
                    case "b":
                    case "B":
                    {
                        subStr = this.GetjcData("jcSendBMin");
                        data1.AppendFormat("{0}{1}{2}{3}", subStr.strBegin,
                            czData.Id, "0", subStr.strEnd);
                        str1.AppendFormat("机车[{0}] 状态[后退]", Id);
                        sendData.dataList.Add(data1.ToString());
                        sendData.msg = str1.ToString();
                        sendData.error = false;
                        break;
                    }
                    //停止
                    case "0":
                    {
                        subStr = this.GetjcData("jcStop");
                        data1.AppendFormat("{0}{1}{2}", subStr.strBegin,
                            czData.Id, subStr.strEnd);
                        subStr = this.GetjcData("jcStop");
                        data2.AppendFormat("{0}{1}{2}", subStr.strBegin,
                            czData.Id, subStr.strEnd);
                        str1.AppendFormat("机车[{0}] 状态[停车]", Id);
                        sendData.dataList.Add(data1.ToString());
                        sendData.dataList.Add(data2.ToString());
                        sendData.msg = str1.ToString();
                        sendData.error = false;
                        break;
                    }
                }
            }
            catch (Exception e1)
            {
                sendData.dataList = null;
                sendData.msg = e1.Message;
                sendData.error = true;
                MessageBox.Show(e1.Message, "错误");
            }

            //str = str1.ToString();
            return sendData;
        }
Example #3
0
        /// <summary>
        /// 初始化数据
        /// </summary>
        /// <param name="data"></param>
        /// <param name="str"></param>
        /// <returns></returns>
        public sendData DataInit(string data)
        {
            StringBuilder data1    = new StringBuilder();
            StringBuilder data2    = new StringBuilder();
            StringBuilder str1     = new StringBuilder();
            sendData      sendData = new sendData();

            sendData.dataList = new List <string>();
            //str = "";
            try
            {
                if (data.Length != 8)
                {
                    Exception e1 = new Exception("数据长度不是8位");
                    throw e1;
                }
                czData czData = new czData();

                dc dc = new dc();
                //编号为现有数字减一
                string idstring = tools.Tool.HexToDec(data.Substring(4, 2));
                int    Id       = Int32.Parse(idstring) - 1;
                czData.Id   = tools.Tool.DecToHex(Id);
                czData.flag = data.Substring(6, 2);
                switch (czData.flag)
                {
                //定位
                case "00":
                {
                    dc = this.Ding;
                    data1.AppendFormat("{0}{1}{2}", dc.ding.strBegin,
                                       czData.Id, dc.ding.strEnd);
                    dc = this.Ding1;
                    data2.AppendFormat("{0}{1}{2}", dc.ding.strBegin,
                                       czData.Id, dc.ding.strEnd);
                    str1.AppendFormat("道岔[{0}] 状态[定位]", idstring);
                    sendData.dataList.Add(data1.ToString());
                    sendData.dataList.Add(data2.ToString());
                    sendData.msg   = str1.ToString();
                    sendData.error = false;
                    break;
                }

                //反位
                case "01":
                {
                    dc = this.Fan;
                    data1.AppendFormat("{0}{1}{2}", dc.fan.strBegin,
                                       czData.Id, dc.fan.strEnd);
                    dc = this.Fan1;
                    data2.AppendFormat("{0}{1}{2}", dc.fan.strBegin,
                                       czData.Id, dc.fan.strEnd);
                    str1.AppendFormat("道岔[{0}] 状态[反位]", idstring);
                    sendData.dataList.Add(data1.ToString());
                    sendData.dataList.Add(data2.ToString());
                    sendData.msg   = str1.ToString();
                    sendData.error = false;
                    break;
                }
                }
            }
            catch (Exception e1)
            {
                sendData.dataList = null;
                sendData.msg      = e1.Message;
                sendData.error    = true;
                MessageBox.Show(e1.Message, "错误");
            }

            //str = str1.ToString();
            return(sendData);
        }