RobotStudio event

Fail to load image from file in RC

Options

Hello,

The application I am working on allows the user to select a graphic file and display its content on the FlexPendant. It works perfectly onthe virtual controller, but on the real controller the image is not shown. The relevant piece of code is:


private void menuitemLoadImage_Click(object sender, EventArgs e)
{
this.fileDialog = new GTPUOpenFileDialog();
this.fileDialog.InitialDirectory = ((TpsViewPressWareWIZARD)this.Parent).MyController.FileSystem.RemoteDirectory + "/PressWare/Images";
this.fileDialog.Filter = "*.bmp|*.bmp|*.gif|*.gif|*.jpg|*.jpg|*.png|*.png";
this.fileDialog.FilterIndex = 1;
this.fileDialog.Closing += new CancelEventHandler(fileDialog_Closing);
this.fileDialog.Closed += new EventHandler(fileDialog_Closed);
this.fileDialog.ShowMe(this);
}

private void fileDialog_Closed(object sender, EventArgs e)

{

if (this.fileDialog.DialogResult == System.Windows.Forms.DialogResult.OK)

{

this.pbxPartImage.Image = new Bitmap(this.fileDialog.FileName);

}

this.fileDialog.Dispose();

}

I suspect the problem has to do with the path of the file, that for some reason, is not recognized properly in the RC.

Can anyone give me a clue on how to overcome this issue?

Thanks in advance.

(Additional info: RW 5.06.0158, FP SDK 5.06.0095)

Yolanda Casas

Comments

  • RussD
    Options
    What is the value as a string of "this.fileDialog.FileName" if you display it on the screen or in a MessageBox?
    Russell Drown
  • ycasas
    Options

    Hello Russell,

    I think I found out what my problem was. I was trying to load to a picturebox a graphic file that was located in the Robot Controller, by instantiating a new Bitmap object and passing the value of "this.fileDialog.FileName":

    "ctrl:/RW5060158/HOME/PressWare/Images/3dpart.png"

    to the Bitmap constructor. The problem is that Bitmap() interpreted this as a LOCAL path, and thus failed to find the file.

    I had similar problems with other objects that deal with files, such as System.IO.StreamReader.

    The reason why it worked on the Virtual Controller is that Remote and Local systems are the same there!

    My workaround is to create a local copy of the file (with the ABB.Robotics.Controllers.FileSystemDomain.FileSystem.GetFile () method) and then use that copy:


    private void fileDialog_Closed(object sender, EventArgs e)
    {
    if (this.fileDialog.DialogResult == System.Windows.Forms.DialogResult.OK)
    {
    string strRemoteImageFile = this.fileDialog.FileName;
    string strLocalImageFile = ((TpsViewPressWareWIZARD) this.Parent).MyController.FileSystem.LocalDirectory + "/img";
    ((TpsViewPressWareWIZARD)
    this.Parent).MyController.FileSystem.GetFile(strRemoteImageFile, strLocalImageFile);
    this.pbxPartImage.Image = new Bitmap(strLocalImageFile);
    }
    this.fileDialog.Dispose();
    }
    However, this is a bit annoying since I have to delete the local copies of the remote files after I use them (or fill the local system with rubbish).
    Is this the only/best way to deal with remote (Robot Controller) files from a GTPU application?
    Thank you.
    Yolanda Casas