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);
@ 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
event.
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…
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.
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)
{
char_Display.Clear();
char_Display.CursorHome();
byte[] readData = new byte[sender.BytesToRead];
sender.Read(readData, 0, sender.BytesToRead);
char[] chars = Encoding.UTF8.GetChars(readData);
string str = new string(chars);
char_Display.PrintString(str);
switch (str)
{
case "Blue":
multicolorLed.FadeOnce(GT.Color.Red,TimeSpan.FromTicks(100000),GT.Color.Blue);
break;
case "Red":
multicolorLed.FadeOnce(GT.Color.Blue, TimeSpan.FromTicks(100000), GT.Color.Red);
break;
}
}
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");
}
@ 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.