Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request - examples for all examples. #310

Closed
fdamador opened this issue Jan 11, 2020 · 5 comments
Closed

Feature Request - examples for all examples. #310

fdamador opened this issue Jan 11, 2020 · 5 comments

Comments

@fdamador
Copy link

Not an issue, but I'm wanted to have more examples of the examples. I'm able to apply most of the examples but some are coming back with errors and I think it's just way I'm applying the code.

For instance, I'm able to read a tag value just fine.

Command: C:\GoProjects\src\github.com\gopcua\opcua> go run examples/read/read.go -endpoint opc.tcp://localhost:49380 -node 'ns=2;s=root.PS1.DB101:REAL:66'
Answer: 3

But I'm stuck when wanting to write to this tag. I appears that we need the tag identifier ID number not the actual tag name.

Command: C:\GoProjects\src\github.com\gopcua\opcua> go run examples/write/write.go -endpoint opc.tcp://localhost:49380 -node 'ns=2;s=root.PS1.DB101:REAL:66' -value '4.2'
Answer: The value supplied for the attribute is not of the same type as the attribute's value. StatusBadTypeMismatch (0x80740000)

As a result, can someone add example codes for all the example codes?

@magiconair
Copy link
Member

The examples are code examples not apps which are ready to use. I would guess that the value you are trying to write is a float value but the code in examples/write will try to write it as a string. You have to change the code to make this work with a float value. E.g. use strconv.Atof to convert and then create the variant from the float.

See https://github.com/gopcua/opcua/blob/master/examples/write/write.go#L40-L43

@fdamador
Copy link
Author

Understood, so the string type conversion has to match the value type for the opc ua tag. I eventually, used the following with good result.

input, _ := strconv.ParseFloat(*value, 32)
result := float32(input)
v, err := ua.NewVariant(result)

Then it worked.

@fdamador
Copy link
Author

Thank you for uploading all the code examples a month ago.

I know this issue is closed but I was wondering why half of the server example code is commented it out. Is it because it's a work in progress code?

@magiconair
Copy link
Member

The server code is on a branch developed by @dwhutchinson but has been stale for a while. Right now we don’t have a working OPC/UA server.

@fdamador
Copy link
Author

Understood, I was just trying to integrate this to the influxdata platform. I’ve already submitted a simple OPC ua client

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants