in reply to Win32::OLE error

Try turning the last parameter to your OPCItemWrite call into a string. Some servers are sensitive to the actual type of the data in the variant. I think you might have tried that though.

Someone else had a similar problem, he started out with this code (which gave the error):

use Win32::OLE::OPC; use CGI qw(:all); $opcintf = Win32::OLE::OPC->new('OPC.Automation','hci.phd'); $group = $opcintf->OPCGroups->Add('sanitize_mode'); $items = $group->OPCItems(); $reset_item = $items->AddItems("6440SAN2.PV", 999); $reset_item->Write('SANITIZE');

and this is the code once he got it working:

use Win32::OLE::OPC; use CGI qw(:all); $opcintf = Win32::OLE::OPC->new('OPC.Automation','hci.phd'); $group = $opcintf->OPCGroups->Add('san_grp'); my $items = $group->OPCItems; $items->AddItem( '6440SAN2.PV', 0 ); $item = $items->Item(1); $item->Write('NORMAL');

You don't show how you are creating the groups, that might have something to do with it.

Replies are listed 'Best First'.
Re^2: Win32::OLE error
by Anonymous Monk on Oct 18, 2007 at 06:42 UTC
    I was just trying this as well with the same problem. Since most of the values I am trying to write are VT_R4, I changed the line 1559 in the OPC.pm module from: my $value = Variant(VT_VARIANT|VT_BYREF, shift); to my $value = Variant(VT_R4|VT_BYREF, shift); and voila!! it works fine. And this mod begs the question, What about other types?...
Re^2: Win32::OLE error
by Anonymous Monk on Oct 18, 2007 at 06:48 UTC
    Since most OPC servers are pretty good at doing the type conversions, try changing the VT_R4 described previously to VT_BSTR. That should take your scalar value as a number or string and pass it to the OPC Server as a string. The OPC server should then be able to decode it back to whatever it needs. It worked with my OPC Server that expected VT_R4 data.