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:
namespace RealTimeClient
{
...
void m_PdwClient_MessageReceived(Socket socket, byte[] bytes)
{
Serializer ser = new Serializer();
currentPdw = ser.ReadStruct<PdwWord>(socket, bytes);
data = new PdwData();
ProcessPdw(data, currentPdw);
}
public void ProcessPdw(PdwData data, PdwWord pdw)
{
...
CircularBuffer.Enqueue(data);
QueueCB.QueueAddedEventArgs e =
new QueueCB.QueueAddedEventArgs(CircularBuffer);
PdwAddedNotify(this, e);
}
public event QueueCB.QueueAddedEventHandler PdwAddedNotify;
protected virtual void OnPdwAddedNotify(QueueCB.QueueAddedEventArgs e)
{
if (PdwAddedNotify != null)
PdwAddedNotify(this, e);
}
...
}
In CircularBuffer.cs
namespace RealTimeClient
{
public class QueueCB : IEnumerable
{
public class QueueAddedEventArgs : EventArgs
{
public QueueAddedEventArgs(QueueCB cb)
{
Form1.PdwData pdw = (Form1.PdwData)cb.Dequeue();
Api.PEvsetW(Pesgo1.PeSpecial.HObject,
DllProperties.AppendYData,
pdw.Amplitude,
1);
Api.PEvsetW(Pesgo1.PeSpecial.HObject,
DllProperties.AppendXData,
pdw.TimeOfArrival,
1);
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