예제 #1
0
        public string Test()
        {
            if (!comPort.Write(new PacketOut(IsLittleEndian)
            {
                command = 1
            }.Serial))
            {
                return("Не смогли записать");
            }
            PacketIn pIn = new PacketIn(IsLittleEndian);

            pIn.Serial = comPort.ReadSome(PacketIn.AdditionalSize);
            if (pIn.command != 1)
            {
                return("Не та команда в ответе");
            }
            if (pIn.abonent != 2)
            {
                return("Не тот абонет в ответе");
            }
            return(pIn.SState);
        }
예제 #2
0
        double?GetSpeed()
        {
            l_lastError = null;
            byte[] b = comPort.ReadSome(7);
            string s = Encoding.Default.GetString(b);

            if (s.Length != 7)
            {
                pr("Не верная длина пакета: " + s.Length.ToString());
                return(null);
            }
            if (s[0] != '!')
            {
                pr("Нет начала: !");
                return(null);
            }
            if (s[s.Length - 2] != Convert.ToChar(0xD))
            {
                pr("Нет 0xD");
                return(null);
            }
            if (s[s.Length - 1] != Convert.ToChar(0xA))
            {
                pr("Нет 0xA");
                return(null);
            }
            if (s.Length == 7)
            {
                if (s.Substring(1, 4) == "stop")
                {
                    return(0);
                }
                string s_speed = s.Substring(1, 4).Replace(".", ",");
                double speed   = 0;
                if (!Double.TryParse(s_speed, out speed))
                {
                    pr("Не смогли интерпретировать скорость: " + s_speed);
                    return(null);
                }
                return(speed);
            }
            return(null);
        }
예제 #3
0
파일: MitCOM.cs 프로젝트: andreyV512/rag
 public void Exec(int _abonent, int _timeout, string _cmd, Request.Etype _request, string request_data, out Reply.EType _replyType, out string _replyData)
 {
     lock (SyncObj)
     {
         request    = new Request(_request, _cmd, request_data);
         _replyType = Reply.EType.None;
         _replyData = null;
         if (!comPort.Write(request.Get(_abonent, _timeout)))
         {
             _replyData = "Не смогли послать запрос";
             return;
         }
         string packet = string.Empty;
         for (; ;)
         {
             byte[] c = comPort.ReadSome(1);
             if (c.Length != 1)
             {
                 if (packet.Length == 0)
                 {
                     _replyData = "Нет ответа";
                 }
                 else
                 {
                     _replyData = "Ответ не разобран";
                 }
                 return;
             }
             packet += Encoding.ASCII.GetString(c);
             foreach (Reply p in Lreply)
             {
                 if (p.parse(_abonent, packet))
                 {
                     _replyType = p.TP;
                     _replyData = p.result;
                     return;
                 }
             }
         }
     }
 }