How to send a WriteableBitmap over ComPort ?

52 Views Asked by At

We are updating the WriteableBitmap every 30 ms.

  private void dt_Tick(object sender, EventArgs e)
    {

        wbm.Clear();
        wbm.Blit(r, wbr, r);
        wbm.Blit(r, wbl, r);

    }

now i have to send it over a virtual com port. this should be done by a Thread.

  private void init_DataOut()
    {
        try
        {

                //the parameters are not important this is done by VirtualComPort
                serial = new SerialPort();
                serial.WriteBufferSize = 64;
                serial = new SerialPort();
                serial.PortName = SerialPortName;
                serial.BaudRate = 921600;
                serial.Parity = Parity.None;
                serial.DataBits = 8;
                serial.StopBits = StopBits.None;
                serial.ReadTimeout = 200;
                serial.WriteTimeout = 1;
                serial.Open();



                T_DataOut = new Thread(SendData);
                T_DataOut.Start();

        }
        catch (Exception e)
        {
            MessageBox.Show(e.Message);
        }

    }
    public void SendData()
    {
        try
        {
            for (; ; ) 
            {
                for (int i = 0; i <42 ; i++)
                {
                    for (int j = 0; j < 68; j++)
                    {
                        serial.Write(wb.GetPixel(i,j).ToString());
                    }

                }

            }
        }
        catch (Exception e)
        {

            MessageBox.Show(e.Message);
        }
    }

My question now is how can i update the writeablebitmap(wb) in sendData(). Is this done with ParamterizedThread?

0

There are 0 best solutions below