Forum Home › Forums › Communicating with Devices › OPC › OPC write value issue-IBH opc server
Tagged: OPC write data
- This topic has 97 replies, 3 voices, and was last updated 4 years, 1 month ago by
Mikhail.
-
AuthorPosts
-
November 12, 2018 at 10:19 pm #4584
mariodavid
ParticipantHi,
thank you, I managed to debug but I wanna see the method inside. Said that the simbols are not charged.I just realize than “public override IdentifiedResult[] Write(ItemValue[] items)” belong to a class,
which is derived from another class That contain “public virtual IdentifiedResult[] Write(ItemValue[] items)”.
So, the next methodpublic IdentifiedResult[] Write(ItemValue[] items)
{
if (this.m_server == null)
throw new NotConnectedException();
return ((IServer) this.m_server).Write(items);
}calls “public virtual IdentifiedResult[] Write(ItemValue[] items)” but why does not call override method too?
Is necesary to create a new class like you said?
I have another doubt. “((IOPCSyncIO) this.m_group).Write” only happens if (arrayList1.Count > 0)?public override IdentifiedResult[] Write(ItemValue[] items)
{
if (items == null)
throw new ArgumentNullException(nameof (items));
if (items.Length == 0)
return new IdentifiedResult[0];
lock (this)
{
if (this.m_server == null)
throw new NotConnectedException();
Item[] items1 = new Item[items.Length];
for (int index = 0; index < items.Length; ++index)
items1[index] = new Item((ItemIdentifier) items[index]);
IdentifiedResult[] items2 = this.AddItems(items1);
try
{
ArrayList arrayList1 = new ArrayList(items.Length);
ArrayList arrayList2 = new ArrayList(items.Length);
for (int index = 0; index < items.Length; ++index)
{
if (!items2[index].ResultID.Failed())
{
if (items[index].QualitySpecified || items[index].TimestampSpecified)
{
items2[index].ResultID = ResultID.Da.E_NO_WRITEQT;
items2[index].DiagnosticInfo = (string) null;
}
else
{
arrayList1.Add((object) items2[index]);
arrayList2.Add((object) items[index]);
}
}
}
if (arrayList1.Count > 0)
{
int[] phServer = new int[arrayList1.Count];
object[] pItemValues = new object[arrayList1.Count];
for (int index = 0; index < phServer.Length; ++index)
{
phServer[index] = (int) ((ItemIdentifier) arrayList1[index]).ServerHandle;
pItemValues[index] = OpcCom.Interop.GetVARIANT(((ItemValue) arrayList2[index]).Value);
}
IntPtr ppErrors = IntPtr.Zero;
try
{
((IOPCSyncIO) this.m_group).Write(arrayList1.Count, phServer, pItemValues, out ppErrors);
}
catch (Exception ex)
{
throw OpcCom.Interop.CreateException(“IOPCSyncIO.Write”, ex);
}
int[] int32s = OpcCom.Interop.GetInt32s(ref ppErrors, arrayList1.Count, true);
for (int index = 0; index < arrayList1.Count; ++index)
{
IdentifiedResult identifiedResult = (IdentifiedResult) arrayList1[index];
identifiedResult.ResultID = OpcCom.Interop.GetResultID(int32s[index]);
identifiedResult.DiagnosticInfo = (string) null;
if (int32s[index] == -1073479674)
items2[index].ResultID = new ResultID(ResultID.Da.E_READONLY, -1073479674L);
}
}
}
finally
{
this.RemoveItems(items2);
}
return items2;
}
}November 12, 2018 at 10:35 pm #4585mariodavid
Participantpublic override IdentifiedResult[] Write(ItemValue[] items) in OpcCom.Da20.Server
public virtual IdentifiedResult[] Write(ItemValue[] items) in OpcCom.Da.Server
I really do not understand how to call override write method.
November 13, 2018 at 3:19 pm #4586Mikhail
ModeratorHi,
I wanna see the method inside. Said that the simbols are not charged.
Because this method belongs to another DLL. If you need to debug this method, attach open the source code of the appropriate DLL.
November 13, 2018 at 3:21 pm #4587Mikhail
ModeratorI really do not understand how to call override write method.
You should create an instance of your own class instead of the parent class.
November 14, 2018 at 1:49 pm #4591mariodavid
ParticipantHi,
I tried to create a class, declaring a field to call override method. Also changing KpOpclogic. Compiled without error.
But, when I run communicator, shows a error. “An object of type Op.Da.Server can not be converted to the type Scada.Comm.KP.Class2”
November 14, 2018 at 2:12 pm #4592mariodavid
ParticipantI also tried to create a project with OpcNetApi but when i compiled shows 2 errors.
With OpcNetApi.com, compiled wiht no error, attach to the process but can not set break points because the symbols can not be charged.
November 14, 2018 at 6:20 pm #4595Mikhail
ModeratorThese errors are very specific. To find answers I should do all this stuff by myself. I hope you can find out how to solve it.
I recommend to catch the exception and write to log complete stack trace. Something like that:
catch (Exception ex) { WriteToLog(ex.ToString()); }
November 15, 2018 at 1:42 am #4597mariodavid
ParticipantHi,
I have another idea, but i need to know how to open a project of OpcNetApi and OpcNetApi.Com.dll in VS 2017. Can you tell me how do you use those dll to debug in VS? Please. Do you have the folder like KpOpcSource that i can use?
November 15, 2018 at 6:56 pm #4601Mikhail
ModeratorI have no source code of OpcNetApi. Does a decompier, that you use, can create a VS project that can be build for debug?
November 16, 2018 at 12:46 am #4602mariodavid
ParticipantYes, I open projects with dotpeek but whe i compiled, give some errors.
I also tried to call override method using a field like this
private OpcCom.Da20.Server campo;
compiled without errors. I run the communicator, trying to send a command give this error:
“Error sending command: Object reference not set to an instance of an object”.
Can you give some template o examples to create a instance in KpOpclogic class?
November 16, 2018 at 1:08 am #4603mariodavid
ParticipantI am trying this:
private OpcCom.Da20.Server campo = new OpcCom.Da20.Server();
but give me this error: CS7036 C# There is no argument given that corresponds to the required formal parameter ‘url’ of ‘Server.Server(URL, object)ยด
November 16, 2018 at 5:23 pm #4608Mikhail
ModeratorCan you give some template o examples to create a instance in KpOpclogic class?
Could you clarify what example do you need?
November 28, 2018 at 2:23 pm #4670mariodavid
ParticipantHi
I am tryng to call override method using this.
URL url = null;
object server = null;
OpcCom.Da20.Server campo = new OpcCom.Da20.Server(url, server);
campo.Write(new Opc.Da.ItemValue[] { itemVal });Compiled witout error. When I run communicator, appers this error: error sending command: url can not be null.
I can not change url to another value. So, Can not I use this method definitly?
Where else can I do with url?November 28, 2018 at 2:35 pm #4671mariodavid
ParticipantIn the original KpOpcLogic, you use:
daServer.write(new Opc.Da.ItemValue[] { itemVal });Going to write method declaration:
public class Server : Opc.Server, IServer, Opc.IServer, IDisposable
.
.
.
public IdentifiedResult[] Write(ItemValue[] items)
{
if (this.m_server == null)
throw new NotConnectedException();
return ((IServer) this.m_server).Write(items);
}So, “m_server.write” calls write method of IServer. but IServer is a interface. Why does not call a implementation of IServer instead?
November 28, 2018 at 4:08 pm #4675Mikhail
ModeratorWhy you don’t pass valid URL to new OpcCom.Da20.Server(url, server)?
This URL is needed to specify the server you connect.Why does not call a implementation of IServer instead?
Interface is just a declaration. The runtime executes the method of an object that was actually created.
-
AuthorPosts
- You must be logged in to reply to this topic.