automed Windows SDK

The automed SDK is now available to be integrated with your Windows application. This document will help you to understand our automed Windows Software Development Kit (SDK) and show you step by step how to use it in your Windows application

             

 


Pre-requisites

  1. Visual Studio IDE
  2. Download automed-user-control.dll, and add it as a reference in your project, along with System.Data.SQLite and System.Runtime.Serialization.

 


Step 1:

Use the following link to download the automed C# SDK for windows applications.

Click to download the automed Windows SDK

 

 


Step 2:

Import the automed SDK into your Windows application

Create or open your windows application project. Right-click on ‘References’ and go to ‘Browse’ to import automed-user-control.dll into your project.

 


Step 3:

 Import the automed SDK in your class

using automed_user_control;

In your class, create an automed object as a local variable and then initialize it in the constructor of your class.

private automed automedUtil;
public Form1()
{
    InitializeComponent();
    automedUtil = new automed();
}

You can also create an automed floating button by calling this method in the constructor or during the Form_load event.

automedUtil.createAutomedButton("192.168.137").Show();

**Note: you might need to replace the IP address ‘192.168.137’ with the IP address of the hotspot. For more details, you can refer to Step 4 below.

Now we can move to the next step: connect to the automed device


Step 4:

The connection between your computer and the automed device is based on your computer’s hotspot. Open the hotspot on your computer and adjust the settings for the following:

Windows 8 and above

First, search for “Change mobile hotspot settings” in the search bar as shown below.

Secondly, you need to change the name of the hotspot to “AutoMed” and the password to “12345678”, and turn the hotspot on. The final result should be the same as below.

Windows 8 below

You may follow the instruction through this Youtube video (https://www.youtube.com/watch?v=2pvK-6321ig). At 1:46 minute, put ‘ssid’ as AutoMed and ‘key’ as 12345678

At last, if you have called the ‘createAutomedButton’ function as illustrated above, you shall be able to connect your automed device to the app now. (**Note: the login might take a few minutes)

Otherwise, you can also integrate the ‘connect’ function into your project.

await automedUtil.connect("192.168.137");

**Note: you need to replace the ‘192.168.137’ with the IP address of the mobile hotspot, which can be obtained by typing ‘netsh interface ip show address’ in Windows Command Prompt, as pictured below:

Also, to integrate the ‘disconnect’ function, you can just simply call:

automedUtil.disconnect();

Once your app is running on your Windows device and you see at least one device already connected to your hotspot, by then you can connect to automed device via the ‘connect’ function or the automed floating button as mentioned above.


Step 5:

Once you connected to the automed device successfully, you can use the two basic functions: Prime and RFID

1. Prime is the function to set the device in Prime mode. If you are using the automed floating button, simply click on ‘Prime’. Otherwise, you would have to call the ‘prime’ function as below, and a prime list should pop up when the user triggers the ‘prime’ function in your project.

automedUtil.prime();

User can turn on/off the prime by clicking on the ‘Prime’ button.

2. RFID is the function to set the device in RFID reading mode. Same as Prime. The only difference is we have two options: individual RFID mode and group RFID mode.

automedUtil.RFID();

These are the two basic functions to control automed devices. Next step is for configuring the devices’ doses. The process is complicated so please make sure to follow the tutorial step by step.


Step 6 :

Get values needed to configure the adapter

What you need in your app:

  1. Token (Authorization)
  2. User ID (the user ID in our automed system)
  3. Farm ID (aka site ID)
  4. Industry type of users farm (can only be “Beef”, “Export Beef”, “Pork”, “Dairy Cattle”, “Dairy Sheep”, “Sheep”)
  5. amID (the medication ID in our automed system)

How to get:

  • Token (online mode): you need to ask the users for their emails and passwords of their automed accounts to login. The function to call is:
    Tuple<bool, String> response1 = await automedUtil.loginOnline(usernameTxt.Text, passwordTxt.Text);
    if (response1.Item1 == true)
    {
        DataContractJsonSerializer deserializer = new DataContractJsonSerializer(typeof(User));
        MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(response1.Item2));
        var login = (User)deserializer.ReadObject(stream);
        token = login.token;
        tokenLb.Text = "TokenStatus: " + login.token;
        statusLb.Text = "LoginStatus: " + Convert.ToString(response1.Item1);
    }

    As you can see, you will also need to create a ‘User’ class to parse the json as follows:

    [DataContract]
    class User
    {
        [DataMember]
        public String email { get; set; }
    
        [DataMember]
        public String password { get; set; }
    
        [DataMember]
        public String username { get; set; }
    
        [DataMember]
        public String id { get; set; }
    
        [DataMember]
        public String farm { get; set; }
    
        [DataMember]
        public String token { get; set; }
    }

    It is an Http GET request to get the token from our server so it needs an internet connection. As shown in the picture, you will be able to know whether the request has succeeded by checking whether ‘response1.Item1’ is true. Also, you have to store the token somewhere else for later use.

  • Token (offline mode): you need to ask the users for their 6 digits code and secret from their automed accounts. The function to call is:
    Tuple<bool, String> response1 = automedUtil.loginOffline(sixDigitsTxt.Text, secrectTxt.Text);
    if (response1.Item1 == true)
    {
        DataContractJsonSerializer deserializer = new DataContractJsonSerializer(typeof(User));
        MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(response1.Item2));
        var login = (User)deserializer.ReadObject(stream);
        token = login.token;
        tokenLb.Text = "TokenStatus: " + login.token;
        statusLb.Text = "LoginStatus: " + Convert.ToString(response1.Item1);
    }

    **Note: The User object is the same as above. This authentication can be done without the internet. However, user is required to obtain those credentials from the automed Web Portal beforehand, and those credentials will expire every month. The 6 digits number and secret can be obtained in ‘Account’ -> ‘Integration’ by clicking on ‘Generate Two Factor Key’ from the automed Web Portal.

 

  • userID: once you have the token, you can call another function to get the user details:
    Tuple<bool, String> response2 = await automedUtil.getUserDetails(login.token);
    if (response2.Item1 == true)
    {
        deserializer = new DataContractJsonSerializer(typeof(User));
        stream = new MemoryStream(Encoding.UTF8.GetBytes(response2.Item2));
        var user = (User)deserializer.ReadObject(stream);
        if (user != null)
        {
            userID = user.id;
            userLb.Text = "UserStatus: " + user.id;
        }
    }

    It is also an Http GET request to get the user details from our server so it needs an internet connection. As shown in the picture, you will be able to know whether the request is succeed by checking whether ‘response2.Item1’ is true. Also, you have to store the user ID somewhere else for later use.

  • farmID and industryType: same with userID, you can get them by calling
    Tuple<bool, String> response3 = await automedUtil.getFarms(login.token);
    if(response3.Item1 == true)
    {
        deserializer = new DataContractJsonSerializer(typeof(List<Farm>));
        stream = new MemoryStream(Encoding.UTF8.GetBytes(response3.Item2));
        var farms = (List<Farm>)deserializer.ReadObject(stream);
        farmList.DataSource = farms;
        farmList.ValueMember = "id";
        farmList.DisplayMember = "name";
    }
    [DataContract]
    class Farm
    {
        [DataMember]
        public String id { get; set; }
    
        [DataMember]
        public String name { get; set; }
    
        [DataMember]
        public String industry { get; set; }
    }

    Note: User might have access to multiple farms. So the json here should be an array contains all farms’ information. You need to store farmID and industryType for each farm so the user can select it later.

  • amID: Once you get the farmID, you can call this function. The available industries at the moment are “Beef”, “Dairy Cattle”, “Dairy Sheep”, “Export Beef”, “Pork”, and “Sheep”.
    //For offline login you will need to define the industry of the offline farm beforehand.
    farm.industry = "Pork";
    //For online login
    Tuple<bool, String> response4 = await automedUtil.getRefTreatmentData(farm.id, token, farm.industry);
    DataContractJsonSerializer deserializer = new DataContractJsonSerializer(typeof(List<RefTreatment>));
    MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(response4.Item2));
    var treatments = (List<RefTreatment>)deserializer.ReadObject(stream);
    refTrList.DataSource = treatments;
    refTrList.ValueMember = "amID";
    refTrList.DisplayMember = "amProduct";

     

    [DataContract]
    class RefTreatment
    {
        [DataMember]
        public int amID { get; set; }
    
        [DataMember]
        public String amProduct { get; set; }
    
    }

Important Note: Your application must have your own medication management system. What you need to do once you get the refTreatment here is to connect your medication with the refTreatment’s medication. The best way to do it is to compare the name (in refTreatment we call it ‘amProduct’). Find the correct amID value in refTreatment for your medication. You will need it for configure the adapter of the automed device.

 


Step 7:

Configure the adapter of the automed device to make it dose!

We have three dose type:

  1. Fix dose                                      (The device will do a fixed dose based on the medication that is configured to the adapter)
    RefTreatment med = (RefTreatment)refTrList.SelectedItem;
    //For offline login you will need to define the industry of the offline farm beforehand.
    farm.industry = "Pork";
    //For online login
    automedUtil.configureAdapterForFixDose(automedUtil.devices[deviceList.SelectedIndex], 
        med.amID,userID,farm.id,farm.industry);

    Input: device should be an automedDevice object; amID shoud be an Int; userID, farm.id and farm.industry should be String

  2. Manual dose                              (The device will do the amount of dose which is input by the user.)
    RefTreatment med = (RefTreatment)refTrList.SelectedItem;
    //For offline login you will need to define the industry of the offline farm beforehand.
    farm.industry = "Pork";
    //For online login
    automedUtil.configureAdapterForManualDose(automedUtil.devices[deviceList.SelectedIndex], 
        med.amID, userID, farm.id, farm.industry, value);

    Input: device should be an automedDevice object; amID shoud be an Int; userID, farm.id and farm.industry should be String; value should be a Double.

  3. Weight-based dose                   (The device will do the dose which is calculated by the weight of animals)
    RefTreatment med = (RefTreatment)refTrList.SelectedItem;
    //For offline login you will need to define the industry of the offline farm beforehand.
    farm.industry = "Pork";
    //For online login
    automedUtil.configureAdapterForWeightBasedDose(automedUtil.devices[deviceList.SelectedIndex], 
        med.amID, userID, farm.id, farm.industry, weight);

    Input: device should be an automedDevice object; amID shoud be an Int; userID, farm.id and farm.industry should be String; weight should be a Double.

Important Note: Before configuring the weight-based dose, it is better to set the preferred weight unit. The default weight unit is ‘lbs’. You can set it by calling this function:

automedUtil.setUnit("kg");
automedUtil.setUnit("lbs");

Once the automed device is configured, the user can administer the dose and the treatment record will be stored in the local database on the computer. The next step is to show you how to get those records.


Step 8:

  1. Get the latest treatment record:
    automedUtil.getLatestTreatmentRecord(farm.id).amId;
    automedUtil.getLatestTreatmentRecord(farm.id).amProduct;

    Calling this will get you a Treatment object. You may create a LdTreatment class to accept the object with your own preference.

  2. Get all of the treatment records in the local database, this will return a List<LdTreatment> to you. Re-use the LdTreatment class that is created in your project.
    for (int i = 0; i< automedUtil.getAllTreatmentRecords(farm.id).Count; i++)
    {
        int id = automedUtil.getAllTreatmentRecords(farm.id)[i].amId;
        String name = automedUtil.getAllTreatmentRecords(farm.id)[i].amProduct;
    }
  3. Sync records from the automed device. We have a new feature called Set&Forget for the automed device. All treatments administered without connecting to the app will store in the device itself. You need to call this function to get them and store them into the local database:
    automedUtil.syncRecordsFromDevice(automedUtil.devices[deviceList.SelectedIndex]);

    Note: you need to ask the user to select a device first before you call this function.

The above steps should include all functions your app can have to control the automed device. Have fun and enjoy the development!


More Information

There is more information stored in the automed Device object such as MAC address, fwVer(firmware version of the device) and AdapterSettings(adapter settings). You can write your own code to get those value if you need. If you have any question about automed SDK for Windows or this tutorial, feel free to contact us at support@automed.io.

 

Related Content

The following links relate to content within this document.

Still need help?

Can’t find the answer you’re looking for?
Don’t worry we’re here to help!

Request Support

Send us your question over email.

Phone

Send us your question over email.