Strange VS2012 behaviour

Ok ive got two weird things happening
The first is this
i want to subscribe to a usbserial datareceived event so I type
usbSerial.SerialLine.DataReceived += TAB TAB etc

what i should get is

usbSerial.SerialLine.DataReceived += new GT.Interfaces.Serial.DataReceivedEventHandler(SerialLine_DataReceived);

what i actually get is

usbSerial.SerialLine.DataReceived += SerialLine_DataReceived;

Just plain annoying.

the second issue is that im only getting one datarecieved event firing and no more.

Im probably going to re install everything but I would rather understand why im not getting the right intellisense?? stuff comming up.

Any pointers greatly recieved.

The line

usbSerial.SerialLine.DataReceived += SerialLine_DataReceived;

is totally correct, as long as DataReceived event and SerialLine_DataReceived function has matching signatures, which actually is the case.

Less letters. Cleaner code :slight_smile:

@ HughB -

[quote]usbSerial.SerialLine.DataReceived += SerialLine_DataReceived;
Just plain annoying.[/quote]

one person’s annoyance is another’s feature. :slight_smile:

@ HughB - Not sure but to receive more then 1 interrupt you could try to call ClearInterrupt() at the end of your interrupt handler if not already.

@ HughB - Just to give you a little background, originally the C# compiler required that you explicitly instantiate a delegate passing the target method to the constructor to add it to a Delegate.

The C# 2.0 compiler introduced the capability for the compiler to instantiate the delegate implicitly for you when ever you indicate that you are adding a method to the delegate or

This makes working with anonymous methods and subsequently lambda expressions much nicer, can you imagine having to new a delegate ever time you wanted to pass a lambda, now that would be annoying…

ok i understand
next thing is why the event isnt firing… hmmmmm

I believe the only time you need to clear the interrupts are when using an InterruptPort with level events. GHI does not support level events. Only edge events.

Definitely not with a serial port.

I haven’t played with that module. Could it be that it expects you to read the buffer to the end before it throws another event?

show up your code please!

the thing is that in vs2010 i did this lots, for example

this is from a vs2010 project that i know worked

// from program started
usbSerial.SerialLine.DataReceived += new GT.Interfaces.Serial.DataReceivedEventHandler(SerialLine_DataReceived);

 void SerialLine_DataReceived(GT.Interfaces.Serial sender, System.IO.Ports.SerialData data)
            byte[] readData = new byte[sender.BytesToRead];
            sender.Read(readData, 0, sender.BytesToRead);
            char[] chars = Encoding.UTF8.GetChars(readData);
            string str = new string(chars);
            switch (str)
                case "Blue":
                case "Red":
                    multicolorLed.FadeOnce(GT.Color.Blue, TimeSpan.FromTicks(100000), GT.Color.Red);

but in VS2012 i cant even get this to work

// from program started
 usbSerial.SerialLine.DataReceived += SerialLine_DataReceived;

 void SerialLine_DataReceived(GT.Interfaces.Serial sender, System.IO.Ports.SerialData data)
            Debug.Print("got some data");

it fires once only.

@ HughB - First, you are assuming you will read “Red” or “Blue” with one read. This will not happen. You need to do a read and then decide if you need more. bytes.

Also, please show your serial port initialization code…

@ Mike - for this test it wasnt so much about the bytes as content mainly getting the bytes in.
However I’ve found the issue… bloody dry joint on my module socket. grrrrrrrrr

Still, you are right in respect to the example. I am making the assumption i will receive a Red or Blue.

@ Mike - [quote]I believe the only time you need to clear the interrupts are when using an InterruptPort with level events. GHI does not support level events. Only edge events.[/quote]

Thanks for the information!! i was not aware of that.