Exemplo n.º 1
0
        public void Connect(string ip, int port, int timeout = 2000)
        {
            watch = new WinWatch("wDaq" + ip, "wDaq" + ip);
            trace = new WinTrace("tDaq" + ip, "tDaq" + ip);

            tcp = new TcpClient();
            try
            {
                var result = tcp.BeginConnect(ip, port, null, null);
                tcp.ReceiveTimeout = 5000;
                bool success = result.AsyncWaitHandle.WaitOne(timeout, true);
                if (!success)
                {
                    throw new DaqException("Connect Failed - WaitOne Failed");
                }

                if (!tcp.Connected)
                {
                    throw new DaqException("Connect Failed - Not Established");
                }

                //tcp.LingerState = new LingerOption(true, 0);
                //tcp.NoDelay = true;
                ns = tcp.GetStream();
                qs = new ByteQueuedStream(ns);
                WriteDebug("Connected");
            }
            catch (Exception)
            {
                tcp.Close();
                throw;
            }
        }
Exemplo n.º 2
0
 private void butCreateWindow_Click(object sender, System.EventArgs e)
 {
     myWinTrace = new WinTrace("MyWINID", "My trace window");
     butDisplayWindow.Enabled = true;
     butHelloWin.Enabled      = true;
     butSaveWinToText.Enabled = true;
     butSaveWinToXml.Enabled  = true;
     butLoadWinXml.Enabled    = true;
 }
Exemplo n.º 3
0
 protected void butCreateWindow_Click(object sender, EventArgs e)
 {
     myWinTrace = new WinTrace("MyWINID", "My trace window");
     butDisplayWindow.Enabled       = true;
     butHelloWin.Enabled            = true;
     butSaveWinToText.Enabled       = true;
     butSaveWinToXml.Enabled        = true;
     butLoadWinXml.Enabled          = true;
     Session.Contents["myWinTrace"] = myWinTrace;
 }
Exemplo n.º 4
0
    //--------------------------------------------------------------------------------------------

    protected void butDisplayWindow_Click(object sender, EventArgs e)
    {
        myWinTrace = (WinTrace)Session.Contents["myWinTrace"];
        if (myWinTrace == null)
        {
            return;
        }

        myWinTrace.DisplayWin();
    }
Exemplo n.º 5
0
    //--------------------------------------------------------------------------------------------

    protected void butHelloWin_Click(object sender, EventArgs e)
    {
        myWinTrace = (WinTrace)Session.Contents["myWinTrace"];
        if (myWinTrace == null)
        {
            return;
        }

        myWinTrace.Debug.Send("Hello", "Can be used to store exceptions, for examples");
    }
Exemplo n.º 6
0
    //--------------------------------------------------------------------------------------------

    protected void butSaveWinToText_Click(object sender, EventArgs e)
    {
        myWinTrace = (WinTrace)Session.Contents["myWinTrace"];
        if (myWinTrace == null)
        {
            return;
        }

        myWinTrace.SaveToTextfile("c:\\log2.txt");
    }
Exemplo n.º 7
0
    //--------------------------------------------------------------------------------------------

    protected void butLoadWinXml_Click(object sender, EventArgs e)
    {
        myWinTrace = (WinTrace)Session.Contents["myWinTrace"];
        if (myWinTrace == null)
        {
            return;
        }

        myWinTrace.LoadXml("c:\\log2.xml");
    }
Exemplo n.º 8
0
 private void butCreateWinTrace_Click(object sender, EventArgs e)
 {
     myWinTrace                 = new WinTrace("MyWINID", "My trace window");
     butDisplayWin.Enabled      = true;
     butHelloToWintrace.Enabled = true;
     butSaveWinToTxt.Enabled    = true;
     butSaveWinToXml.Enabled    = true;
     butClearWin.Enabled        = true;
     butWinLoadXml.Enabled      = true;
     butCloseWin.Enabled        = true;
 }
Exemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:System.Object"/> class.
        /// </summary>
        static Trace()
        {
#if DEBUG || DEVELOP
            TTrace.Options.SendMode = SendMode.WinMsg;
            TTrace.Options.SendInherited = true;

            var processName = Process.GetCurrentProcess().ProcessName;

            Default = Default ?? new WinTrace(processName, processName);
            Default.ClearAll();
#endif
        }
Exemplo n.º 10
0
 private void butMulticolTest_Click(object sender, System.EventArgs e)
 {
     if (MultiColTrace == null)
     {
         MultiColTrace = new WinTrace("MCOL", "MultiCol trace window");
         MultiColTrace.SetMultiColumn(1);  // must be called before calling setColumnsTitle
         MultiColTrace.SetColumnsTitle("col1 \t col2 \t col3");
         MultiColTrace.SetColumnsWidth("100:20:80 \t 200:50 \t 100");
         MultiColTrace.DisplayWin();
     }
     MultiColTrace.Debug.Send("1 \t 2 \t 3");
 }
Exemplo n.º 11
0
        //------------------------------------------------------------------------------

        private void butCreateWinTrace_Click(object sender, RoutedEventArgs e)
        {
            _myWinTrace                  = new WinTrace("MyWINID", "My trace window");
            ButDisplayWin.IsEnabled      = true;
            ButHelloToWintrace.IsEnabled = true;
            ButSaveWinToTxt.IsEnabled    = true;
            ButSaveWinToXml.IsEnabled    = true;
            ButClearWin.IsEnabled        = true;
            ButWinLoadXml.IsEnabled      = true;
            ButCloseWin.IsEnabled        = true;
            ButSetLocalLog.IsEnabled     = true;
        }
Exemplo n.º 12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:System.Object"/> class.
        /// </summary>
        static Trace()
        {
#if DEBUG || DEVELOP
            TTrace.Options.SendMode      = SendMode.WinMsg;
            TTrace.Options.SendInherited = true;

            var processName = Process.GetCurrentProcess().ProcessName;

            Default = Default ?? new WinTrace(processName, processName);
            Default.ClearAll();
#endif
        }
Exemplo n.º 13
0
 protected void butMulticolTest_Click(object sender, EventArgs e)
 {
     MultiColTrace = (WinTrace)Session.Contents["MultiColTrace"];
     if (MultiColTrace == null)
     {
         MultiColTrace = new WinTrace("MCOL", "MultiCol trace window");
         MultiColTrace.SetMultiColumn(1);  // must be called before calling setColumnsTitle
         MultiColTrace.SetColumnsTitle("col1 \t col2 \t col3");
         MultiColTrace.SetColumnsWidth("100:20:80 \t 200:50 \t 100");
         MultiColTrace.DisplayWin();
         Session.Contents["MultiColTrace"] = MultiColTrace;
     }
     MultiColTrace.Debug.Send("1 \t 2 \t 3");
 }
Exemplo n.º 14
0
        //------------------------------------------------------------------------------

        /// <summary>
        /// Initialise the plugin
        /// </summary>
        public void Start()
        {
            // create a window and ask to receive timer, action and onBeforeDelete events
            PlugTraces = new WinTrace("CSHARP", "CSharp Plugin9");
            PlugTraces.DisplayWin();
            PlugTraces.LinkToPlugin(PlugName,
                                    TraceConst.CST_PLUG_ONACTION +
                                    TraceConst.CST_PLUG_ONBEFOREDELETE +
                                    TraceConst.CST_PLUG_ONTIMER);

            // disable the  LogFile label
            PlugTraces.DisableResource(TraceConst.CST_ACTION_LABEL_LOGFILE);

            // add a menu to the 'window' menu
            PlugTraces.CreateResource(100, TraceConst.CST_RES_MENU_WINDOW, 0, "My CSharp Plug");

            // add a menu to the 'action' menu
            PlugTraces.CreateResource(101, TraceConst.CST_RES_MENU_ACTION, 0, "My CSharp action Plug");

            // add a label on right, autosize (0)
            PlugTraces.CreateResource(102, TraceConst.CST_RES_LABEL_RIGHT, 0, "My label");

            // add a button on right (100 pixels)
            PlugTraces.CreateResource(103, TraceConst.CST_RES_BUT_RIGHT, 100, "STOP");

            // add a label on left, 100 pixels
            PlugTraces.CreateResource(104, TraceConst.CST_RES_LABEL_LEFT, 100, "My status");

            TraceNodeEx node;

            node         = new TraceNodeEx(PlugTraces.Debug);
            node.LeftMsg = "Actions";
            node.Id      = "ActionsNode";
            ActionNodes  = node.Send();

            node              = new TraceNodeEx(PlugTraces.Debug);
            node.LeftMsg      = "Deleted Nodes";
            node.Id           = "BeforeDeletes";
            BeforeDeleteNodes = node.Send();

            node         = new TraceNodeEx(PlugTraces.Debug);
            node.LeftMsg = "Timer";
            node.Id      = "Timer";
            Timer        = node.Send();

            PlugTraces.Debug.Send("Sample CSharp 10.1 Plugin started");
        }
Exemplo n.º 15
0
        //------------------------------------------------------------------------------

        private void MulticolBut_Click(object sender, RoutedEventArgs e)
        {
            if (MultiColTrace == null)
            {
                MultiColTrace = new WinTrace("MCOL", "MultiCol trace window");
                MultiColTrace.SetMultiColumn(1); // must be called before calling setColumnsTitle
                MultiColTrace.SetColumnsTitle("col1 \t col2 \t col3");
                MultiColTrace.SetColumnsWidth("100:20:80 \t 200:50 \t 100");
                MultiColTrace.DisplayWin();
                // set local log
                // 3, Local log is disabled
                // 4, Local log enabled. No size limit.  No effect in silverlight 2
                // 5, Local log enabled. A new file is create each day (CCYYMMDD is appended to the filename). No effect in silverlight 2
                MultiColTrace.SetLogFile("c:\\MultiCol.xml", 4); // will be inored by the API : writing to local file is not allowed in silberlight.
            }
            MultiColTrace.Debug.Send("1 \t 2 \t 3");
        }
Exemplo n.º 16
0
        //------------------------------------------------------------------------------

        private void MulticolBut_Click(object sender, RoutedEventArgs e)
        {
            if (_multiColTrace == null)
            {
                _multiColTrace = new WinTrace("MCOL", "MultiCol trace window");
                _multiColTrace.SetMultiColumn(1); // must be called before calling setColumnsTitle
                _multiColTrace.SetColumnsTitle("col1 \t col2 \t col3");
                _multiColTrace.SetColumnsWidth("100:20:80 \t 200:50 \t 100");
                _multiColTrace.DisplayWin();
                // set local log
                // 3, Local log is disabled
                // 4, Local log enabled. No size limit.
                // 5, Local log enabled. A new file is create each day (CCYYMMDD is appended to the filename)
                _multiColTrace.SetLogFile("c:\\MultiCol.xml", 4);
            }
            _multiColTrace.Debug.Send("1 \t 2 \t 3");
        }
Exemplo n.º 17
0
        /// <inheritdoc/>
        public void CreateTraceWindow(
            string key,
            string title)
        {
            if (!IsEnabled)
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentException(DevConstants.ValueCannotBeNullOrWhitespace, nameof(key));
            }
            if (string.IsNullOrWhiteSpace(title))
            {
                throw new ArgumentException(DevConstants.ValueCannotBeNullOrWhitespace, nameof(title));
            }

            if (!_traceWindowDictionary.TryGetValue(key, out var traceWindow))
            {
                traceWindow = new WinTrace(key, title);
                _traceWindowDictionary.Add(key, traceWindow);
            }
        }
Exemplo n.º 18
0
        //------------------------------------------------------------------------------

        /// <summary>
        /// Initialise the plugin
        /// </summary>
        public void Start(string strParameter)
        {
            //lowTrace("        WebSockPlugin Start\n") ;

            if (string.IsNullOrEmpty(strParameter))
            {
                strParameter = "";
            }

            try
            {
                var paramList = strParameter.Split(',');
                foreach (var keyValue in paramList)
                {
                    var keyValueList = keyValue.Split('=');

                    if (keyValueList.Length != 2)
                    {
                        throw new Exception($"{PlugName} : Wrong parameter : <{strParameter}> / <{keyValue}>");
                    }

                    var key   = keyValueList[0].Trim();
                    var value = keyValueList[1].Trim();
                    if (string.Compare(key, "WebSocketHost", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        webSocketHost = value;
                    }
                    else if (string.Compare(key, "WebSocketPort", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        webSocketPort = int.Parse(value);
                    }
                    else if (string.Compare(key, "ViewerSocketHost", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        viewerSocketHost = value;
                    }
                    else if (string.Compare(key, "ViewerSocketPort", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        viewerSocketPort = int.Parse(value);
                    }
                }
            }
            catch (Exception)
            {
                TTrace.Error.Send($"{PlugName} : Wrong parameters : <{strParameter}>");
                TTrace.Error.Send("parameters format : WebSocketHost = 0.0.0.0, WebSocketPort = 8091, ViewerSocketHost = 127.0.0.1, ViewerSocketPort = 8090");
                TTrace.Error.Send("Select Plugin, click stop button, change parameters ans click start button");
                throw;
            }

            TTrace.Options.SendMode   = SendMode.Socket;
            TTrace.Options.SocketHost = viewerSocketHost;
            TTrace.Options.SocketPort = viewerSocketPort;

            // create a window and ask to receive timer (ignore action and onBeforeDelete events)
            PlugTraces = new WinTrace("_", "");  // match the default Wintrace. No new windows is created

            // add a hyperlink label on left, 100 pixels
            PlugTraces.CreateResource(labelWinsockResourceId, TraceConst.CST_RES_LABELH_LEFT, 100, "Web Socket");

            PlugTraces.LinkToPlugin(PlugName,
                                    TraceConst.CST_PLUG_ONACTION
                                    //+TraceConst.CST_PLUG_ONBEFOREDELETE
                                    //+TraceConst.CST_PLUG_ONTIMER
                                    );

            //TTrace.Debug.Send($"WebsockPlugin started with param {strParameter}") ;

            FleckLog.Level = LogLevel.Error;

            // FlecK WebSocketServer
            server = new WebSocketServer($"ws://{webSocketHost}:{webSocketPort}");
            server.Start(socket =>
            {
                socket.OnOpen = () =>
                {
                    activeConnection++;
                };
                socket.OnClose = () =>
                {
                    activeConnection--;
                    closedConnection++;
                };
                //socket.OnMessage = message =>
                //{
                //    PlugTraces.Debug.Send($"OnMessage", message);
                //};
                socket.OnBinary = buffer =>
                {
                    messageCount++;
                    //PlugTraces.Debug.Send($"Message, Len = {buffer.Length}");
                    //PlugTraces.SetTextResource(102, $"WebSock {buffer.Length}");
                    _buffToSend = buffer;
                    SendMessageToSocket();
                };
            });
        }
Exemplo n.º 19
0
        public static DaqDataPacket RecvDataPacket(DaqClient parent, ByteQueuedStream ns, string commandNameForLog, WinTrace trace = null)
        {
_START:
            int invalidHeaderCount = 0;

            byte[] firstInvalidHeader = null;
            while (IsValidHeader(parent, ns.PullLast(4)) == DaqHeaderType.Invalid)
            {
                ns.PopFrontByte();
                if (invalidHeaderCount == 0)
                {
                    firstInvalidHeader = ns.byteQueue.ToArray();
                }
                invalidHeaderCount++;
            }

            var header    = ns.PopFront(4);
            var type      = (DaqDataType)header[0];
            var wordCount = (ushort)(BitConverter.ToUInt16(header, 2) * 2);

            if (trace != null && type == DaqDataType.DAQ_DATA)
            {
                trace.Send("Daq DATA Packet - wordCount:" + wordCount);
            }

            int readSize = 0;

            if (type == DaqDataType.DAQ_DATA)
            {
                readSize = 1024;
            }
            else if (type == DaqDataType.GAP_DATA)
            {
                //if (wordCount == 12)
                readSize = 48 - 4;
            }
            else if (type == DaqDataType.SYNC_AMP)
            {
                readSize = 2;
            }
            else if (Enum.IsDefined(typeof(DaqCmdType), (ushort)type))
            {
                readSize = DaqCommand.DefaultPacketSize;
                ns.PullLast(readSize);
                var data_ = ns.PopFront(readSize);
                ns.RevertFront(header);
                ns.RevertFront(data_);
                ns.PopFrontByte();
                goto _START;
            }
            else
            {
                ns.RevertFront(header);
                ns.PopFrontByte();
                goto _START;
            }

            ns.PullLast(readSize);
            var data = ns.PopFront(readSize);

            if (IsValidHeader(parent, ns.PullLast(4)) == DaqHeaderType.Invalid)
            {
                Debug.WriteLine("====================");
                ns.RevertFront(header);
                ns.RevertFront(data);
                ns.PopFrontByte();
                goto _START;
            }

            //Debug.WriteLine(" " + type + "," + invalidHeaderCount);
            //if(invalidHeaderCount != 0)
            //    Debug.WriteLine(" " + type + "," + invalidHeaderCount + "," + firstInvalidHeader.Length);
            return(new DaqDataPacket {
                DataType = type, Header = header, Bytes = data
            });
        }
Exemplo n.º 20
0
 public WintraceWrapper(string id, string name)
 {
     m_trace = new WinTrace(id, name);
     m_trace.ClearAll();
 }
Exemplo n.º 21
0
 //--------------------------------------------------------
 private void MulticolBut_Click(object sender, EventArgs e)
 {
     if (MultiColTrace == null)
     {
         MultiColTrace = new WinTrace("MCOL", "MultiCol trace window");
         MultiColTrace.SetMultiColumn(1);  // must be called before calling setColumnsTitle
         MultiColTrace.SetColumnsTitle("col1 \t col2 \t col3");
         MultiColTrace.SetColumnsWidth("100:20:80 \t 200:50 \t 100");
         MultiColTrace.DisplayWin();
         // set local log
         // 3, Local log is disabled
         // 4, Local log enabled. No size limit.
         // 5, Local log enabled. A new file is create each day (CCYYMMDD is appended to the filename)
         MultiColTrace.SetLogFile("c:\\MultiCol.xml", 4);
     }
     MultiColTrace.Debug.Send("1 \t 2 \t 3");
 }
Exemplo n.º 22
0
 //--------------------------------------------------------
 private void butCreateWinTrace_Click(object sender, EventArgs e)
 {
     myWinTrace = new WinTrace("MyWINID", "My trace window");
     butDisplayWin.Enabled = true;
     butHelloToWintrace.Enabled = true;
     butSaveWinToTxt.Enabled = true;
     butSaveWinToXml.Enabled = true;
     butClearWin.Enabled = true;
     butWinLoadXml.Enabled = true;
     butCloseWin.Enabled = true;
     butSetLocalLog.Enabled = true;
 }
Exemplo n.º 23
0
 public WintraceWrapper(string id, string name)
 {
     m_trace = new WinTrace(id, name);
     m_trace.ClearAll();
 }
Exemplo n.º 24
0
        static int Main(string[] args)
        {
            //A TraceTool
            WinTrace myWinTrace = null;

            bool   firstTime = true;         //Don't do any work if no input stream to process
            string line;

            //Inititalize Tracing Framework for socket delivery to viewer!!
            TTrace.Options.SendMode = SendMode.Socket;

            //Process command line args
            Arguments CommandLine = new Arguments(args);

            // Look for specific arguments values and process
            // them if they exist.
            if (CommandLine["h"] != null || CommandLine["help"] != null || CommandLine["?"] != null)
            {
                usage();
                return(0);
            }

            if (CommandLine["t"] != null)
            {
                //Must be Viewer tab name
                myWinTrace = new WinTrace(CommandLine["t"], CommandLine["t"]);
            }
            else
            {
                myWinTrace = new WinTrace();
            }

            if (CommandLine["i"] != null)
            {
                //Set the host IP address
                TTrace.Options.SocketHost = CommandLine["i"];
            }

            if (CommandLine["p"] != null)
            {
                //Set the host port
                TTrace.Options.SocketPort = Convert.ToInt32(CommandLine["p"]);
            }

            //Loop while there are lines to read from the input stream

            while ((line = Console.ReadLine()) != null)
            {
                //Do once the first time
                if (firstTime)
                {
                    firstTime = false;
                    myWinTrace.Debug.Indent("===========================================================");
                }

                //pipe input stream line to log viewer
                myWinTrace.Debug.Send(line);
            }
            TTrace.Flush();
            TTrace.CloseSocket();
            return(0);
        }