98 lines
3.3 KiB
C#
98 lines
3.3 KiB
C#
using Opc.Ua;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.Remoting.Messaging;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AuroraLaser.Trumpf
|
|
{
|
|
public partial class LaserTruFiber
|
|
{
|
|
// Slot No 3번이 아닌지..
|
|
private string Header = "ns=2;s=Activation.MPI-Slot03.Input.";
|
|
|
|
// Write할 WriteNode를 검색.
|
|
private Dictionary<string, WriteValue> values = new Dictionary<string, WriteValue>();
|
|
|
|
private RequestHeader octRequest = new RequestHeader();
|
|
private WriteValueCollection octNodes = new WriteValueCollection();
|
|
|
|
private uint ExceptionEmptyNodes = 10001;
|
|
|
|
// 예제를 위한 명시적 호출 필요
|
|
public void SetHeader(string header) {
|
|
if (string.IsNullOrEmpty(header))
|
|
return;
|
|
|
|
Header = header;
|
|
}
|
|
public void ClearRegist()
|
|
{
|
|
values.Clear();
|
|
octNodes.Clear();
|
|
}
|
|
|
|
public bool WriteIW(string IW, double position)
|
|
{
|
|
if(values.ContainsKey(IW)){
|
|
values[IW].Value.WrappedValue = position;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public void SendOCT()
|
|
{
|
|
if(octNodes.Count() <= 0)
|
|
throw ServiceResultException.Create(ExceptionEmptyNodes, "Parameter가 등록되지 않음");
|
|
|
|
// read the attributes.
|
|
StatusCodeCollection results = null;
|
|
DiagnosticInfoCollection diagnosticInfos = null;
|
|
|
|
lock (sessionLock) {
|
|
ResponseHeader responseHeader = _session.Write(octRequest, octNodes, out results, out diagnosticInfos);
|
|
|
|
// 밑에 부분은 lock에서 빼보고 싶음..
|
|
ClientBase.ValidateResponse(results, octNodes);
|
|
ClientBase.ValidateDiagnosticInfos(diagnosticInfos, octNodes);
|
|
|
|
// check status.
|
|
if (StatusCode.IsBad(results[0])) {
|
|
// embed the diagnostic information in a exception.
|
|
throw ServiceResultException.Create(results[0], 0, diagnosticInfos, responseHeader.StringTable);
|
|
}
|
|
}
|
|
}
|
|
public void RegistParameter(string nodeName)
|
|
{
|
|
string fullName = Header + nodeName;
|
|
try {
|
|
NodeId nodeId = new NodeId(fullName);
|
|
octRequest.ReturnDiagnostics = (uint)DiagnosticsMasks.All;
|
|
// cast the value to a string.
|
|
//object value = TypeInfo.Cast(ValueTB.Text, TypeInfo.Scalars.String, m_sourceType.BuiltInType);
|
|
|
|
// build list of attributes to read.
|
|
|
|
WriteValue nodeToWrite = new WriteValue();
|
|
nodeToWrite.NodeId = nodeId;
|
|
nodeToWrite.AttributeId = Attributes.Value;
|
|
|
|
// using the WrappedValue instead of the Value property because we know the TypeInfo.
|
|
// this makes the assignment more efficient by avoiding reflection to determine type.
|
|
//nodeToWrite.Value.WrappedValue = new Variant(value, m_sourceType);
|
|
|
|
octNodes.Add(nodeToWrite);
|
|
|
|
values.Add(nodeName, nodeToWrite);
|
|
|
|
} catch (Exception ex) {
|
|
throw ex;
|
|
}
|
|
}
|
|
}
|
|
}
|