Main Site Documentation

Change image in serial data receive interrupt


#1

I am working with FEZ cobra, I want to change an image on the bases of data receive interrupt from serial port. When i am changing an image in data receive interrupt it is giving me error, the same image, i can able to change in button click.

I think i have to us dispatcher here but i don’t know how? Can some one guide.


#2

You will need to use the dispatcher for updating images on the screen.
See it as a thread safe method in normal .net.

Icon switching using dispatcher class:


void SetControlIcon(Image control, Bitmap icon)
        {
            control.Dispatcher.Invoke(new TimeSpan(0, 0, 1), new DispatcherOperationCallback(UpdateImageControl), new ImageToUpdate(control, icon));
        }

Image update class:

public class ImageToUpdate
    {
        public ImageToUpdate(Image ctl, Bitmap img)
        {
            Control = ctl;
            Image = img;
        }
 
        public Image Control { get; set; }
        public Bitmap Image { get; set; }
    }

Which can then be used like this:

SetControlIcon(joystickButton, Resources.GetBitmap(Resources.BitmapResources.icon_Joystick));

#3

I don’t want to get flamed for using WPF, but seriously it is this easy:

void imageButtonOne_TouchDown(object sender, Microsoft.SPOT.Input.TouchEventArgs e) {
 imageButtonOne.Bitmap = bmpIconOne_select;
}

#4

Does it work other threads?
Example: this user’s problem?


#5

Possibly not…

but then you can simply call a function in the display class which will update the displayed bitmap based on whatever value you pass it.

void UpdateDisplay(Boolean whatever) {
    if (whatever == true) {
        imageOne.Bitmap = bmpOne_selected;
    } else {
        imageOne.Bitmap = bmpOne_unselected;
    }
}

#6

Thanks Robert, In serial data receive interrupt, I have used like this and it works properly.



ImageControl.Dispatcher.BeginInvoke(delegate(object args)
            {
                if (ImageControl.Bitmap == SSLvl0)
                {
                    ImageControl.Bitmap = SSLvl1;
                }
                else
                {
                    ImageControl.Bitmap = SSLvl0;
                }

                return null;
            }, null);


#7

Glad you got it working!
Have fun with FEZ 8)


#8

I stuck at one more place.

I want to open a Popup window in serial interrupt. I have made a class without using WPF components. When i am writing below code in Serial interrupt, it gives error as “Invalid Operation”.

clsIncomingCallPopup Clpopup = new clsIncomingCallPopup();

As a work around solution, i have already open a popup class and make it hidden. In serial interrupt, i have assign the property as visible through dispatcher and it works.

I think it can be possible to open a class through dispatcher too but don’t know how? Can some one guide?