コード例 #1
0
        //示例: $00010K01yymmddhh#13
        public String BuildQuery(string sid, EStationType stationType, ETrans trans, DateTime beginTime, EChannelType ctype)
        {
            //  拼接发送指令的字符串
            StringBuilder sb = new StringBuilder();

            sb.Append(ProtocolMaps.ChannelProtocolStartCharMap.FindValue(ctype));
            sb.Append(String.Format("{0:D4}", Int32.Parse(sid.Trim())));
            sb.Append("0K");
            //  type : 01:01为水位 02为雨量
            sb.Append(ProtocolHelpers.StationType2ProtoStr(stationType));

            switch (trans)
            {
            case ETrans.ByHour:
                sb.Append(beginTime.ToString("yyMMddHH"));
                break;

            case ETrans.ByDay:
                sb.Append(beginTime.ToString("yyMMdd"));
                sb.Append("88");
                break;

            default:
                throw new Exception("传输格式错误");
            }
            sb.Append('\r');
            return(sb.ToString());
        }