siemens / simatic-s7-webserver-api

A .NET API Client Library for the SIMATIC S7 PLC Webserver API
https://www.nuget.org/packages/Siemens.Simatic.S7.Webserver.API/
MIT License
107 stars 23 forks source link

Get and Set array with custom data type #31

Closed Little-Cat closed 1 year ago

Little-Cat commented 1 year ago

Sorry. How i can get array values from plc with my custom data type. I can`t create json request.

KircMax commented 1 year ago

Hi @Little-Cat... I'd need a bit more details... I guess you are having a DB with a custom data type and you want to read the values of arrays inside that one using the Web-API?

Little-Cat commented 1 year ago

Thanks. Yes. You are right. I need read and write data from array with custom data type. { String name; Byte id; String value } as examle. I can get Browse variables over WebApi but i don`t know how I can read it. Sorry for my English.

KircMax commented 1 year ago

All right and this part of the readme does not help you with that?

https://github.com/siemens/simatic-s7-webserver-api#plcprogram-browse-read-and-write

If you can browse the variable you should be able to read the sub-values just the same way let's say there's a custom datatype "cumstomudt" called "myudt" inside a DB called "mydb" it contains a bool called "bool" and an array[0..1] of byte called "arr" Now you should be able to read the sub-values like the following: await requestHandler.PlcProgramRead("\"mydb\".\"myudt\".\"bool\"") Or for the array: requestHandler.PlcProgramRead("\"mydb\".\"myudt\".\"arr\"[0]")

All right? You could also try using the plcprogramhandler but the readstructvychildvalues might not be working for the array ...

Little-Cat commented 1 year ago

Yes. It is true. I can read separate variables from each array. But i need read all 50 array variableas at one time. As i can read it in the modbus, for example "read(array, 50)" where array = Array.of(my UDT data type). For reading each variables separate i must create syntax for each variable. Too long.

KircMax commented 1 year ago

I think I got you now. To be honest, right now what you want to do is afaik not fully supported by the Web-API, but you can try using the PlcProgramHandler, I tried making a first draft to read all the sub-values of an array via 1 bulk request and set the values accordingly. Of course you can also just build that bulk request and do the assignment accordingly (you'll have to save the request id to know which array element the response belongs to). Maybe you could try sending a request to read with raw for the array "head" but as I said - I'm not sure that's supported... if you absolutely want to have the data in one "big" encoded stream you might want to check wether you want to use OPC UA for that...

Little-Cat commented 1 year ago

Thanks a lot