Ejemplo n.º 1
0
 //_________________________________________________________________________
 public override void BeforeRequest()
 {
     base.BeforeRequest();
     CurrCom = EComm.Service;
     TrTimeoutRX.Stop();
     TrTimeoutRX.Start();
 }
Ejemplo n.º 2
0
        private void RecieveDev(object sender, EventArgs e)
        {
            byte[] btaBufRX  = (byte[])sender;
            int    iPosRight = 0;

            btaBufRX = Conv7to8byt(btaBufRX, Recieve.RecieveByte);
            OutMess($"RX: {Global.ByteToStr(btaBufRX, 0, Recieve.RecieveByte)}" //(btaBufRX, 0, Recieve.RecieveByte, Base64FormattingOptions.InsertLineBreaks)
                    , " ");                                                     //Convert.ToBase64String

            int iPosLeft = Array.FindIndex(btaBufRX, s => s == '(');

            if (iPosLeft > 0)
            {
                iPosRight = Array.FindIndex(btaBufRX, s => s == ')');
                if ((iPosRight > iPosLeft + 1) == false)
                {
                    OutMess("Bad recieve", " ");
                    return;
                }
            }
            else
            {
                return;
            }
            // CRC пока не считаем
            if (CurrCom == EComm.Service && btaBufRX[0] == (byte)'s' && btaBufRX[1] == (byte)'e')               // Получение ответа на Reading of service data (heading)
            {
                OutMess(EComm.Отправка_заголовка.ToString(), " ");
                for (int i = iPosRight; i < iPosRight + SIZE_PAS; i++)
                {
                    btaBufRX[i] = (byte)'3';
                }
                ushort usCRC      = CRC(btaBufRX, iPosLeft, iPosRight - iPosLeft + SIZE_PAS);
                string asCRCascii = CRCtoASCII(usCRC);
                string asHeadWr   = /*asPauseFF + */ $"/?{asAddr}{asFirstComm}{asCRCascii + asCRCascii[3]}!\r\n";
                byte[] btaHead    = Global.EncodingCurr.GetBytes(asHeadWr);               // ASCIIEncoding.ASCII UTF8Encoding.UTF8.
                InitBufTX(Global.Conv8n1To7e1(btaHead, btaHead.Length));
                CurrCom = EComm.Отправка_заголовка;
                OutMess(asHeadWr, " ");
                SendComm();
            }
            else if (CurrCom == EComm.Отправка_заголовка && btaBufRX[0] == (byte)'m' && btaBufRX[1] == (byte)'s')              // Получение ответа на заголовок записи параметра
            {
                OutMess(EComm.Запись_данных.ToString(), " ");
                string asW0  = /*asPauseFF + */ $"W1({asUser}\tK200212)";          //{}!\r\n";asFirstComm
                byte[] btaW0 = ASCIIEncoding.ASCII.GetBytes(asW0);                 // Global.StrToBytes
                ushort usCRC = CRC(btaW0, 0, btaW0.Length);
                asW0 += CRCtoASCII(usCRC) + "!\r\n";
                //OutMess (asW0, " ");
                btaW0 = System.Text.Encoding.ASCII.GetBytes(asW0);                 //Global.StrToBytes ASCIIEncoding.ASCII
                InitBufTX(Global.Conv8n1To7e1(btaW0, btaW0.Length));               // Размер
                CurrCom = EComm.Запись_данных;
                OutMess(asW0, " ");
                SendComm();
            }
            else
            {
                if (CurrCom == EComm.Запись_данных)
                {
                    if (btaBufRX[0] == (byte)'m' && btaBufRX[1] == (byte)'w' && btaBufRX[3] == 'W')                     // Если запись успешна
                    {
                        OutMess("запись успешна", " ");
                    }
                    else
                    {
                        OutMess($"{btaBufRX}", " ");
                    }
                }
            }
        }