command Unup(myreceivebitobj funobj)
        {
            if (DT == DataType.custom)
            {
                int bytesRead = alldata.Length;

                if (bytesRead == 0)
                {
                    return(null);
                }
                byte[] tempbtye = new byte[bytesRead];

                Array.Copy(alldata, tempbtye, tempbtye.Length);
                funobj?.Invoke(0x0, tempbtye, this);

                alldata = new byte[0];
                command command = new command();
                command.comand = 0;
                command.data   = tempbtye;
                return(command);
            }

            else if (DT == DataType.bytes)
            {
                return(Unupbyte(funobj));
            }
            return(null);
        }
        public command Receives(myreceivebitobj funobj)
        {
            //var task = Task.Run(() =>
            //{
            //    var w = new SpinWait();
            DateTime dt = new DateTime();

            while (isok)
            {
                try
                {
                    if (tcpc.Client == null)
                    {
                        return(null);
                    }
                    int bytesRead = tcpc.Client.Available;
                    if (bytesRead > 0)
                    {
                        byte[] tempbtye = new byte[bytesRead];
                        try
                        {
                            timeout = DateTime.Now;
                            dt      = DateTime.Now;
                            tcpc.Client.Receive(tempbtye);

                            byte[] tempp = new byte[alldata.Length];
                            alldata.CopyTo(tempp, 0);
                            int lle = alldata.Length;
                            bytesRead = tempbtye.Length;
                            byte[] temp = new byte[lle + bytesRead];
                            Array.Copy(alldata, 0, temp, 0, lle);
                            Array.Copy(tempbtye, 0, temp, lle, bytesRead);
                            alldata = temp;
                        }
                        catch (Exception ee)
                        {
                            throw ee;
                            // ErrorMge(22, ee.Message);
                        }
                    }


                    if (alldata.Length > 3)
                    {
                        var outcommand = Unup(funobj);

                        if (outcommand != null)
                        {
                            DateTime dt2 = DateTime.Now;
                            //  Console.WriteLine("TcpSynClient:" + (dt2 - dt).TotalMilliseconds);
                            return(outcommand);
                        }
                        else
                        {
                        }
                    }
                    else
                    {
                        System.Threading.Thread.Yield();
                    }


                    try
                    {
                        TimeSpan ts = DateTime.Now - timeout;
                        if (ts.TotalSeconds > mintimeout)
                        {
                            Isline = false;

                            break;
                        }
                    }
                    catch (Exception ee)
                    {
                        throw ee;
                    }
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            tcpc.Close();
            Isline = false;
            return(null);
            // });
            //return null;
        }
        command Unupbyte(myreceivebitobj funobj)
        {
            try
            {
lb0x99:
                int bytesRead = alldata.Length;

                if (bytesRead == 0)
                {
                    return(null);
                }

                byte[] tempbtye = new byte[bytesRead];

                Array.Copy(alldata, tempbtye, tempbtye.Length);


                if (bytesRead > 2)
                {
                    int a = tempbtye[1];
                    if (a == 0)
                    {
                    }
                    if (bytesRead > 4 + a)
                    {
                        int len = 0;

                        byte[] bbcrc = new byte[4 + a];
                        Array.Copy(tempbtye, 0, bbcrc, 0, 4 + a);
                        if (CRC.DataCRC(ref bbcrc, 4 + a))
                        {
                            byte[] bb = new byte[a];
                            Array.Copy(tempbtye, 2, bb, 0, a);
                            len = ConvertToInt(bb);
                        }
                        else
                        {
                            byte[] temps = new byte[tempbtye.Length - 1];
                            Array.Copy(tempbtye, 1, temps, 0, temps.Length);
                            alldata = temps;
                            //return;
                            goto lb0x99;
                        }
                        try
                        {
                            if ((len + 4 + a) > tempbtye.Length)
                            {
                                return(null);
                            }
                            else if (tempbtye.Length > (len + 4 + a))
                            {
                                byte[] temps = new byte[tempbtye.Length - (len + 4 + a)];
                                Array.Copy(tempbtye, (len + 4 + a), temps, 0, temps.Length);
                                alldata = temps;
                                //return;
                                //  goto lb0x99;
                            }
                            else if (tempbtye.Length == (len + 4 + a))
                            {
                                alldata = new byte[0];
                            }
                        }
                        catch (Exception e)
                        {
                            // ErrorMge?.Invoke(3, e.StackTrace + "unup001:" + e.Message + "2 + a" + 2 + a + "---len" + len + "--tempbtye" + tempbtye.Length);
                            alldata = new byte[0];
                        }
                        try
                        {
                            byte[] bs = new byte[len];
                            Array.Copy(tempbtye, (4 + a), bs, 0, bs.Length);
                            if (tempbtye[0] == 0x99)
                            {
                                return(null);
                            }

                            funobj?.Invoke(tempbtye[0], bs, this);
                            command command = new command();
                            command.comand = tempbtye[0];
                            command.data   = bs;
                            if (command.comand == 0)
                            {
                            }
                            return(command);
                        }
                        catch (Exception e)
                        {
                            //  ErrorMge?.Invoke(3, e.StackTrace + "unup122:" + e.Message);
                            alldata = new byte[0];
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception e)
            {
                alldata = new byte[0];
                return(null);
            }
            return(null);
        }