B.,
I think that everything is done right.
The only point for consideration is whether it wouldn’t be better to create your own error code, rather than re-using OPC_E_BADRIGHTS. My opinion is that since OPC_E_BADRIGHTS is already generated inside the OPC Server in appropriate situations (such as Writing to a read-only item), using a different error code could help in distinguishing where the errors come from.
Best regards,
Zbynek Zahradnik
From: B.
Sent: Saturday, December 17, 2011 5:15 PM
To: Zbynek Zahradnik
Subject: RE: OPC writing
Zbynek,
It seems o work as expected now. My goal is to have around three or four different write errors depending of different things. My name of the class is:
void CMBusTagLeaf::Write(CVTQ& VTQ, BYTE Flags, HRESULT& Error)
I have during tests forced that this error will occur in the server.
Error = OPC_E_BADRIGHTS;
Here is the client code. The idea is to cache the different errors and write out a specific detailed text. If it should be a big exception it will be catched by the maincatch Exception exc.
Is this handled OK from your point of you?
EasyDAClient easyDa = new EasyDAClient();
DAItemDescriptor dai = new DAItemDescriptor(tag.ChannelName + "." + tag.GroupName + (tag.GroupName != "" ? "_" : "") + tag.DeviceName + "." + tag.TagName);
OpcLabs.EasyOpc.ServerDescriptor server = new OpcLabs.EasyOpc.ServerDescriptor(ApplicationModel.ServerId);
easyDa.HoldPeriods.TopicWrite = 9000;
try
{
easyDa.WriteItemValue(server, dai, val);
}
catch (OpcLabs.EasyOpc.OpcException ce)
{
switch ((uint)ce.ErrorCode)
{
case 0xc0040006://OPC_E_BADRIGHTS;
break;
default:
break;
}
}
catch (Exception exc)
{
//Dialogs.ShowError(ResourceLanguageHandler.getValue(2407) + " " + exc.Message);
Dialogs.ShowError(exc.Message);
}
Best Regards
/B.