I'm trying read data of RFID scanner using Silverlight4. I know I can do so as Silverlight4 supports reading client COM ports in OOB mode and using Elevated permissions.
RFID scanner works fine when I read the data by simple win app however when I did the same with a silverlight app I get an exception when Datareceived event is called I have no clue why this happen. below is the code I have
P.S: I'm using the below library to access serialports from silverlight https://interopcom.codeplex.com/
private void button1_Click(object sender, RoutedEventArgs e)
{
if (Application.Current.IsRunningOutOfBrowser /*&& Application.Current.HasElevatedPermissions*/)
{
SerialPort sp1 = new SerialPort("COM7");
sp1.BaudRate = 9600;
sp1.Parity = Parity.None;
sp1.StopBits = StopBits.One;
sp1.DataBits = 8;
sp1.Handshake = Handshake.None;
sp1.DataReceived += new SerialDataReceivedEventHandler(sp1_DataReceived);
sp1.Open();
MessageBox.Show("opened");
}
}
private static void sp1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
SerialPort sp2 = sender as SerialPort;
MessageBox.Show(sp2.ReadLine());
sp2.Close();
MessageBox.Show("closed");
}