In an earlier article, we saw how to use the (still not officially released) remote gRPC server feature of the PLCnext Runtime. In that article, protobuf files were required to call gRPC services using grpcurl. Protobuf files define the services, methods and messages that a server provides to gRPC clients.
The use of protobuf files can be awkward. For example, a client needs to make sure that the version of the protobuf files it is using always matches the version of the gRPC server that's being used. In PLCnext Control firmware version 2025.0, gRPC server reflection is introduced as a new feature. Reflection allows gRPC clients like grpcurl to discover the available services on a gRPC server - and even to use those services - without the need for protobuf files.
This guide demonstrates how reflection can be used by grpcurl to discover and use the gRPC services on a PLCnext Control device running firmware version 2025.0 or later.
Procedure
- Complete the steps in the earlier article to set up the remote gRPC server on the PLC, and to set up grpcurl on the gRPC client. It is not necessary to download the protobuf files to the client machine.
Now try the following commands on the gRPC client machine:
-
List the gRPC services available on the PLCnext Control device with IP address 192.168.1.10.
grpcurl -insecure 192.168.1.10:50051 list
Response:
Arp.Device.Interface.Services.Grpc.IDeviceControlService Arp.Device.Interface.Services.Grpc.IDeviceInfoService Arp.Device.Interface.Services.Grpc.IDeviceSettingsService Arp.Device.Interface.Services.Grpc.IDeviceStatusService Arp.Io.Axioline.Services.Grpc.IAcyclicCommunicationService Arp.Io.Axioline.Services.Grpc.IAxioMasterService Arp.Plc.Gds.Services.Grpc.IDataAccessService Arp.Plc.Gds.Services.Grpc.IForceService Arp.Plc.Gds.Services.Grpc.ISubscriptionService Arp.Services.DataLogger.Services.Grpc.IDataLoggerService2 Arp.Services.NotificationLogger.Services.Grpc.INotificationLoggerService Arp.System.Commons.Services.Io.Grpc.IDirectoryService Arp.System.Commons.Services.Io.Grpc.IFileService Arp.System.Commons.Services.Io.Grpc.IFileSystemInfoService Arp.System.Lm.Services.Grpc.ILicenseStatusService Arp.System.Nm.Services.Grpc.INotificationManagerService Arp.System.Security.Services.Grpc.IAuthenticationService Arp.System.Um.Services.Grpc.IAuthorizationInfoService Arp.System.Um.Services.Grpc.IPasswordAuthenticationService grpc.reflection.v1.ServerReflection grpc.reflection.v1alpha.ServerReflection
-
List the methods that are available on the IDeviceStatusService.
grpcurl -insecure 192.168.1.10:50051 describe Arp.Device.Interface.Services.Grpc.IDeviceStatusService
Response:
Arp.Device.Interface.Services.Grpc.IDeviceStatusService is a service: service IDeviceStatusService { rpc GetItem ( .Arp.Device.Interface.Services.Grpc.IDeviceStatusServiceGetItemRequest ) returns ( .Arp.Device.Interface.Services.Grpc.IDeviceStatusServiceGetItemResponse ); rpc GetItems ( .Arp.Device.Interface.Services.Grpc.IDeviceStatusServiceGetItemsRequest ) returns ( .Arp.Device.Interface.Services.Grpc.IDeviceStatusServiceGetItemsResponse ); }
-
Get details of the message that is used as the input parameter on the GetItem method.
grpcurl -insecure 192.168.1.10:50051 describe Arp.Device.Interface.Services.Grpc.IDeviceStatusServiceGetItemRequest
Response:
Arp.Device.Interface.Services.Grpc.IDeviceStatusServiceGetItemRequest is a message: message IDeviceStatusServiceGetItemRequest { string identifier = 1; }
-
Retrieve the Board Temperature value from the PLCnext Control device, without any reference to protobuf files:
grpcurl -insecure -format json -d '{"identifier":"Status.Board.Temperature.Centigrade"}' 192.168.1.10:50051 Arp.Device.Interface.Services.Grpc.IDeviceStatusService.GetItem
Response:
{ "_ReturnValue": { "TypeCode": "CT_Int8", "Int8Value": 46 } }
Next Steps
The above examples use the -insecure
option to avoid the need for security certificates. If secure communications is necessary, then this can be done in the same way as shown in another earlier Makers Blog post.
FAQ
Can gRPC clients written in python, C#, C++, or any other language, also use reflection?
Yes, in theory, but this may be easy or difficult depending on the support for this feature provided by the gRPC client library(s) available for that language. You should be able to find the answer to this question online, for your preferred language.
For more help ...
Use grpcurl -help
to get more information on available options.
For questions about the gRPC Server in the PLCnext Runtime, please use the PLCnext Community Forum.
Leave a Reply
You must be logged in to post a comment.