python-opcua icon indicating copy to clipboard operation
python-opcua copied to clipboard

Unable to read data from node. Throwing opcua.ua.uaerrors._auto.Bad: The operation failed.(Bad) error.

Open sb934 opened this issue 3 years ago • 19 comments

I am trying to read data from a Kepware server at regular intervals. I am able to read some tags in the address space; however some tags end up giving me a _opcua.ua.uaerrors.auto.Bad: The operation failed.(Bad) error. So I included a try/catch so that the code is not interrupted, skips the tags throwing Bad StatusCode. Check the following output (of 1 iteration)...

Node1: 333

ua.uaerrors._auto.Bad @ Node2 ua.uaerrors._auto.Bad @ Node3

Node4 : 0

Node5 : 1

Node6 : 9

Node7 : False

Something that doesn't add up is that if I open these Nodes (1,2,3) in UAExpert, the Python script is suddenly able to read values for those nodes too (like Node1 above). It takes a few seconds for UAExpert to get Good StatusCode for these nodes. (BadInitialWaiting -> Bad -> Good) . Similarly, if I close UAExpert the Python script starts catching Bad error on these nodes again...

Is there a way I can repeatedly try reading a node value, before moving on to the next line of code? Or any other workaround this issue?

sb934 avatar Oct 12 '20 15:10 sb934

try reading if status is not good raise error/except pass in a while loop and if reading is good break!?

but tbh its ugly 😬

AndreasHeine avatar Oct 12 '20 15:10 AndreasHeine

I have my Node Details in a JSON file. This is what I am doing...

if(len(config['Tags'])):

    for obj in config['Tags']:

        try:

            node = client.get_node(obj['node_addr'])

            node_value = node.get_value()

            print(obj['tag'],':',str(node_value),'\n')

            v1 = [obj['tag'],str(node_value),obj['msg_type'],0]

            push_value(c, v1)

        except ua.uaerrors._auto.BadWaitingForInitialData:

            print("ua.uaerrors._auto.BadWaitingForInitialData @ ", obj['tag'])

            #pass 
        except ua.uaerrors._auto.Bad:

            print("ua.uaerrors._auto.Bad @ ", obj['tag'])

            #pass
else:

    print("No Tags to retrieve from server")

This reads the remaining nodes. But Node 1,2,3 aren't readable even after multiple iterations.

sb934 avatar Oct 12 '20 15:10 sb934

can you post a screenshot from ua expert of those nodes (addressspace and attributes)? have you tryed to subscribe the nodes, instead of polling, to get the data it much simpler because you will get a datachange notification if the node value change!?

AndreasHeine avatar Oct 12 '20 16:10 AndreasHeine

image

image

image

image

As mentioned earlier: As soon as I open these tags in UAExpert. The Python script is able to read values without any exceptions. Attaching a screenshot for your reference.

sb934 avatar Oct 12 '20 18:10 sb934

@AndreasHeine you got anything mate?

sb934 avatar Oct 12 '20 21:10 sb934

sorry took some sleep guess your in a different timezon 🤔

AndreasHeine avatar Oct 13 '20 04:10 AndreasHeine

try browse them before reading value!!?

AndreasHeine avatar Oct 13 '20 04:10 AndreasHeine

success?

AndreasHeine avatar Oct 13 '20 20:10 AndreasHeine

If I use the subscriber class instead of manually reading the value, it throws the same "Bad Status" error. I can try again though. Didn't get you on the browsing part..?

sb934 avatar Oct 13 '20 21:10 sb934

What I don't understand is that how is UAExpert and Python script connected? Like why does the code stop giving me errors and starts reading the value as soon as I start reading the same nodes in UAExpert?

sb934 avatar Oct 13 '20 21:10 sb934

just call node.get_browse_name() before you subscribe or read the node! there was something in the past but i can hardly remember... not sure if it was with kepware.

AndreasHeine avatar Oct 14 '20 04:10 AndreasHeine

I have exactly the same problem as @sb934. The suggested solution from @AndreasHeine does not work for me. Does someone have an idea how I can fix this?

LostInDarkMath avatar Jul 13 '21 14:07 LostInDarkMath

Sorry, best answer I can give is to avoid using Kepware. The server is notoriously bad.

zerox1212 avatar Jul 13 '21 14:07 zerox1212

Are there any alternatives to Kepware that you would recommend?

LostInDarkMath avatar Jul 13 '21 14:07 LostInDarkMath

the thing with the the statuscode of kepware tags is it is dependend on the connectionstatus from kepware to the datahost... had this in a prev project the only thing you can do is to react to the bad statuscodes and try to browse the tags up front most of the time it helps otherweise it depends on the driver in kepware when it starts to update the opc ua tags...

AndreasHeine avatar Jul 13 '21 16:07 AndreasHeine

Hi there, I have the same problem that I cannot read some nodes from Sinumerik 840D opcua server and get 'Operation failed.(Bad)' error. Also, I can read all nodes with Prosys opcua client. Did you find any solution?

yetkinakyz avatar Feb 11 '22 05:02 yetkinakyz

I have the same problem with SINUMERIK OPC UA Server. One specific node doesn't want to be read. /Tool/Catalogue/toolIdent[u1,49] it's the last one of a list.

That's the same error as if I go one index too far in another working list. UaExpert doesn't give an error I can read whatever index I want out of range and it will still say it's ok without return value.

FailedRead

KenSense avatar Nov 28 '22 08:11 KenSense

As you see UAExpert can only read it via Subscription, but not via ReadRequest. So this is something the SINUMERIK OPC UA Server doesn't support and not the error of this library.

schroeder- avatar Nov 28 '22 10:11 schroeder-

I can indeed subscribe to it, Thanks. New data change event ns=2;s=/Tool/Catalogue/toolIdent[u1,49] None

KenSense avatar Nov 29 '22 09:11 KenSense