Force device into download mode...

Posted on 2008-11-19
Last Modified: 2013-11-26
I've been battling this for a few days now and I stumbled upon this post that is very similar to what I'm trying to accomplish.  It uses the exact output also, the xdld command to put the device in download mode.  I don't need this process automated however, and I don't want it to do it on startup.  I just cant seem to get the code right for opening com1 and sending it the right xdld command.  I'm using visual basic 2003 and I know it should be just a few lines, but I'm a novice in this area.  Any help in this area is much appreciated, again... all I need to do is open com1, utilize the XDLD command and then I have a separate batch file that will download the file once it is in that mode.  Thanks for any help!
Question by:jasgiv1122
    LVL 16

    Expert Comment

    Hi, unfortunatelly, i have no clue regarding
    You see, i am in the Old and Good School of VB6.
    LVL 2

    Author Comment

    Was the post I referenced in vb6?  I may have misjudged what language it was - Any help is appreciated... Does anyone know if it's possible to do it in .Net?
    LVL 38

    Expert Comment


    If you post the code that you have tried, it might help us help you.
    LVL 2

    Author Comment

    This is what I used, but I get an application error when I run it.
    Module Module1
        Sub Main()
            'New a MSComm control
            Dim MSComm1 As MSComm
            MSComm1 = New MSComm
            ' Buffer to hold input string.
            Dim Buffer As String
            ' Use the COM1 serial port.
            MSComm1.CommPort = 1
            ' 9600 baud, no parity, 8 data, and 1 stop bit.
            MSComm1.Settings = "9600,N,8,1"
            ' Tell the control to read the whole buffer when Input is used.
            MSComm1.InputLen = 0
            ' Open the serial port.
            MSComm1.PortOpen = True
            Console.WriteLine("Open the serial port.")
            ' Tell the control to make the Input property return text data.
            MSComm1.InputMode() = InputModeConstants.comInputModeText
            'Clear the receive buffer.
            MSComm1.InBufferCount() = 0
            ' Send the attention command to the modem.
            MSComm1.Output = "xdld"
                Buffer = Buffer & MSComm1.Input
            Loop Until InStr(Buffer, "OK" & vbCrLf)
        End Sub
    End Module

    Open in new window

    LVL 38

    Expert Comment

    Well, that looks a lot like VB6 code.  If you're getting an application error it's probably because the MSCOMM32.OCX is not available for use like this.

    Try a .NET solution for comm communications:

    That sample project should allow you to experiement sending the right download code to your device.
    LVL 2

    Author Comment

    Thanks for that valuable piece of information! The next wall I've run in to, is that I'm trying to call a batch file after the port is open and the command has been sent - this has to be within the same application, right?  When I just run the batch file by itself after trying to send the command, it seems to just think the port is closed or in use.  
    LVL 38

    Expert Comment

    I was wondering about that... Unless you close the port from the application, your batch file won't work.  I'm guessing the batch file does a redirect of a file to COM1: or something similar.
    LVL 38

    Expert Comment

    To clarify, you need to try opening the port, sending the command and closing the port, then running the batch file.
    LVL 2

    Author Comment

    Ok, after weeks of waiting for a response from the manufacturer, I have it.  I have the command I'm supposed to use, but I'm stuck on getting anything to communicate to it.

    REQ: <STX>XDLD<FS>FileName<FS>DownloadType<FS>[ForceRestart]<ETX>{LRC}
    RSP: <STX>XDLD<FS>RetVal<FS>RetValString<ETX>{LRC}
    FileName = name of file to be downloaded
    DownloadType =
    'P' = PARTIAL download (contents of file system are NOT erased)
    'F' = FULL download (contents of file system are erased)
    ForceRestart = 1 = Force restart the application
    2 = Force restart the Device
    RetVal = 0 - Unsuccessful operation
    1 - Successful operation
    RetValString - contains a text description of the result.

    Is there anyway you can guide me through setting this up in Visual Studio 2003?  I tried inputting this into apps, but it doesn't communicate.

    Hopefully you can offer any kind of solution!  Thanks

    It would be better if I could just have this all happen in a console application and open my port, then send the command, then possibly prompt the batch file I have that sends the file...  I've invested hours upon hours with trial and error, and nothing to show for it :/
    LVL 2

    Accepted Solution

    any help is appreciated!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now