Step-by-step guide
- Place X20CS1020 behind X20BC008U-rack
- Restore factory settings of X20BC008U, which will activate automatic configuration of X20BC008U
- With UaExpert additional settings can be found on the X20CS1020 module like Baud rate, Parity, Stop bits, Termination characters, Receive idle time and so on.
- With UaExpert methods can be found on the X20CS1020 module like ApplyChanges, LoadDefault, Restore, Open, Close, Read and Write.
- The correct settings can be made by writing to these variables like Baud rate, Parity, Stop bits and so on.
- By calling method ApplyChanges, these settings are saved and the module is rebooted.
- With method Open the communication is activated.
- By reading of variable FramesReceived, the application can check if the method Read must be called.
- By calling method Write frames can be written.
- Method Close will stop the communication.
- This can be tested with HyperTerminal or Putty.
Information Model
Data Access View
Structured Text example
Serial.zip (3.3 KB)
Python example
from opcua import Client
from opcua import ua
if __name__ == "__main__":
url = "opc.tcp://192.168.1.1:4840"
mode = ['']
nodemethod = ['2:ST2','2:MethodSet']
nodeopen = ['2:ST2','2:MethodSet','2:Open']
noderead = ['2:ST2','2:MethodSet','2:Read']
nodewrite = ['2:ST2','2:MethodSet','2:Write']
nodeframe = ['2:ST2','2:ProcessData','2:FramesReceived']
startnode = "ns=2;i=11" # SubDevices X20BC008U
def RelativePath(nodes):
rpath = ua.RelativePath()
for node in nodes:
el = ua.RelativePathElement()
el.ReferenceTypeId = ua.FourByteNodeId(ua.ObjectIds.HierarchicalReferences)
el.IsInverse = False
el.IncludeSubtypes = True
if isinstance(node, ua.QualifiedName):
el.TargetName = node
else:
el.TargetName = ua.QualifiedName.from_string(node)
rpath.Elements.append(el)
return rpath
def Translate(node,startnode):
bpath = ua.BrowsePath()
bpath.StartingNode = ua.NodeId.from_string(startnode)
bpath.RelativePath = RelativePath(node)
nodeids = client.uaclient.translate_browsepaths_to_nodeids([bpath])
return nodeids[0].Targets[0].TargetId
client = Client(url=url)
try:
client.connect()
NodeM = Translate(nodemethod,startnode)
NodeO = Translate(nodeopen,startnode)
NodeR = Translate(noderead,startnode)
NodeW = Translate(nodewrite,startnode)
NodeF = Translate(nodeframe,startnode)
if NodeM.Identifier > 0:
print('NameSpaceIndex: ',NodeM.NamespaceIndex,' Identifier: ',NodeM.Identifier)
if NodeO.Identifier > 0:
print('NameSpaceIndex: ',NodeO.NamespaceIndex,' Identifier: ',NodeO.Identifier)
if NodeR.Identifier > 0:
print('NameSpaceIndex: ',NodeR.NamespaceIndex,' Identifier: ',NodeR.Identifier)
if NodeW.Identifier > 0:
print('NameSpaceIndex: ',NodeW.NamespaceIndex,' Identifier: ',NodeW.Identifier)
if NodeF.Identifier > 0:
print('NameSpaceIndex: ',NodeF.NamespaceIndex,' Identifier: ',NodeF.Identifier)
MethodSet = client.get_node(NodeM)
Open = client.get_node(NodeO)
Read = client.get_node(NodeR)
Write = client.get_node(NodeW)
resOpen = MethodSet.call_method(Open,mode)
node = client.get_node(NodeF)
val = node.get_value()
while val == 0:
val = node.get_value()
print('FramesReceived: ',val)
res = MethodSet.call_method(Read)
MethodSet.call_method(Write,res)
print(res)
finally:
client.disconnect()