Hi Monks,

Has anyone per chance worked at all with OPC & perl? Specifically the package Win32::OLE::OPC. I'm having a mare of a time with it. My latest problem is writing data, here's the relavent code:

my $itemdata = OPCItemRead ($rightdata[0], $i+1); $rightdata[0]->{lastvalues}->[$i] = $itemdata->{Value}; OPCItemWrite($rightdata[0], $i+1, $rightdata[0]->{lastvalues}->[$i +] + 1);
And the subs

sub OPCItemRead { my $groupdata = shift; my $itemno = shift; my $items; my $data; # reference to the ha +sh of data returned by Read() $items = $groupdata->{grouphandle}->OPCItems(); $data = $items->Item($itemno)->Read($OPCDevice); } sub OPCItemWrite { my $groupdata = shift; my $itemno = shift; my $newvalue = shift; my $items; $items = $groupdata->{grouphandle}->OPCItems(); $items->Item($itemno)->Write($newvalue); }
The read function works absolutely fine, the write always gives:
OPC::Item::Write Matrikon.OPC.DDE: Win32::OLE(0.1707) error 0x80070057: "The parameter is incorrect" in METHOD/PROPERTYGET "Write" at C:/Program Files/Perl/lib/Win32/OLE/OPC.pm line 1666
If I stop the debugger in the write function just before the write $groupdata, $itemno and $newvalue all look fine. If I do this
x $items->Item($itemno)->Read($OPCDevice)
I get the expected data hash so I'm sure everything is set up correctly. As soon as I execute the write up pops this more verbose version of the same error:
OPC::Item::Write Matrikon.OPC.DDE: Win32::OLE(0.1707) error 0x80070057: "The parameter is incorrect" in METHOD/PROPERTYGET "Write" at C:/Program Files/Perl/lib/Win32/OLE/OPC.pm line 1666 at C:/Program Files/Perl/lib/Win32/OLE/OPC.pm line 123 Win32::OLE::OPC::_check_error('OPC::Item::Write Matrikon.OPC.D +DE') called at C:/Program Files/Perl/lib/Win32/OLE/OPC.pm line 1666 Win32::OLE::OPC::Item::Write('Win32::OLE::OPC::Item=HASH(0x22c +2360)', 11) called at opccompare.pl line 542 main::OPCItemWrite('HASH(0x2291d14)', 5, 11) called at opccomp +are.pl line 151 main::(opccompare.pl:154): if (not($debug + =~ m/quiet/)) {
All the man for this method says is
<b>Write(VALUE)</b> Write VALUE to this item.
So taking the error message at face value perhaps I'm expressing VALUE incorrectly. I've tried passing a ref to the data instead of the data value and it makes no difference. I've tried a bare value, a quoted value and a double quoted value. I've tried using a hash like the Read() returns or a ref to that hash. Apart from Swahili, Sanskrit or Welsh I've expressed VALUE in every way I can think of. Here's an online version of the help http://www.opcconnect.com/perl/OPC.html#opcitem

The example supplied with the package, groups.pl, gives exactly the same error for writes. Any monks in the monestary familiar with OPC?

Cheers
nonk


In reply to Win32::OLE error by nonnonymousnonk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.