Documentation/Samples Needed

Sep 8, 2010 at 7:25 PM

Are there any samples available showing how to use this library to connect to a device, copy files to it, delete files, etc?  I was able to download the project and compile it into a DLL but I really need some samples in VB.NET showing how to use this library...  Thank you in advance.

Sep 8, 2010 at 7:45 PM

I have posted samples in the past. Let me dig up a couple.

I use the following imports (not sure which ones you'll need)

Imports System.IO
Imports System.Environment
Imports OpenNETCF.Desktop.Communication
Imports System.Data
Imports System.Data.SqlClient
Imports System.Net

 

Here are the various subs that I use, let me know if I didn't include a function or sub

    Public Sub CopySDFfromIpaqToPC()
        UpDateCaption("Copying database from iPAQ")

        'Me.DeleteSDFonPC() 'Delete SDF located on the PC, if it already exists
        Me.ConnectToiPAQ()

        If Me.VerifyFileExistsOnIpaq() = True Then
            Try
                UpDateCaption("Copying SDF from iPAQ")
                myrapi.CopyFileFromDevice(MomsUpdPath & SDFfile, PathiPAQ)
                UpDateCaption("Finished copying SDF from iPAQ")
            Catch ex As Exception
                Throw New Exception("Error copying SDF from iPAQ: " & ex.Message)
            End Try
        Else
            Throw New Exception("SDFdoesntExistoniPAQ")
            'We need to change this to change a flag that iPAQ doesnt exist, indicating that this is a new/blank install
        End If

        Me.DisconnectFromIpaq()

    End Sub

    Public Sub DisconnectFromIpaq()
        myrapi.Disconnect()
        myrapi.Dispose()
    End Sub

 

    Public Sub ConnectToiPAQ()

        If myrapi.DevicePresent Then
            myrapi.Connect()
            'Me.Invoke(New MethodInvoker(ShowConnected))
        Else
            MessageBox.Show("Please connect your device to your PC using " & Me.SyncMethod() & " before clicking the OK button.", "iPAQ was not detected")
            If myrapi.DevicePresent Then
                myrapi.Connect()
                'Me.Invoke(New MethodInvoker(ShowConnected))
            Else
                MessageBox.Show("Please connect your device to your PC using " & Me.SyncMethod() & " before clicking the OK button. If you have just docked your unit, please wait for " & Me.SyncMethod() & " to start up and connect to your iPAQ before pressing OK", "iPAQ still has not been detected")
                If myrapi.DevicePresent Then
                    myrapi.Connect()
                    'Me.Invoke(New MethodInvoker(ShowConnected))
                Else
                    MessageBox.Show("Please verify " & Me.SyncMethod() & " is running and displays 'Connected' before clicking the OK button. If the iPAQ cannot be detected at this point, this application will shut down.", "iPAQ was not detected, last try.")
                    If myrapi.DevicePresent Then
                        myrapi.Connect()
                        'Me.Invoke(New MethodInvoker(ShowConnected))
                    Else
                        Throw New Exception("IpaqNotConnected")
                    End If
                End If
            End If
        End If
    End Sub

 

 

 

    Public Function VerifyFileExistsOnIpaq() As Boolean
        If myrapi.DeviceFileExists(PathiPAQ) = True Then 'If the SDF file exists, check further (conditions have been found where an empty field is left)
            If myrapi.GetDeviceFileSize(PathiPAQ) > 0 Then 'Make sure the file is bigger than 0kb, otherwise we will error out later on
                Return True 'If the device is >0kb, all should be good, return a 'True'
            Else
                If myrapi.DeviceFileExists(NewFileName) = True Then 'Check to make sure last sync didn't rollback correctly by checking for temp copy
                    If myrapi.GetDeviceFileSize(NewFileName) > 0 Then ' If the temp copy does exist, make sure it is larger than 0kb
                        myrapi.DeleteDeviceFile(PathiPAQ) 'Delete the 0kb file
                        myrapi.MoveDeviceFile(NewFileName, PathiPAQ) 'If it does exist and is >0kb, rename the temp file with the actual filename
                        Return True
                    Else
                        Return False
                    End If
                End If
            End If
        Else
            Return False
        End If
    End Function

 

 

    Public Sub CopySDFfromPCtoIpaq()
        'This sub replaces "DownloadTableToPPC" in version 1.7 and earlier
        UpDateCaption("Copying sdf back onto iPAQ")

        Me.ConnectToiPAQ()

        Try
            If Me.VerifyFileExistsOnIpaq() = True Then
                If myrapi.DeviceFileExists(NewFileName) = True Then myrapi.DeleteDeviceFile(NewFileName) 'If a file with the new name already exists on iPAQ, delete it
                myrapi.MoveDeviceFile(PathiPAQ, NewFileName) 'Move/rename original sdf incase we have to roll back
            End If
        Catch ex As Exception
            Throw New Exception("Error copying SDF to iPAQ: " & ex.Message)
        End Try

        myrapi.CopyFileToDevice(MomsUpdPath & SDFfile, PathiPAQ) 'Copy the local copy back onto the iPAQ
        If myrapi.DeviceFileExists(NewFileName) = True Then myrapi.DeleteDeviceFile(NewFileName) 'Delete the back up copy on the iPAQ
        Me.DisconnectFromIpaq()
    End Sub

Sep 8, 2010 at 7:51 PM

I guess I forgot these:

 

    Private Sub UpDateCaption(ByVal strCaption As String)
        lblStatus.Text = strCaption
        System.Windows.Forms.Application.DoEvents()
    End Sub

 

    Private Function SyncMethod() As String
        'Get Operating system information.
        Dim os As OperatingSystem = Environment.OSVersion
        'Get version information about the os.
        Dim vs As Version = os.Version
        'Variable to hold our return value
        Dim operatingSystem As String = ""
        Dim Program As String = ""
        If (os.Platform = PlatformID.Win32NT) Then
            Select Case (vs.Major)
                Case 5
                    Program = " Active Sync "
                Case 6
                    Program = " Windows Mobile Device Center "
                Case Else
                    Program = ""
            End Select
        Else
            Program = ""
        End If
        Return Program
    End Function

Sep 8, 2010 at 8:52 PM
Thank you so much.  I think the thing I might need first (and maybe all I need) is the declaration for myrapi.  I don't see that below, and am assuming it is type OpenNetCF Desktop Communication?  Please can you provide from your code the declaration for myrapi.

All I really need are the following abilities, which I think you might provide in your sample code already:

1) Connect to device / detect if connected
2) Determine if a file is on the device
3) Delete a file and copy a new file over, and create a directory if needed
4) Close connection

Thanks again,
Alan Glanz

On Wed, Sep 8, 2010 at 3:51 PM, DavyMac <notifications@codeplex.com> wrote:

From: DavyMac

I guess I forgot these:

 

    Private Sub UpDateCaption(ByVal strCaption As String)
        lblStatus.Text = strCaption
        System.Windows.Forms.Application.DoEvents()
    End Sub

 

    Private Function SyncMethod() As String
        'Get Operating system information.
        Dim os As OperatingSystem = Environment.OSVersion
        'Get version information about the os.
        Dim vs As Version = os.Version
        'Variable to hold our return value
        Dim operatingSystem As String = ""
        Dim Program As String = ""
        If (os.Platform = PlatformID.Win32NT) Then
            Select Case (vs.Major)
                Case 5
                    Program = " Active Sync "
                Case 6
                    Program = " Windows Mobile Device Center "
                Case Else
                    Program = ""
            End Select
        Else
            Program = ""
        End If
        Return Program
    End Function

Read the full discussion online.

To add a post to this discussion, reply to this email (rapi@discussions.codeplex.com)

To start a new discussion for this project, email rapi@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com


Sep 8, 2010 at 8:57 PM
Cancel my last message, I see now that myrapi is of type RAPI.  I hadn't included the correct import statements.

Thanks again,
Alan Glanz

On Wed, Sep 8, 2010 at 3:51 PM, DavyMac <notifications@codeplex.com> wrote:

From: DavyMac

I guess I forgot these:

 

    Private Sub UpDateCaption(ByVal strCaption As String)
        lblStatus.Text = strCaption
        System.Windows.Forms.Application.DoEvents()
    End Sub

 

    Private Function SyncMethod() As String
        'Get Operating system information.
        Dim os As OperatingSystem = Environment.OSVersion
        'Get version information about the os.
        Dim vs As Version = os.Version
        'Variable to hold our return value
        Dim operatingSystem As String = ""
        Dim Program As String = ""
        If (os.Platform = PlatformID.Win32NT) Then
            Select Case (vs.Major)
                Case 5
                    Program = " Active Sync "
                Case 6
                    Program = " Windows Mobile Device Center "
                Case Else
                    Program = ""
            End Select
        Else
            Program = ""
        End If
        Return Program
    End Function

Read the full discussion online.

To add a post to this discussion, reply to this email (rapi@discussions.codeplex.com)

To start a new discussion for this project, email rapi@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com


Sep 8, 2010 at 9:06 PM

I simply add the OpenNETCF.Desktop.Communication.dll to my project folder then make a reference to it from my solution explorer (right click reference then add reference)

 

The sub above named ConnectToiPAQ, will help you connect to your device.

The most basic part of the code is:

                    If myrapi.DevicePresent Then
                        myrapi.Connect()
                    Else
                        Throw New Exception("IpaqNotConnected")
                    End If

A lot of people use a "Do while" not connect and try to connect, but I noticed that it loops indefinitely under certain conditions so thats why I try the connection 3 times, prompting the user each time.

If you are connected (the device connection hasn't come loose, which does happen) then there is no issue, but if not, it will prompt them to check.

 

For your 2nd and 3rd issue, look at "CopySDFfromPCtoIpaq" in my first post above

 

For your 4th issue, look at Public Sub DisconnectFromIpaq() in my first post above.