SteveL has asked for the wisdom of the Perl Monks concerning the following question:

Hi all

First post, so be gentle with me :)

I have been using Perl for many years with too much trouble, but I have only recently had to deal with Win32::OLE.

I am trying to control a Phidget USB Display board via Perl ( http://www.phidgets.com/products.php?category=15&product_id=1203 )

So far, no problems opening the device via OLE, and obtain the board serial number, set the backlight and cursor blink.

use Win32::OLE; $phidget = Win32::OLE->new("Phidget21COM.PhidgetTextLCD"); $phidget->Invoke("Open", -1); (check/wait loop here for "IsAttached") $serial = $phidget->{SerialNumber}; $phidget->{"Backlight"} = 1; $phidget->{"CursorBlink"} = 0;

but, when I try to set the text in the LCD display, I am having really issues trying to work out the VB to Perl equivalent of this:

TextLCD.DisplayString(0) = "hello"

where "TextLCD" is the "$phidget" OLE object I have opened. I have tried just about everything I can think of, and must be missing something really obvious:

#does nothing $phidget->Invoke('DisplayString', (1,"hello")); $phidget->Invoke('DisplayString', (2,"goodbye")); #again, does nothing $phidget->{"DisplayString"} = (1,"hello"); $phidget->{"DisplayString"} = (2,"goodbye"); #still does nothing $phidget->DisplayString(1, "hello"); $phidget->DisplayString(2, "goodbye"); #This still does nothing $phidget->{DisplayString}[0] = "hello";

If it runs, it does nothing. If it doesnt run, it spits out:

Win32::OLE(0.1707) error 0x8002000e: "Invalid number of parameters" in PROPERTYPUT "DisplayString" at phidget-test.pl line 30

Is there anyone here at the Monastery who can enlighten me to my glaring mistake?

Replies are listed 'Best First'.
Re: Win32::OLE / Perl / Phidget Display code
by holli (Abbot) on Aug 16, 2009 at 21:00 UTC
    From what I remember about VB
    TextLCD.DisplayString(0) = "hello"
    is an array subscript. So what does
    use Data::Dumper; print Dumper( $phidget->DisplayString->[1] ); # or print Dumper( $phidget->{DisplayString}->[1] );
    say?


    holli

    You can lead your users to water, but alas, you cannot drown them.
      print Dumper( $phidget->DisplayString->[1] ); Win32::OLE(0.1709) error 0x80020003: "Member not found" in METHOD/PROPERTYGET "DisplayString" at C:/Perl/lib/Data/Dumper.p +m line 527
      And if I try to set the value, it passes through just fine, but it still doesnt actually do anything Doing a Dumper on the entire $phidget object shows all the readable entries, but according to the docs, you can set but not read DisplayString.
      $VAR1 = bless( { 'DeviceType' => 'Phidget TextLCD', 'SerialNumber' => <snip>, 'Name' => 'PhidgetTextLCD', 'Label' => '', 'IsAttached' => 1, 'DeviceVersion' => 123, 'LibraryVersion' => 'Phidget21 - Version 2.1.6 - Buil +t Aug 6 2 009 16:11:11 Phidget COM Library 2.1.6 - Built Aug 6 2009 16:12:18', 'port' => 0, 'Address' => '', 'ServerID' => '', 'IsAttachedToServer' => 0, 'RowCount' => 2, 'ColumnCount' => 20, 'Backlight' => 1, 'CursorOn' => 0, 'CursorBlink' => 0, 'Contrast' => 0 }, 'Win32::OLE' );