blah blah blah is here! blah blah » Close

up0down
link

Hi All,

I have an issue I want to use the serial ports DataRecieved Event to over 6 six serial ports,
I in the past only have used it on one. The procedure of defining and attaching them I know what I'm not sure of is

public static SerialDataREcievedEventHandler SerialDataReceivedEventHandlerATE = 
new SerialDataReceivedEventHandler(ATEComPort.DataRecieved);


ATEComPort.DataRecieved += SerialDataReceivedEventHandlerATE;


is fine but how do I use

internal void DataReceived(object sender, SerialDataReceivedEventArgs e)
{
//blah
}

can it be
internal void DataReceivedATE(object sender, SerialDataReceivedEventArgs e)
{
//blah
}
internal void DataReceivedDUT(object sender, SerialDataReceivedEventArgs e)
{
//blah
}

for all six device? or am I loosing the plot!

Glenn

last answered one year ago

1 answers

up0down
link

If you have six serial ports and you want each one to have its own DataReceived eventhandler, then you'd typically proceed like this:

ATEComPort.DataRecieved += DataReceivedATE;
DUTComPort.DataReceived += DataReceivedDUT;
// and so on for the other four

internal void DataReceivedATE(object sender, SerialDataReceivedEventArgs e)
{
// blah
}

internal void DataReceivedDUT(object sender, SerialDataReceivedEventArgs e)
{
// blah
}

GlennP
329

No, I was trying to get seperate handlers for all six. When you say issues with the DataReceived event it seems like I might have experienced them before. Like the PC slowing to crawling speed?? Glenn

vulpes
17279

OK, I've edited my answer to do it on that basis. The main issue with the DataReceived eventhandler is that you can't be sure that it will fire for each byte received and so need to be alert to that when reading the buffer. I can't really think of any reason why it would slow down the UI or the PC itself, given that it's fired on a separate thread.

Feedback