Serial communication with X20BC008U and SERIAL/CAN with X20BC008T

Step-by-step guide

  1. Place X20CS1020 behind X20BC008U-rack
  2. Restore factory settings of X20BC008U, which will activate automatic configuration of X20BC008U
  3. 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.
  4. With UaExpert methods can be found on the X20CS1020 module like ApplyChanges, LoadDefault, Restore, Open, Close, Read and Write.
  5. The correct settings can be made by writing to these variables like Baud rate, Parity, Stop bits and so on.
  6. By calling method ApplyChanges, these settings are saved and the module is rebooted.
  7. With method Open the communication is activated.
  8. By reading of variable FramesReceived, the application can check if the method Read must be called.
  9. By calling method Write frames can be written.
  10. Method Close will stop the communication.
  11. 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()
6 Likes

With the latest firmware v1.4.6 for the X20BC008T, serial and can communication is possible.
The X20CS1020 and X20CS1070 cards can be used and frames can be read and written with OPC UA methods.
The information model is slightly diffferent and documented in the X20BC008T datasheet v1.31 ( Data sheet X20BC008T | B&R Industrial Automation).

Python example

from opcua import Client
from opcua import ua
import keyboard
    
if __name__ == "__main__":
    url = "opc.tcp://172.16.1.100:4840"
    Size = "ns=4;s=IF1.ST2@IF1.Size"
    OpenCount = "ns=4;s=IF1.ST2@IF1.OpenCount"
    NothingReceivedCount = 0
  
    client = Client(url=url)
    # Set user token
    client.set_user("admin")
    client.set_password("secret")
    try:
        client.connect()
    
        nodeSize = client.get_node(Size)
        nodeSizeValue = nodeSize.get_value()
        print(f"The value of the node {Size} is: {nodeSizeValue}")

        nodeOpenCount = client.get_node(OpenCount)
        nodeOpenCountValue = nodeOpenCount.get_value()
        print(f"The value of the node {OpenCount} is: {nodeOpenCountValue}")

        IF1_method_node_id = "ns=4;s=IF1.ST2@IF1"
        Open_object_node_id = "ns=4;s=IF1.ST2@IF1.Open"
        Read_object_node_id = "ns=4;s=IF1.ST2@IF1.Read"
        Write_object_node_id = "ns=4;s=IF1.ST2@IF1.Write"
        Close_object_node_id = "ns=4;s=IF1.ST2@IF1.Close"

        IF1 = client.get_node(IF1_method_node_id)
        Open = client.get_node(Open_object_node_id)
        Read = client.get_node(Read_object_node_id)
        Write = client.get_node(Write_object_node_id)
        Close = client.get_node(Close_object_node_id)

        Mode = ua.Variant(3, ua.VariantType.Byte) # read/write
        FileHandle = IF1.call_method(Open,Mode)
        FileHandleArg = ua.Variant(FileHandle, ua.VariantType.UInt32)
        print(f"The result of the method call is: {FileHandle}")
        nodeOpenCount = client.get_node(OpenCount)
        nodeOpenCountValue = nodeOpenCount.get_value()
        print(f"The value of the node {OpenCount} is: {nodeOpenCountValue}")

        print("Press 'q' to exit the loop.")

        while True:
            #nodeSize = client.get_node(Size)
            nodeSizeValue = nodeSize.get_value()
            #nodeOpenCount = client.get_node(OpenCount)
            nodeOpenCountValue = nodeOpenCount.get_value()
            # Your loop code here
            if nodeOpenCountValue == 0:
                print(f"The value of the node {OpenCount} is: {nodeOpenCountValue}")
                break
            if nodeSizeValue > 0:
                print(f"The value of the node {Size} is: {nodeSizeValue}")
                nodeSizeValueArg = ua.Variant(nodeSizeValue, ua.VariantType.Int32)
                ReceivedData = IF1.call_method(Read,FileHandleArg,nodeSizeValueArg)
                print(f"Received data is: {ReceivedData}")
                SendData = ua.Variant(ReceivedData, ua.VariantType.ByteString)
                ReadStatus = IF1.call_method(Write,FileHandleArg,SendData)
                NothingReceivedCount = 0
            else:
                NothingReceivedCount += 1

            if NothingReceivedCount > 4000:
                nodeSizeValueArg = ua.Variant(1, ua.VariantType.Int32)
                ReceivedData = IF1.call_method(Read,FileHandleArg,nodeSizeValueArg)
                print(f"Received data is: {ReceivedData}")
                NothingReceivedCount = 0
                
            # Check for keyboard interrupt
            if keyboard.is_pressed('q'):
                print("Exiting loop...")
                break
        CloseStatus = IF1.call_method(Close,FileHandleArg)
  
    finally:
        client.disconnect()
6 Likes

Hi, I tested it with CS1030 and it works as well

3 Likes

X20BC008T is a B&R successor product in portfolio of X20BC008U that offers more features and functionality.

1 Like