Exemplo n.º 1
0
        private static HexString ReadPortIncomes()
        {
            //string bin_answer = "";
            //string txt_answer = "";
            //Thread.Sleep(150);
            int gotbytes = 0;

            try { gotbytes = Code.genr.BytesToRead; }
            catch { };
            var hexstring = new HexString();

            try
            {
                for (int i = 0; i < gotbytes; i++)
                {
                    int bit = Code.genr.ReadByte();
                    hexstring.AddByte(bit);
                    //bin_answer += bit.ToString("X2") + " ";
                    //txt_answer += ( (char)bit).ToString();
                }
            }
            catch (TimeoutException ex)
            {
                Trace.WriteLine(ex.Message);
            }
            //bin_answer = bin_answer.Trim();

            //string returnBin = bin_answer.Replace(" ", "").ToLower();
            //string returnTxt = txt_answer.ToLower();
            return(hexstring);
        }
Exemplo n.º 2
0
        private HexString ReadPortIncomes()
        {
            Thread.Sleep(200);
            int gotbytes = 0;

            Ex.Try(() =>
                   { gotbytes = Code.port.BytesToRead; });
            logger.Trace($"gotbytes={gotbytes}");
            var gotPortIncome = new HexString();

            try
            {
                for (int i = 0; i < gotbytes; i++)
                {
                    int bit = Code.port.ReadByte();
                    gotPortIncome.AddByte(bit);
                }
            }
            catch (TimeoutException ex)
            { logger.Error(ex, ex.Message); }
            catch (Exception ex)
            { logger.Error(ex, ex.Message); }

            if (!isTestAutoStart)
            {
                PublicData.write_tv("text =  " + gotPortIncome.TxtNiceDisplay);
                PublicData.write_tv("code =  " + gotPortIncome.HexNiceDisplay);
            }
            logger.Trace($"COM Read Txt: {gotPortIncome.TxtNiceDisplay}");
            logger.Trace($"COM Read Bin: {gotPortIncome.HexNiceDisplay}");
            UsePrevRead    = true;
            LastPortIncome = gotPortIncome;
            return(gotPortIncome);
        }
Exemplo n.º 3
0
        private void ReadPortIncomesAsync(string find)
        {
            SerialDataReceivedEventHandler eventName;
            var incomePortMethod = new HexString();

            eventName = (o, e) =>
            {
                int gotbytes = 0;
                Ex.Try(() =>
                       { gotbytes = Code.port.BytesToRead; });
                logger.Trace($"gotbytes={gotbytes}");
                var incomePortEvent = new HexString();
                try
                {
                    for (int i = 0; i < gotbytes; i++)
                    {
                        int bit = Code.port.ReadByte();
                        incomePortEvent.AddByte(bit);
                    }
                }
                catch (Exception ex)
                { ex.Log(); }
                if (!isTestAutoStart)
                {
                    PublicData.write_tv("text =  " + incomePortEvent.TxtNiceDisplay);
                    PublicData.write_tv("code =  " + incomePortEvent.HexNiceDisplay);
                }
                logger.Trace($"COM Read Txt: {incomePortEvent.TxtNiceDisplay}");
                logger.Trace($"COM Read Bin: {incomePortEvent.HexNiceDisplay}");
                UsePrevRead      = true;
                incomePortMethod = incomePortEvent;
            };
            try
            {
                Code.port.DataReceived += eventName;
            }
            finally
            {
                Code.port.DataReceived -= eventName;
            }
        }