Using Vendor defined commands
Hi all:
Attached is a recent thread posted to'rfidsupp@microsoft' that I thought would be useful to share with the community.
Mail thread copied below, and code samples pasted as well.
Does Microsoft have any examples for vendor defined commands? The documentation is (IMO) very unclear (looking at the latest html help in the RC1. I've also looked at the DSPI word document). I'm attempting to make use of VendorDefinedCommand to allow applications to send a custom vendor command. This command must allow passing of two parameters - an integer and a list of strings. The method for passing these parameters seems to be the use of the VendorDefinedParameters property. This being basically a dictionary of string key / object value pairs. Now what is very unclear to me, is what types of object are valid to pass. For example, is it valid to pass a string array - which would be very handy in this use case, or is there a limited set of valid types? My guess is that the type must be serializable and preferably must be defined either in one of the .NET framework assemblies or in the BizTalk assemblies, so as to avoid requiring assembly deployment for client applications which may well be deployed on different systems from the BizTalk RFID system which has the provider and controls the device in question. Correct?
[Abhishea]Correct. There is a limited set of valid types, which includes (at a very high level) primitive types, arrays of primitive types, strings, arrays of strings, and types defined in the BizTalk RFID SPISDK and Design DLL. We will rev up our documentation to have more details on this.
However again how to do this? No examples (that I can see), and unclear documentation.
In addition, passing reference is made in the documentation to the need to describe the data you wish to pass using VendorExtensionsEntityMetadata (under Development -> Provider Development -> Implementing Vendor Extensions -> How to Create a Vendor-Defined Parameter or Class in the html help doc).
[Abhishea] There are 6 extension points to the DSPI:
-Command
-Response
-TransportSettings
-ManagementEvent
-Observation
-PrintTemplateField
There are 2 kinds of extensions to each of these types:
-Extending a standard DSPI type e.g. adding Vendor parameters to TcpTransportSettings.
-Defining a new vendor extension of this type e.g. implementing a new VendorTransportSettings class
You must expose meta data about all the extension points implemented in the provider. This can be done via the ProviderMetadata.VendorExtensionsEntityMetadata property.
Attached is an example, with the scenario being:
Implement a new VendorDefinedCommand called SetProgramOnDevice
-In that case, the provider must also implement a new VendorDefinedResponse also called SetProgramOnDevice
VendorExtensions.cs contains some sample code on how to create metadata on vendor extensions.
VendorExtensionsClient.cs contains some sample code on how a client can use the vendor extensions.
Can anyone provide help on this?
VendorExtensions.cs
sing
System;using
System.Collections.Generic;using
System.Collections.ObjectModel;using
System.IO.SensorServices.Rfid.Client;using
System.Text;using
Microsoft.SensorServices.Rfid;using
Microsoft.SensorServices.Rfid.Dspi;namespace
ScratchCSharp{
class VendorExtensions{
privatestaticvoid DefineVendorExtensionsMetadata(){
//Lets take an example of the provider implementing the following extensions:////- Implement a new VendorDefinedCommand called SetProgramOnDevice// o In that case, the provider must also implement a new VendorDefinedResponse also called SetProgramOnDevice////- Implements a new transport setting called MyVendorTransportSetting//- Extends observations as follows:// o Adds RSSI to the dictionary of the TagReadEvent// o Adds a new VendorDefinedEvent called ButtonPressedEventDictionary vendorExtensions =newDictionary();//////////////////////////////////////////////////////////////// Extension 1: A vendor defined command called SetProgramOnDevice////////////////////////////////////////////////////////////////Define the metadata for the command extensionDictionary<string, VendorEntityParameterMetadata> parametersForSetProgramOnDevice =newDictionary<string, VendorEntityParameterMetadata>();//Parameter1 is the GPIO port for whose state change we do somethingCollection<object> availableGPIOPorts =newCollection<object>();availableGPIOPorts.Add(
"1");availableGPIOPorts.Add(
"2");availableGPIOPorts.Add(
"3");availableGPIOPorts.Add(
"4");//Use the VendorEntityParameterMetadata corresponding to Valueset (similar to enums)parametersForSetProgramOnDevice.Add(
"gpIOPort",new VendorEntityParameterMetadata(typeof(string),"The GPIO port, for whose state change event, some action shuld be taken",null,true,availableGPIOPorts
));
//Parameter2 is the value the GPIO port should change to, for the action to execute//Use the VendorEntityParameterMetadata corresponding to max (1) / min (0)parametersForSetProgramOnDevice.Add(
"newValue",new VendorEntityParameterMetadata(typeof(int),"The value the GPIO port should change to, for executing the action",1,
true,0,
1
));
//Parameter3 is the command that must be executed when the GPIO Port value changesCollection<object> availableActions =newCollection<object>();availableActions.Add(
"TurnOffRF");availableActions.Add(
"TurnOnRF");availableActions.Add(
"SetDenseMode");//Use the VendorEntityParameterMetadata corresponding to Valueset (similar to enums)parametersForSetProgramOnDevice.Add(
"action",new VendorEntityParameterMetadata(typeof(string),"The action to execute",availableActions[0],
true,availableActions
));
VendorEntityKey commandKey =
new VendorEntityKey(typeof(VendorDefinedCommand),"SetProgramOnDevice", EntityType.Command);VendorEntityMetadata commandMetadata =
new VendorEntityMetadata("Sets programs on the device",parametersForSetProgramOnDevice);
vendorExtensions[commandKey] = commandMetadata;
//////////////////////////////////////////////////////////////// Extension 2////////////////////////////////////////////////////////////////Define the metadata for the response to this commandVendorEntityKey responseKey =
new VendorEntityKey(typeof(VendorDefinedResponse),"SetProgramOnDevice", EntityType.Response);//.//.//Define the parameters in the dictionary returned//and add to vendorExtensions//.//////////////////////////////////////////////////////////////// Extension 3////////////////////////////////////////////////////////////////Define the metadata for the MyVendorTransportSettingVendorEntityKey myTransportVendorEntityKey =
new VendorEntityKey(typeof(VendorDefinedTransportSettings),"MyVendorTransportSetting", EntityType.TransportSettings);//.//.//Define the parameters which the vendor expects in the dictionary//and add to vendorExtensions////////////////////////////////////////////////////////////////// Extension 4//////////////////////////////////////////////////////////////VendorEntityKey tagReadEventExtension =
new VendorEntityKey(typeof(TagReadEvent), EntityType.Observation);//.//.//Define the parameters which the vendor returns in the dictionary in the TagReadEvent//and add to vendorExtensions//.//////////////////////////////////////////////////////////////// Extension 5//////////////////////////////////////////////////////////////VendorEntityKey buttonPressedEvent =
new VendorEntityKey(typeof(VendorDefinedEvent),"ButtonPressedEvent", EntityType.Observation);//.//.//Define the parameters which the vendor returns in the dictionary in the ButtonPressedEvent//and add to vendorExtensions//.ProviderMetadata myProviderMetadata =
new ProviderMetadata(
null,//provide some ProviderInformationnull,//provide some provider capabilities,null,//provide property meta datavendorExtensions,
null//provider device property metadata);
}
}
}
VendorExtensionsClient.cs
using
System;using
System.Collections.Generic;using
System.IO.SensorServices.Rfid.Client;using
System.Text;namespace
ScratchCSharp{
class VendorExtensionsClient{
privatestaticvoid ExecuteVendorCommands(){
//Set up the parameters for the vendor command://We must "TurnOnRF" when the value of gpio port no "2" becomes 1.VendorSpecificInformation inputParameters =
new VendorSpecificInformation();inputParameters.Add(
"gpIOPort","2");inputParameters.Add(
"newValue", 1);inputParameters.Add(
"action","TurnOnRF");VendorDefinedParameters vendorParameters =
new VendorDefinedParameters();vendorParameters.InputParameters = inputParameters;
using (DeviceConnection dc =new DeviceConnection("mydevice")){
dc.ExecuteVendorDefinedCommand(
null,//source name"MyVendorName",//vendor name"SetProgramOnDevice",//the name of the vendor extensionnull,//commandnull,//passcodevendorParameters
);
}
}
}
}

