Click here to Skip to main content
15,893,486 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hopefully someone out there can help me with this problem.
Background: I am writing a Windows Forms program in C# to collect and process data from an external signal digitizer. The digitizer sends the data across TCP, where I collect them in a circular buffer (thanks to Karam Chandrabose for the buffer class).
I created an event in the queue class to fire when a pulse structure is added to the queue so I can remove it and display it on four strip charts in the main form.

My problem is that I don't know how to get the data from the event method to the charts. I used the same namespace in the queue class as I have for the main form. Why do I get a "does not exist in the current context" error?

I am still fairly new to C# (and delegates/events), so my searches for the error message is confusing to me...especially MSDN.

Any help will be appreciated. Thanks in advance.

Here is the portion of code I am having trouble with:

In Form1.cs:
From the point where the data is received at the TCP port:

C#
namespace RealTimeClient
{
        ...

        /// <summary>
        /// Message received from PdwClient
        /// </summary>
        /// <param name="socket">the socket</param>
        /// <param name="bytes">the message</param>
        void m_PdwClient_MessageReceived(Socket socket, byte[] bytes)
        {
            Serializer ser = new Serializer();
            currentPdw = ser.ReadStruct<PdwWord>(socket, bytes);
            data = new PdwData();
            ProcessPdw(data, currentPdw);
        }

        /// <summary>
        /// ProcessPdw: extract data from message into PdwData structs
        /// </summary>
        /// <param name="data">the output struct</param>
        /// <param name="pdw">the struct from the digitizer</param>
        public void ProcessPdw(PdwData data, PdwWord pdw)
        {
            ...

            //
            // The data is extracted from the message here...
            //
            // add the PdwData struct to the queue
            CircularBuffer.Enqueue(data);
            // generate the event to remove it from the queue and
            // add it to the chart
            QueueCB.QueueAddedEventArgs e =
                new QueueCB.QueueAddedEventArgs(CircularBuffer);
            PdwAddedNotify(this, e);
        }

        public event QueueCB.QueueAddedEventHandler PdwAddedNotify;

        /// <summary>
        /// OnPdwAddedNotify
        /// </summary>
        protected virtual void OnPdwAddedNotify(QueueCB.QueueAddedEventArgs e)
        {
            if (PdwAddedNotify != null)
                PdwAddedNotify(this, e);
        }

        ...
}


In CircularBuffer.cs

C#
namespace RealTimeClient
{
    public class QueueCB : IEnumerable
    {
        public class QueueAddedEventArgs : EventArgs
        {
            /// <summary>
            /// Constructor
            /// </summary>
            /// <param name="pdw"></param>
            public QueueAddedEventArgs(QueueCB cb)
            {
                Form1.PdwData pdw = (Form1.PdwData)cb.Dequeue();
                // Append new values  //
//
// This is where I get the error message "Pesgo1 does not exist in the current context"
// Pesgo1 is the strip chart in Form1.cs
//
                Api.PEvsetW(Pesgo1.PeSpecial.HObject,
                            DllProperties.AppendYData,
                            pdw.Amplitude,
                            1);
                Api.PEvsetW(Pesgo1.PeSpecial.HObject,
                            DllProperties.AppendXData,
                            pdw.TimeOfArrival,
                            1);
                // Update image and force paint //
                Pesgo1.PeFunction.ReinitializeResetImage();
                Pesgo1.Refresh();
            }
        }

        public delegate void QueueAddedEventHandler(object sender, QueueAddedEventArgs e);

        ...
    }
}


Admittedly, I am very weak on events and how to interact with them. I'm not even sure if I put the code in the right places.
The idea was to generate an event to trigger the removal of a PdwData struct from the queue every time one was added, if possible.
I think I will need the queue because the data could possibly come in at a rate of >500000 per second. To do this, many of the messages will have multiple data points included. The queue could catch up during 'quiet times'. I cannot miss any pulse data.

If you need more info, please let me know.

Thanks
Dave
Posted
Updated 9-Aug-12 23:19pm
v3
Comments
AmitGajjar 9-Aug-12 2:38am    
can you improve question with some code ?
Philip Stuyck 9-Aug-12 3:09am    
And an indication on which line the error is occurring.

1 solution

There are a whole load of possible reasons here are just a few:
1) You have your queue class in a different project, and you have not referenced the project in the form. Add a reference.
2) You have not included a using statement to access the namespace the queue is in.
3) The queue is private, protected, or internal, or a method is private, protected or internal and you are trying to access it from outside.
4) You are trying to access an instance member of the queue class statically.
5) You can't spell! :laugh:

If your problem isn't in this list, we will need to see the code fragment causing the problem, and an indication of which line is reported as an error.
 
Share this answer
 
Comments
Volynsky Alex 11-Aug-12 3:45am    
Nice answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900