IDTech Windows SDK Guide  3.2.4.393
API reference for Visual Studio .Net
Using ZMQ Server/Client

Zero Messaging Queue (ZMQ) allows you to turn your PC into a server that can service remote requests from IDTech ZMQ Clients.

IDTech ZMQ Server SDK can be utilized to create a server app that controls locally connected IDTech devices (usually USB connected). The ZMQ Server will spin up a TCP/IP listener socket that ZMQ Clients can connect to. This not only allows you ZMQ Clients to be located in remote locations, but also give you the ability to control the IDTech device connected to the ZMQ Server from muliple locations/clients.

Setting Up ZMQ Server App

Source code and compiled server app can be found at IDTech Knowledge Base at the following link:
https://atlassian.idtechproducts.com/confluence/download/attachments/30479625/IDTech_ZMQ_Server_App_Source_Code.zip?api=v2

For your project, import from NuGet the library IDTechZMQ_Server.

After the library is linked, add it's refernce to your form/project

using IDTechZMQ_Server;

If you are building a GUI interface and would like the server app to display/report information, you have the following four callback you can optionally utilize:

void deviceListChanged(List<string> connectedDevices)
{
//whenever devices are attached/removed, this callback will be updated with the connected devices
}
void clientListChanged(List<string> connectedClients)
{
//whenever clients are connected to the server, this callback will be updated with the connected clients
}
void deviceStateChanged(string ident, string client, int state)
{
//whenever device stat changes, this callback will report the client and new state
}
public void communicationCallback(bool incoming, string json)
{
//This callback will report all the data going to/from the devices. Used for debugging/extended logging
}

You set the callback usually upon form/project initialization by utilizing the RemoteAPI class

public Form1()
{
InitializeComponent();
RemoteAPI.setDeviceListChangedCallback(deviceListChanged);
RemoteAPI.setClientListChangedCallback(clientListChanged);
RemoteAPI.setDeviceStateChangedCallback(deviceStateChanged);
RemoteAPI.setCommunicationCallback(communicationCallback);
}

To start the ZMQ server, you utilize the following API from the RemoteAPI class:

public bool ZMQServer(bool enable, string identifier = "ZMQ_SERVER", string address = "127.0.0.1", int port = 13599);
  • enable: True = turn ON server, False = Stop Server
  • identifier: The name to call the server instance
  • address: The IP address to bind the listening socket to
  • port: The port to bind the listening socket to

The RemoteAPI class has a singleton instance called SharedController.

Example to start and stop the ZMQ Server:

//Start Server
RemoteAPI.SharedController.ZMQServer(true); //spins up server using name "ZMQ_SERVER", address 127.0.0.1 and port 13559
//Stop Server
RemoteAPI.SharedController.ZMQServer(false);

Setting Up ZMQ Client App

The ZMQ Client SDK device API are in the IDT_Device class which mirrors the same methods/signatures as the IDT_Device class in our main IDTechSDK_STD SDK. This means the implementation is identical to using IDTechSDK_STD SDK (when using IDT_Device class and not individual device classes like IDT_VP330 and IDT_NEO2), except for the device connection.

When using IDTechSDK_STD, you enable USB and devices automaically appear. When using ZMQ Client SDK, you must first connect to the ZMQ Server app, and once that is established, any devices connected to ZMQ Server app will be passed to the ZMQ Client app as if they are locally attached.

You establish your application as you would if using the regular IDTechSDK_STD, but you must only send device commands using IDT_Device class.

Establish/test your application for local device access using IDTechSDK_STD. Once you are happy with the operation and ready to convert it to a ZMQ Client app, remove the link to IDTechSDK_STD, and instead import from NuGet IDTechZMQ_Client.

There should be no error in your app after importing the client SDK. If there are any, it probably is because your app using individual device class calls (IDT_VP3300.SharedController.device_getFirmawareVersion(ref ver, ident)), instead of the IDT_Device version (IDT_Device.SharedController.device_getFirmawareVersion(ref ver, ident)). Please update any of your existing methods if this is the case.

To connect/disconnect your client to the server app, you use the following API call

//IDT_Device class
public static bool client_remoteCommandClient(bool enable, string identifier = "", string address = "127.0.0.1", int port = 13599)
  • enable: True = turn ON client, False = Stop Client
  • identifier: The name to call your client instance
  • address: The IP address where the server is running at
  • port: The port were the server is running at

    Example to start and stop the ZMQ Client:

//Start Client
IDT_Device.client_remoteCommandClient(true,"Store1"); //spins up client using name "Store", and attempts to connect to server at address 127.0.0.1 and port 13559
//Stop Client
IDT_Device.client_remoteCommandClient(false);
Get/Set Wait Time
This function will allow you to define how long the client is willing to wait for a command to execute when the server reports the device is busy from a request from another client.
//IDT_Device Class
public static void client_setWaitTime(int time)
public static int client_getWaitTime()
//NOTE: time is in milliseconds

ZMQ Server / Client Example

The following steps will allow you to execute a ZMQ Server/Client environment using sample code provided by IDTech. This requires you to open IDTech uDemo source code in Visual Studio and adjust the imported SDK.

Please download and unzip the ZMQ Server App

https://atlassian.idtechproducts.com/confluence/download/attachments/30479625/IDTech_ZMQ_Server_App_Source_Code.zip?api=v2

Please download and unzip IDTech uDemo source code

https://atlassian.idtechproducts.com/confluence/download/attachments/30479625/dot%20NET%20SDK%20Demo%20Source%20Code.zip?api=v2

In Visual Studio, open uDemo with file SDKDemo.csproj

udemo.png

Right-click on SDKDemo project, and Manage Nuget Packages...

nuget1.png

Under the Installed tab, click the red X to REMOVE IDTechSDK_STD

removeIDTech.png

Under the Browse tab, Browse and install IDTechSDK_Client

installIDTech.png

Plug a device into your PC, example VP3350

In the ZMQ Sever App bin/Release folder, run the server app ZMQ_Server_App.exe

runserver.png
serverapp.png

Click "Start Server" and enter one of the valid IP address the server NIC has access to. In our example, we will use 10.211.55.27

serverip.png

You should see the server successfully start, and the VP3300 as connected device

serverstarted.png

Back in Visual Studio, run uDemo. Select Menu->Enable Client.

You will be asked to provide a name of your client. Example "SDK_DEMO".

You will be asked the address of the server. In our example, we are using 10.211.55.27

You will now see uDemo connect the client, and you will see the server app serving the client.

At this point, you can now send commands to the VP3300.

clientconnect.png
serverconnect.png