Expose variables for viewing on iPhone

A repetitive sequence of steps will expose each variable for iPhone remote.

The exposed variables

If you have a chance to test run this demo, you should be able to enter an array of items separated by semicolon and see each item manifests into a row in the iPhone table view. This is how it works. In Demo1 example, two variables are exposed.The first variable is linked to the first textbox (1).The iQuipment iPhone app first retrieves the string linked to this exposed variable then parse the string into different sub strings and assign each sub string to a table row..

The second exposed variable is linked to the second textbox (2). iQuipment iPhone app send back the item that you tapped via the second variable. The value is then updated on the textbox (2).

How to expose the two variables

Variables are grouped by view. You are free to name the view or variable. In the Demo 1 example, we made up a view name called "myViewName." We then made up two variables "dataName_rowArray" and "dataName_selectedItem." To expose these two variables, just assign a null or a value to these variables as shown below:

INFOMATO.WCF.DataExchangeService.servicePostData(myViewName, dataName_rowArray, "");
INFOMATO.WCF.DataExchangeService.servicePostData(myViewName, dataName_selectedItem, "");

Link the first textfield to an exposed varialbe

Now open Form1.cs of Demo 1 in Designer view. Double click on the textbox. Visual Studio should bring you to the code below:

private void textBox1_TextChanged(object sender, EventArgs e)
{
//add this line
INFOMATO.WCF.DataExchangeService.servicePostData(myViewName, dataName_rowArray, textBox1.Text); //exposed and update variable dataName_rowArray;
}

The function textBox1_TextChanged is self-generated by Visual Studio. All you need to do is fill in the code enclosed by the curly brackets. This function is executed whenever the textBox value changes. So we made it execute INFOMATO.WCF.DataExchangeService.servicePostData to inform iQuipment PC the value has changed.

More on INFOMATO.WCF.DataExchangeService.servicePostData

This function is important because every time you want to expose or update a variable for monitoring purposes (get value), you need to recall this function. There is another function for remote control purposes (set value) which we will discuss later. Here, we will focus only on getting the value.

This function encompasses three parameters (viewName, dataName, dataValue). It tells the iQuipment PC (the PC agent) that the dataName within the viewName has a value that equals dataValue.

You are free to name ViewName and dataName as you wish. Just be sure to make the combination descriptive enough to create a relationship to the exposed variable. For ease of organization, you should consider using one viewName for each Window Form.

- INFOMATO.WCF.DataExchangeService.servicePostData has another version that takes in the requester's IP. If you need to response to each client differently, use this version.

Client (iPhone) set data

So far we have discussed to send data from your Windows application to the iPhone (or other i-Devices). Next, we will discuss how you can receive data from the iPhone due to the user's tap action.

By suscrbing the event INFOMATO.WCF.DataExchangeService.clientSetData_ID_Event, your code is now listening to the client (the iPhone) set-data event. If any of the exposed variables value has changed due to a client action, it will triggers this event and execute the function DataExchangeService_clientSetData_ID_Event.

public Form1()
{
...
INFOMATO.WCF.DataExchangeService.clientSetData_ID_Event +=
new INFOMATO.WCF.DataExchangeService.ClientSetData_ID_Delegate(DataExchangeService_clientSetData_ID_Event); //event triggered by client set data
...
}

 

void DataExchangeService_clientSetData_ID_Event(string clientIP, string viewName, string dataName, object dataValue, long processID)
{
if (viewName == myViewName && dataName == dataName_selectedItem)
UpdateTextGUIObject(textBox2, (string)dataValue);
}

In this function, it matches the viewName and dataName with the second exposed variable's viewName and dataName. When it does, it update the textBox2 value.

Unfortunately, update the textBox2 value is not straightforward because the event may be handled by a thread that is not the UI thread. When a client request for data, the incoming thread often is not the main thread that capable of handling UI (textbox, checkbox values etc.). Special UI thead safe procedure needs to be implemented to take care of READ or WRITE.

Only main thread is allowed to change a user interface value. We take care of this in the UpdateTextGUIObject function, where we check if the handling thread is a UI thread, if not, we do nothing and launch a delegate to execute the UpdateTextGUIObject function again. We will keep relaunch the function until a UI thread happens to be assigned for this function.

Previous Lesson: Initialize INFOMATO.WCF in your Program.cs file Table of Contents Next Lesson: Configure a view (UI) for iPhone