private void Query(SusceptorExportPacket packet)
        {
            if (client.Connected)
            {
                try
                {
                    {
                        if (stream.CanWrite)
                        {
                            byte[] returnbyte = packet.ToBytes();
                            stream.Write(returnbyte, 0, returnbyte.Length);
                            EMx.Log.Info("SusceptorExportServer Stream sended " + packet);
                        }
                        else
                        {
                            EMx.Log.Error("SusceptorExportServer Stream cannot write " + packet);
                        }

                        Thread.Sleep(100);

                        if (stream.CanRead)
                        {
                            double   timeouttime = 30000;
                            DateTime now         = DateTime.Now;

                            List <byte> DataArray    = new List <byte>();
                            byte        prevlastbyte = 0xFF;
                            byte        lastbyte     = 0xFF;

                            while ((DateTime.Now - now).TotalMilliseconds < timeouttime)
                            {
                                if ((prevlastbyte == (byte)'\r') && (lastbyte == (byte)'\n'))
                                {
                                    break;
                                }
                                else
                                {
                                    prevlastbyte = lastbyte;
                                    lastbyte     = (byte)stream.ReadByte();
                                    DataArray.Add(lastbyte);
                                    if (DataArray.Count > 10000)
                                    {
                                        EMx.Log.Info("SusceptorExportClient endchar none");
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                catch (System.IO.IOException except)
                {
                    EMx.Log.Error("SusceptorExportServer client Timeout " + except.ToString());
                }
                catch (Exception except)
                {
                    EMx.Log.Error("SusceptorExportServer client Exception" + except.ToString());
                }
            }
        }
예제 #2
0
        public void ParseStream(string str)
        {
            try
            {
                lastPacket = new SusceptorExportPacket();
                EMx.Log.Info("SusceptorExportClient Stream received " + str);
                lastPacket.Parse(str);

                switch (lastPacket.Commnad)
                {
                case SusceptroExportCommands.None:
                    EMx.Log.Error("LCLIENT ParseStream NONE " + str);
                    break;

                case SusceptroExportCommands.Error:
                    EMx.Log.Error("LCLIENT ParseStream Error " + str);
                    break;

                default:
                    OnSusceptorEvent(lastPacket);
                    break;
                }
            }
            catch (Exception except)
            {
                EMx.Log.Error("LCLIENT ParseStream ERRERRERR " + except.ToString());
            }
        }
        public override void LoadSusceptor(string path)
        {
            SusceptorExportPacket packet = new SusceptorExportPacket();

            packet.Commnad = SusceptroExportCommands.LoadSusceptor;
            packet.Args    = new string[] { path };
            Query(packet);
        }
        public override void SetItem(string item)
        {
            SusceptorExportPacket packet = new SusceptorExportPacket();

            packet.Commnad = SusceptroExportCommands.SetItem;
            packet.Args    = new string[] { item };
            Query(packet);
        }
        public override void SetAverageOffsetRange(double rngmin, double rngmax)
        {
            SusceptorExportPacket packet = new SusceptorExportPacket();

            packet.Commnad = SusceptroExportCommands.SetAverageOffsetRange;
            packet.Args    = new string[] { rngmin.ToString(), rngmax.ToString() };
            Query(packet);
        }
        public override void Close(string msg)
        {
            SusceptorExportPacket packet = new SusceptorExportPacket();

            packet.Commnad = SusceptroExportCommands.Close;
            packet.Args    = new string[0];
            Query(packet);
        }
예제 #7
0
 private void OnSusceptorEvent(SusceptorExportPacket packet)
 {
     SusceptorExportEvent?.Invoke(packet);
 }