0

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");
    }

enter image description here enter image description here

Roman R.
  • 68,205
  • 6
  • 94
  • 158
Ahmed Fayed
  • 141
  • 2
  • 10
  • Don't display message boxes from worker threads. Don't call the SerialPort.Close() method in one of its event. Perhaps the basic issue is that you just quit programming too soon. – Hans Passant May 07 '15 at 13:40
  • even if I do I get the same issue . I tried empty event and I get the same error when I scan the cards. – Ahmed Fayed May 10 '15 at 09:10

0 Answers0