Skip to main content

Past Blast

Featured Products

Stay in touch using the DEVBUSS RSS feeds.
 

News

Access PC information from your Pocket PC

Written by Pete Vickers  [author's bio]  [read 57956 times]
Edited by Derek

Download the code

Page 1  Page 2  Page 3 

As in the RDA project, we send a '~' as a terminator, as the Pocket PC reads data in 'chunks'.

Viewing the resulting XML in PIE results in

The Client

The client form is set out thus:-

and all positioning is handled in code. The 3 text boxes and the listview are invisible at first, and the tab control is disabled. We connect to the server on port 9898 (client connection has been fully covered in previous articles).

After connecting, we enable the 'Get Info' button. When we click on the 'Get Info' button, it simply sends the string 'INFO~' to the server. The server should do its stuff, and send us a buffer starting 'INFOOK'. If we get 'INFOER', the server has hit an error condition, and will send us back the error information. When the 'dataarrival' event fires, we do the same as on the server, i.e. collect all the data until we get a termination character.

Private Sub tcpClient_DataArrival _
  (ByVal bytesTotal As Long)
  If Trec = 0 Then
   Rbuff = ""
  End If
  tcpClient.GetData WkBuff
  Trec = Trec + bytesTotal
  Rbuff = Rbuff & WkBuff
  If InStr(WkBuff, "~") <> 0 Then 'End of data
   Trec = 0
   Rbuff = Mid(Rbuff, 1, Len(Rbuff) - 1)
   Process_The_Data
  End If
End Sub

We have a Process_The_Data sub, to deal with the data we get back from the server.

Private Sub Process_The_Data()
 Dim Obuff As String
 Dim WkErr
 Obuff = Mid(Rbuff, 7, Len(Rbuff) - 6)
 wkbuff = Mid(Rbuff, 1, 6)
 Select Case wkbuff
  Case "INFOOK"
   cmdClose.Enabled = True
   Create_The_File
   Process_The_XML_File
   Set_Up_The_Tab
  Case "INFOER"
   WkErr = Split(Obuff, ",")
   Err.Raise CLng(WkErr(0)), , WkErr(1)
  Case "CLOSOK"
   cmdretrieve.Enabled = False
   cmdClose.Enabled = False
   cmdConnect.Enabled = True
   tcpClient.Close
 End Select
End Sub

Our function return is 6 characters, so we split off the buffer accordingly. If we get an error, the server is returning us the error number, and the error message, so we can raise an error. We get the number and message by using the split function, and putting them in the variable WkErr.

Retrieving and formatting the data

First, we need to create a file from the data we have received...

Private Sub Create_The_File()
 Dim ofile As File
 Set ofile = CreateObject("FileCtl.File")
 Rbuff = Replace(Rbuff, "INFOOK", "")
 Rbuff = Replace(Rbuff, "~", "")
 Call ofile.Open(App.Path & "\pcinfo.xml", _
      fsModeOutput, _
      fsAccessWrite, _
      fsLockReadWrite)
 Call ofile.LinePrint(Rbuff)
 Call ofile.Close
End Sub

We replace the 'INFOOK' and '~' spaces with nothing, and hopefully we now have a valid XML file. We now load this into memory for formatting.

Private Sub Process_The_XML_File()
 Dim iFile As File
 Set iFile = CreateObject("FileCtl.File")
 Call iFile.Open(App.Path & "\pcinfo.xml", _
      fsModeInput, fsAccessRead, fsLockRead)
 Rbuff = iFile.Input(iFile.LOF)
 Call iFile.Close
 Set iFile = Nothing
 Set xmlDoc = CreateObject("Microsoft.XMLDOM")
 xmlDoc.async = False
 xmlDoc.LoadXML Rbuff

The XML should now be safely in memory, so we set about extracting it.

The data goes in the 3 text boxes, and the list view. As the text box processing is the same, we have written a generic routing to extract it and add it to the text boxes.

 Add_Item "PcInfo/UserName", txtUser

Public Sub Add_Item(ItemKey As String, _
           txtbox As TextBox)
 Dim XmlNodes
 Set XmlNodes = xmlDoc.getElementsByTagName _
     (ItemKey)
 Dim WkItem As String
 WkItem = XmlNodes.Item(0).Text
 Set XmlNodes = Nothing
 txtbox.Text = txtbox.Text & _
    SplitWords(ItemKey) & ": " & _
    WkItem & vbCrLf
End Sub

Previous Page  Next Page