5

I am writing a program that monitors commands sent from the serialport (from an arduino) and sends keystrokes to various other programs.

I have placed a dispatcher in my event, but it will only run once... I have stepped through the code and it runs all the way through the first time but not the second time.

private void portReadEvent(object sender, SerialDataReceivedEventArgs args)
        { //break here
            Action dump = delegate() 
            {
                dumpInfoText(serialPort.ReadExisting());
            }; //create my deligate

            txt_portInfo.Dispatcher.Invoke(dump); //run dispatcher

        }

        private void dumpInfoText(string text)
        {
            string completeCommand = "";
            foreach (char C in text)
            {
                if (serDump.Length <=8 && (C != (char)0x0A || C != (char)0x0D)) //check 
                {
                    serDump = serDump + C; //add char
                }
                if (serDump.Length == 8) //check to see if my info has a complete command (serDump is global)
                {
                    completeCommand = serDump; //move to complete
                    serDump = ""; // reset dump
                    if (C == (char)0x0A || C == (char)0x0D) //dont add crlf
                    {
                        serDump = serDump + C; //add char
                    }
                }
                if (completeCommand.Length == 8)
                {
                    txt_portInfo.Text = txt_portInfo.Text + completeCommand; //do something with it.
                }
            }
Neon_c
  • 51
  • 3

1 Answers1

0

Ahh, Fixed... Not sure why.

    private void portReadEvent(object sender, SerialDataReceivedEventArgs args)
    {
        txt_portInfo.Dispatcher.Invoke(new Action(() => {dumpInfoText(serialPort.ReadExisting());})); //run dispatcher

    }
Neon_c
  • 51
  • 3