g. Create a remote control client-server application

There are many problems where remote control of multiple microcontrollers or control boards is essential. One example is a robot that has a Windows based microcomputer, which connects to the main computer via wireless Ethernet or other TCP/IP capable physical network.

A client-server application (Remote access example.zip in Downloads section) consists of a server application and a client application. In our case SVHomeControlCenter v3.2 server application has already been developed. It requires Windows operating system with .NET 4.0 framework (http://www.microsoft.com/en-us/download/details.aspx?id=17718) and Windows 7 SDK (http://www.microsoft.com/en-us/download/details.aspx?id=18950). After the installation of .NET 4.0 framework and Windows 7 SDK runtime completes copy SVHomeControlCenter v3.2.exe and SVLIB_PIC18F24J50 v2.1.NET4.dll to the same folder. If you want the server application to start automatically, you may also copy a link to it into the Start Up folder.

Client PCs also need Windows 7 SDK runtime and .NET 4.0 framework installed. Client application is customizable. Remote access example folder inside Remote access example.zip file. The example is a working application with source code based in SVPIC18F2xJ50_TCP_IP.dll. The DLL has only a few powerful functions that give you remote control over the K8055 or K8055N compatible control board inputs and outputs.

The library is initially loaded with the following statement:

RPIC = New SVPIC18F2xJ50_TCP_IP.SVPIC18F2xJ50_TCP_IP(ServerIP, LBX_CommandHistory)

ServerIP is an IP address of the server PC where SVHomeControlCenter v3.2 application runs. LBX_CommandHistory is a pointer to a ListBox object, where communication control messages are printed. You may set it to Nothing, if you want to omit control messaging.

The commands to remote control board are sent by SendCommandString function. The function has two input parameters: command string and pointer to a ListBox object. The later may be omitted by specifying Nothing. Here is an example:

RPIC.SendCommandString("1,0,1,1", LBX_CommandHistory)

The command string consists of four parameters separated by a comma. The parameters are as follows:

“<command>, <number of control board (0, 1, 2 or 3)>, <parameter 1>, <parameter 2>, …”

Accessible control command is:

Reading of analog and digital inputs is done by the following command:

RPIC.GetAllDevicesStatuses(Nothing)

The command stores results to two-dimensional table DEVICEstatus(<control board number>,<input number>).

All values in the table are 8-bit (0..255). Therefore, 10-bit A/D values are represented by two fields in the table. Here is an example on how to read 10-bit A/D channels 0 through 3 values:

AD1val = (CInt(RPIC.DEVICEstatus(0, 6)) << 2) + CInt(RPIC.DEVICEstatus(0, 8))

AD2val = (CInt(RPIC.DEVICEstatus(0, 7)) << 2) + CInt(RPIC.DEVICEstatus(0, 9))

AD3val = (CInt(RPIC.DEVICEstatus(1, 6)) << 2) + CInt(RPIC.DEVICEstatus(1, 8))

AD4val = (CInt(RPIC.DEVICEstatus(1, 7)) << 2) + CInt(RPIC.DEVICEstatus(1, 9))

A/D channels 0 and 1 reside in control board 0, while A/D channels 3 and 4 reside on control board 1.

Digital channels are read five Boolean 8-bit fields (1 through 5)

value = RPIC.DEVICEstatus(<device>, <digital channel number>)

If value is greater than 0, the digital channel value is logical 1, otherwise digital channel value is logical 0. Here are examples on how to read digital channels:

Function v01(x As Integer) As String

If x > 0 Then

v01 = "1"

Else

v01 = "0"

End If

End Function

LbI2.Text = v01(RPIC.DEVICEstatus(0, 2))

LbI3.Text = v01(RPIC.DEVICEstatus(0, 3))

LbI4.Text = v01(RPIC.DEVICEstatus(0, 4))

LbI5.Text = v01(RPIC.DEVICEstatus(0, 5))

LbI11.Text = v01(RPIC.DEVICEstatus(1, 1))

LbI12.Text = v01(RPIC.DEVICEstatus(1, 2))

LbI13.Text = v01(RPIC.DEVICEstatus(1, 3))

LbI14.Text = v01(RPIC.DEVICEstatus(1, 4))

LbI15.Text = v01(RPIC.DEVICEstatus(1, 5))

….

There is only one more important control function to mention. Disconnect must be called as application closes to terminate the client communication channel to the server:

Private Sub Form1_Disposed(sender As Object, e As System.EventArgs) Handles Me.Disposed

RPIC.Disconnect(LBX_CommandHistory)

End Sub

LBX_CommandHistory parameter must be replaced by Nothing if control reporting is omitted.