예제 #1
0
 //_________________________________________________________________________
 CModbusTCP Free(IAsyncResult Res /*, AsyncCallback CurrFunc*/)
 {
     //if (Global.Closing)				return null;
     MTCP = CloseAsyncRecieve(Res /*, CurrFunc*/);
     Владелец.Flush();             //if (MTCP != null)				MTCP.Flush ();
     return(MTCP);
 }
예제 #2
0
 /// <summary>
 /// Пришёл ответ на запрос параметров
 /// </summary>
 /// <param name="Res">The status of an asynchronous operation</param>
 public void RecieveAnswer(IAsyncResult Res)
 {
     if (Res.IsCompleted == false)
     {
         return;
     }
     MTCP = Free(Res);
     try
     {
         if (MTCP != null && Res.IsCompleted && MTCP.StateExch == EStateRecieve.OK)
         {
             //          if (/*Protocol == EProtocol.IRGA2 && */RecieveByte > 0 && RecieveByte < LenAnswer)
             //          {
             //#if LOG_IRGA
             //						Global.LogWriteLine ("LenRecieve= " + LenRecieve + ", LenAnswer= " + LenAnswer);
             //#endif
             //            MTCP.ReadNext (iRecieveByte);
             //            return;
             //          }
             Владелец.TrStopWait.Stop();
             //if (MTCP.StateExch == EStateRecieve.OK)
             {
                 iCountHandle++;
                 //if (iCountHandle >1)                MTCP.Stream.Read (MTCP.BufRX, 0, MTCP.BufRX.Length);
                 HandlingData(MTCP);
             }
         }
     }
     catch (Exception exc)
     {
         StopWaitRecieve();
         Владелец.OutMess($"RecDataRd: {exc.Message}{Environment.NewLine}{exc.StackTrace}", "");
     }
 }
예제 #3
0
 public override bool HandlingData(CModbusTCP MTCP)
 {
     TrTimeoutRX.Stop();
     //OutMess ($"TCP.RX: [{Global.ByteArToStr (BufRX, NumRecieveByte, Recieve.RecieveByte)}]", "");
     NumRecieveByte += Recieve.RecieveByte;
     Global.Append(BufRX, btaRX, 0, Recieve.RecieveByte);
     TrTimeoutRX.Start();
     return(false);
 }
예제 #4
0
 //_________________________________________________________________________
 public override bool HandlingData(CModbusTCP MTCP)
 {
     if (base.HandlingData(MTCP))
     {
         EvRecieve?.Invoke(BufRX, EventArgs.Empty);
         return(true);
     }
     return(false);
 }
예제 #5
0
        public virtual bool HandlingData(CModbusTCP MTCP)
        {
            if (Владелец.Closing)
            {
                return(false);
            }
            TrStopWait.Stop();

            //OutMess ("CountHandl " + Recieve.iCountHandle + " ___" + Recieve.iCnt.ToString() + " iCntPeaces=" + Recieve.iCntPieces, "");
            OutMess("TCP.RX " + Recieve.RecieveByte + ": [" + Global.ByteArToStr(BufRX, 0, Recieve.RecieveByte) + "]", "");

            if (Владелец.RMG != null)               //if (Владелец.CBDev.SelectedIndex == (int)DEVICE.IRGA2)
            {
                if (BufTX[iPosData] == (byte)ESymComm.CurrVals)
                {
                    if (BufRX[0] == 0xC9)
                    {
                        iLenAnswer = Global.ToInt16rev(BufRX, 1);
                    }

                    NumRecieveByte += Recieve.RecieveByte;                     //OutMess ("Full=" + iRecieveFull + " LenAnswer=" + iLenAnswer, "");
                    if (iLenAnswer > NumRecieveByte)
                    {
                        //OutMess ("ReadNext", "");
                        ReadNext();                             // SendComm (iPosData, usLenData);
                    }
                    return(false);
                }
                else                // if (BufTX[iPosData] == (byte)ESymComm.ФХП)
                {
                    if (NextRequest() == false)
                    {
                        return(false);
                    }
                }
            }
            else
            {
                if (NextRequest() == false)
                {
                    return(false);
                }
            }

            if (Recieve.LenAnswer == 1)
            {
                Thread.Sleep((int)Владелец.NUDTimeout.Value);                 //OutMess ("Buf2 " + ": [" + Global.ByteArToStr (Recieve.bta2, 0, Recieve.RecieveByte) + "]", "");
            }
            if (++iCurrRequest < iQuantComm)
            {
                //OutMess ("iCountHandle " + Recieve.iCountHandle + " DataAvailable " + bNWstream, "");
                NumRecieveByte = 0;
                Request(GetStrFromArr(Владелец.TBCommand.Lines, iCurrRequest));                   //Request (Владелец.TBCommand.Lines[iCurrRequest]);
                return(false);
            }
            return(true);
        }