PhuongTran1983
Level-1
- Beiträge
- 67
- Reaktionspunkte
- 3
-> Hier kostenlos registrieren
Hallo zusammen,
ich habe ein Problem mit der OPC-Ua Verbindung und könntet Ihr mir bitte weiterhelfen.
Ich habe einen OPC Ua Server in einer SPS am Laufen. In TC3 habe ich ein kleines Programm "PRG_Read" anhand eines Beispiels von Beckhoff geschrieben, um die Daten von einem OPC Server zu lesen. Der Ablauf des Programms wird in 7 verschiedenen State vom OPC Ua-Connect bis zum Disconnect aufgeteilt (s. Unten).
Der Client konnte den Server zugreifen. Es hat aber nur das Problem, dass die Daten in den Client sehr langsam geholt wurden. Wie kann man die Taktzyklus für den Client definieren. D.h. Beispielweise greift der Client den Server je nach 50ms einmal zu.
Hat jemand dieses Thema schon mal beschäftigt. Könnte mir bitte Lösungsvorschläge geben.
Vielen Dank und viele Grüße,
Phuong Tran
CASE iState OF
0: (* idle *)
bTest := TRUE;
IF bTest THEN
bTest := FALSE;
bError := FALSE;
nErrorID := 0;
SessionConnectInfoEx.tConnectTimeout := T#5S;
SessionConnectInfoEx.tSessionTimeout := T#5S;
SessionConnectInfoEx.sApplicationName := '';
SessionConnectInfoEx.eSecurityMode := eUASecurityMsgMode_None;
SessionConnectInfoEx.eSecurityPolicyUri := eUASecurityPolicy_None;
SessionConnectInfoEx.eTransportProfileUri := eUATransportProfileUri_UATcp;//eUATransportProfileUri_UATcp;
iState := iState + 1;
END_IF
1: (* open UA session *)
fbUA_ConnectEx(
Execute := TRUE,
ServerURL := sOpcUaServerUrl,
SessionConnectInfo := SessionConnectInfoEx,
Timeout := T#5S,
ConnectionHdl => nConnectionHdl
);
IF NOT fbUA_ConnectEx.Busy THEN
fbUA_ConnectEx(Execute := FALSE);
IF NOT fbUA_ConnectEx.Error THEN
(* session open *)
iState := iState + 1;
ELSE
bError := TRUE;
nErrorID := fbUA_ConnectEx.ErrorID;
nConnectionHdl := 0;
iState := 0; (* idle *)
END_IF
END_IF
2: (* GetNS Index *)
fbUA_GetNamespaceIndex(
Execute := TRUE,
ConnectionHdl := nConnectionHdl,
NamespaceUri := sNamespaceUri,
NamespaceIndex => nNamespaceIndex
);
IF NOT fbUA_GetNamespaceIndex.Busy THEN
fbUA_GetNamespaceIndex(Execute := FALSE);
IF NOT fbUA_GetNamespaceIndex.Error THEN
(* session closed *)
iState := iState + 1; (* idle *)
ELSE
bError := TRUE;
nErrorID := fbUA_GetNamespaceIndex.ErrorID;
iState := 6; (* idle *)
END_IF
END_IF
3: (* Get Node Handle *)
NodeIDs[1].eIdentifierType := eUAIdentifierType_String;
NodeIDs[1].nNamespaceIndex := nNamespaceIndex;
NodeIDs[1].sIdentifier := 'MAIN.P';
NodeIDs[2].eIdentifierType := eUAIdentifierType_String;
NodeIDs[2].nNamespaceIndex := nNamespaceIndex;
NodeIDs[2].sIdentifier := 'MAIN.Q';
NodeIDs[3].eIdentifierType := eUAIdentifierType_String;
NodeIDs[3].nNamespaceIndex := nNamespaceIndex;
NodeIDs[3].sIdentifier := 'MAIN.I';
NodeIDs[4].eIdentifierType := eUAIdentifierType_String;
NodeIDs[4].nNamespaceIndex := nNamespaceIndex;
NodeIDs[4].sIdentifier := 'MAIN.U';
NodeIDs[5].eIdentifierType := eUAIdentifierType_String;
NodeIDs[5].nNamespaceIndex := nNamespaceIndex;
NodeIDs[5].sIdentifier := 'MAIN.Lampe';
fbUA_NodeGetHandleList(
Execute := TRUE,
ConnectionHdl := nConnectionHdl,
NodeIDCount := NodeIDCount,
NodeIDs := NodeIDs,
NodeHdls => nNodeHdls
);
IF NOT fbUA_NodeGetHandleList.Busy THEN
fbUA_NodeGetHandleList(Execute := FALSE);
IF NOT fbUA_NodeGetHandleList.Error THEN
(* session closed *)
iState := iState + 1; (* idle *)
ELSE
bError := TRUE;
nErrorID := fbUA_NodeGetHandleList.ErrorID;
iState := 6; (* idle *)
END_IF
END_IF
4: (* UA_Read *)
cbData[1] := SIZEOF(stReadListData.P);
cbData[2] := SIZEOF(stReadListData.Q);
cbData[3] := SIZEOF(stReadListData.I);
cbData[4] := SIZEOF(stReadListData.U);
cbData[5] := SIZEOF(stReadListData.Lampe);
cbDataTotal := SIZEOF(stReadListData);
fbUA_ReadList(
Execute := TRUE,
ConnectionHdl := nConnectionHdl,
NodeHdlCount := NodeHdlCount, // 2
NodeHdls := nNodeHdls,
stNodeAddInfo := stNodeAddInfo,
pVariable := ADR(stReadListData),
cbData := cbData ,
cbDataTotal := cbDataTotal
);
IF NOT fbUA_ReadList.Busy THEN
fbUA_ReadList( Execute := FALSE, cbData_R => cbData_R);
IF NOT fbUA_ReadList.Error THEN
(* session closed *)
iState := iState + 1; (* idle *)
ELSE
bError := TRUE;
nErrorID := fbUA_ReadList.ErrorID;
iState := 6; (* idle *)
END_IF
END_IF
5: (* Release Node Handle *)
fbUA_NodeReleaseHandleList(
Execute := TRUE,
ConnectionHdl := nConnectionHdl,
NodeHdlCount := NodeHdlCount,
NodeHdls := nNodeHdls
);
IF NOT fbUA_NodeReleaseHandleList.Busy THEN
fbUA_NodeReleaseHandleList(Execute := FALSE);
IF NOT fbUA_NodeReleaseHandleList.Error THEN
(* session closed *)
iState := iState + 1; (* idle *)
ELSE
bError := TRUE;
nErrorID := fbUA_NodeReleaseHandleList.ErrorID;
iState := 6; (* idle *)
END_IF
END_IF
6: (* close session *)
fbUA_Disconnect(
Execute := TRUE,
ConnectionHdl := nConnectionHdl
);
IF NOT fbUA_Disconnect.Busy THEN
fbUA_Disconnect(Execute := FALSE);
bBusy := FALSE;
IF NOT fbUA_Disconnect.Error THEN
(* session closed *)
iState := 0; (* idle *)
IF NOT bError THEN
bDone := TRUE;
END_IF
ELSE
bError := TRUE;
nErrorID := fbUA_Disconnect.ErrorID;
iState := 0; (* idle *)
nConnectionHdl := 0;
END_IF
END_IF
END_CASE
ich habe ein Problem mit der OPC-Ua Verbindung und könntet Ihr mir bitte weiterhelfen.
Ich habe einen OPC Ua Server in einer SPS am Laufen. In TC3 habe ich ein kleines Programm "PRG_Read" anhand eines Beispiels von Beckhoff geschrieben, um die Daten von einem OPC Server zu lesen. Der Ablauf des Programms wird in 7 verschiedenen State vom OPC Ua-Connect bis zum Disconnect aufgeteilt (s. Unten).
Der Client konnte den Server zugreifen. Es hat aber nur das Problem, dass die Daten in den Client sehr langsam geholt wurden. Wie kann man die Taktzyklus für den Client definieren. D.h. Beispielweise greift der Client den Server je nach 50ms einmal zu.
Hat jemand dieses Thema schon mal beschäftigt. Könnte mir bitte Lösungsvorschläge geben.
Vielen Dank und viele Grüße,
Phuong Tran
CASE iState OF
0: (* idle *)
bTest := TRUE;
IF bTest THEN
bTest := FALSE;
bError := FALSE;
nErrorID := 0;
SessionConnectInfoEx.tConnectTimeout := T#5S;
SessionConnectInfoEx.tSessionTimeout := T#5S;
SessionConnectInfoEx.sApplicationName := '';
SessionConnectInfoEx.eSecurityMode := eUASecurityMsgMode_None;
SessionConnectInfoEx.eSecurityPolicyUri := eUASecurityPolicy_None;
SessionConnectInfoEx.eTransportProfileUri := eUATransportProfileUri_UATcp;//eUATransportProfileUri_UATcp;
iState := iState + 1;
END_IF
1: (* open UA session *)
fbUA_ConnectEx(
Execute := TRUE,
ServerURL := sOpcUaServerUrl,
SessionConnectInfo := SessionConnectInfoEx,
Timeout := T#5S,
ConnectionHdl => nConnectionHdl
);
IF NOT fbUA_ConnectEx.Busy THEN
fbUA_ConnectEx(Execute := FALSE);
IF NOT fbUA_ConnectEx.Error THEN
(* session open *)
iState := iState + 1;
ELSE
bError := TRUE;
nErrorID := fbUA_ConnectEx.ErrorID;
nConnectionHdl := 0;
iState := 0; (* idle *)
END_IF
END_IF
2: (* GetNS Index *)
fbUA_GetNamespaceIndex(
Execute := TRUE,
ConnectionHdl := nConnectionHdl,
NamespaceUri := sNamespaceUri,
NamespaceIndex => nNamespaceIndex
);
IF NOT fbUA_GetNamespaceIndex.Busy THEN
fbUA_GetNamespaceIndex(Execute := FALSE);
IF NOT fbUA_GetNamespaceIndex.Error THEN
(* session closed *)
iState := iState + 1; (* idle *)
ELSE
bError := TRUE;
nErrorID := fbUA_GetNamespaceIndex.ErrorID;
iState := 6; (* idle *)
END_IF
END_IF
3: (* Get Node Handle *)
NodeIDs[1].eIdentifierType := eUAIdentifierType_String;
NodeIDs[1].nNamespaceIndex := nNamespaceIndex;
NodeIDs[1].sIdentifier := 'MAIN.P';
NodeIDs[2].eIdentifierType := eUAIdentifierType_String;
NodeIDs[2].nNamespaceIndex := nNamespaceIndex;
NodeIDs[2].sIdentifier := 'MAIN.Q';
NodeIDs[3].eIdentifierType := eUAIdentifierType_String;
NodeIDs[3].nNamespaceIndex := nNamespaceIndex;
NodeIDs[3].sIdentifier := 'MAIN.I';
NodeIDs[4].eIdentifierType := eUAIdentifierType_String;
NodeIDs[4].nNamespaceIndex := nNamespaceIndex;
NodeIDs[4].sIdentifier := 'MAIN.U';
NodeIDs[5].eIdentifierType := eUAIdentifierType_String;
NodeIDs[5].nNamespaceIndex := nNamespaceIndex;
NodeIDs[5].sIdentifier := 'MAIN.Lampe';
fbUA_NodeGetHandleList(
Execute := TRUE,
ConnectionHdl := nConnectionHdl,
NodeIDCount := NodeIDCount,
NodeIDs := NodeIDs,
NodeHdls => nNodeHdls
);
IF NOT fbUA_NodeGetHandleList.Busy THEN
fbUA_NodeGetHandleList(Execute := FALSE);
IF NOT fbUA_NodeGetHandleList.Error THEN
(* session closed *)
iState := iState + 1; (* idle *)
ELSE
bError := TRUE;
nErrorID := fbUA_NodeGetHandleList.ErrorID;
iState := 6; (* idle *)
END_IF
END_IF
4: (* UA_Read *)
cbData[1] := SIZEOF(stReadListData.P);
cbData[2] := SIZEOF(stReadListData.Q);
cbData[3] := SIZEOF(stReadListData.I);
cbData[4] := SIZEOF(stReadListData.U);
cbData[5] := SIZEOF(stReadListData.Lampe);
cbDataTotal := SIZEOF(stReadListData);
fbUA_ReadList(
Execute := TRUE,
ConnectionHdl := nConnectionHdl,
NodeHdlCount := NodeHdlCount, // 2
NodeHdls := nNodeHdls,
stNodeAddInfo := stNodeAddInfo,
pVariable := ADR(stReadListData),
cbData := cbData ,
cbDataTotal := cbDataTotal
);
IF NOT fbUA_ReadList.Busy THEN
fbUA_ReadList( Execute := FALSE, cbData_R => cbData_R);
IF NOT fbUA_ReadList.Error THEN
(* session closed *)
iState := iState + 1; (* idle *)
ELSE
bError := TRUE;
nErrorID := fbUA_ReadList.ErrorID;
iState := 6; (* idle *)
END_IF
END_IF
5: (* Release Node Handle *)
fbUA_NodeReleaseHandleList(
Execute := TRUE,
ConnectionHdl := nConnectionHdl,
NodeHdlCount := NodeHdlCount,
NodeHdls := nNodeHdls
);
IF NOT fbUA_NodeReleaseHandleList.Busy THEN
fbUA_NodeReleaseHandleList(Execute := FALSE);
IF NOT fbUA_NodeReleaseHandleList.Error THEN
(* session closed *)
iState := iState + 1; (* idle *)
ELSE
bError := TRUE;
nErrorID := fbUA_NodeReleaseHandleList.ErrorID;
iState := 6; (* idle *)
END_IF
END_IF
6: (* close session *)
fbUA_Disconnect(
Execute := TRUE,
ConnectionHdl := nConnectionHdl
);
IF NOT fbUA_Disconnect.Busy THEN
fbUA_Disconnect(Execute := FALSE);
bBusy := FALSE;
IF NOT fbUA_Disconnect.Error THEN
(* session closed *)
iState := 0; (* idle *)
IF NOT bError THEN
bDone := TRUE;
END_IF
ELSE
bError := TRUE;
nErrorID := fbUA_Disconnect.ErrorID;
iState := 0; (* idle *)
nConnectionHdl := 0;
END_IF
END_IF
END_CASE