Serial deploy to G80 with FEZ Config or MFDeploy

There are no current known issues around MFDeploy or serial debug. Testing a G80 here in serial mode, over a virtual com port, with MFDeploy works fine on 64 bit Windows 10.

Both FEZ Config and MFDeploy use the same backing API, Microsoft.NetMicroFramework.Tools.MFDeployTool.Engine.

Out of curiosity what were you using to monitor opening serial port connections?
SysInternals tool?

Yes its for the new TinyCLR platform/firmware.
Sorry, when I read one of your questions quickly, I thought I saw TinyCLR mentioned, so assumed you were using that.
But I do think GHI also names their version of MS MircoFramework tinyclr when connecting or pinging devices also, which can be a bit confusing.

From your device dump above, looks like your def. running NET MF, so as john said TinyCLR Config can’t be used for that, but interesting to hear resuslts.

IRP_MJ_CREATE
STATUS_ACCESS_DENIED
Can also be caused by "The device is already open."
Is there something running on your system that grabs comm ports (have you closed down all other comms software?)
Not for above reasons, but ever tried running FEZ Config in elevated Admin at some point?

Serial Port Monitor by Eltima Software.

Portmon in the Sysinternals Suite doesn’t work on 64-bit machines.

Yes, from Microsoft’s Hardware Dev Center (IRP_MJ_CREATE (Serial) (Windows Drivers) | Microsoft Learn), this status means:

STATUS_ACCESS_DENIED
The device is already open.

The odd thing is that it seems like MFDeploy is conflicting with itself. Here is a test where I did the following:

  1. Opened COM7 (the serial deploy/debug port) in Tera Term - Success
  2. Close COM7 in Tera Term
  3. Open COM7 in MFDeploy - Failure
  4. Exit MFDeploy
  5. Open COM7 in Tera Term again - Success again
COM7;COM8;COM9
#TimeFunctionDirectionStatusDataData (chars)Data lengthReq. lengthPort
Step #1Open COM7 in Tera TermThis WORKS
37216:15:13:193IRP_MJ_CREATEDOWNSTATUS_SUCCESSC:\Program Files (x86)\teraterm\ttermpro.exeCOM7
37316:15:13:208IRP_MJ_CREATEUPSTATUS_SUCCESSC:\Program Files (x86)\teraterm\ttermpro.exeCOM7
37416:15:13:208IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_GET_COMMSTATUS)DOWNSTATUS_SUCCESSCOM7
.
.More IRP_MJ_DEVICE_CONTROL stuff that succeeds
.
Step #2Close COM7 in Tera Term
41416:15:23:278IRP_MJ_CLOSEDOWNSTATUS_SUCCESSCOM7
41516:15:23:383IRP_MJ_CLOSEUPSTATUS_SUCCESSCOM7
Step #3Open COM7 in MFDeployThis FAILS
41616:15:27:611IRP_MJ_CREATEDOWNSTATUS_SUCCESSC:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Tools\MFDeploy.exeCOM7
41716:15:27:611IRP_MJ_CREATEUPSTATUS_ACCESS_DENIEDC:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Tools\MFDeploy.exeCOM7
41816:15:27:811IRP_MJ_CREATEDOWNSTATUS_SUCCESSC:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Tools\MFDeploy.exeCOM7
41916:15:27:811IRP_MJ_CREATEUPSTATUS_ACCESS_DENIEDC:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Tools\MFDeploy.exeCOM7
42016:15:28:012IRP_MJ_CREATEDOWNSTATUS_SUCCESSC:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Tools\MFDeploy.exeCOM7
42116:15:28:012IRP_MJ_CREATEUPSTATUS_ACCESS_DENIEDC:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Tools\MFDeploy.exeCOM7
42216:15:28:213IRP_MJ_CREATEDOWNSTATUS_SUCCESSC:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Tools\MFDeploy.exeCOM7
42316:15:28:213IRP_MJ_CREATEUPSTATUS_ACCESS_DENIEDC:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Tools\MFDeploy.exeCOM7
42416:15:28:414IRP_MJ_CREATEDOWNSTATUS_SUCCESSC:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Tools\MFDeploy.exeCOM7
42516:15:28:414IRP_MJ_CREATEUPSTATUS_ACCESS_DENIEDC:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Tools\MFDeploy.exeCOM7
42616:15:28:615IRP_MJ_CREATEDOWNSTATUS_SUCCESSC:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Tools\MFDeploy.exeCOM7
42716:15:28:615IRP_MJ_CREATEUPSTATUS_ACCESS_DENIEDC:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Tools\MFDeploy.exeCOM7
Step #4Close MFDeploy
Step #5Open COM7 in Tera TermThis WORKS AGAIN
42816:15:36:751IRP_MJ_CREATEDOWNSTATUS_SUCCESSC:\Program Files (x86)\teraterm\ttermpro.exeCOM7
42916:15:36:754IRP_MJ_CREATEUPSTATUS_SUCCESSC:\Program Files (x86)\teraterm\ttermpro.exeCOM7
43016:15:36:754IRP_MJ_DEVICE_CONTROL (IOCTL_SERIAL_GET_COMMSTATUS)DOWNSTATUS_SUCCESSCOM7
.
.More IRP_MJ_DEVICE_CONTROL stuff that succeeds
.

I believe I have figured it out. I got the source code for MFDeploy from the Micro Framework Porting Kit and ran it in the debugger in Visual Studio.

It first enumerates through a list of my USB devices and opens handles to them. These are the “\Device\USBPDO-xx” handles. One of these devices is my USB-Serial Module, as the “file” variable on line 527 of “Streams.cs” where it calls “Native.CreateFile” is “\?\usb#vid_0403&pid_6001…”, which matches the hardware IDs for the GHI USB-Serial Module in Device Manager.

Apparently, once it opens a handle to the USB Serial Converter as a USB device, when “Native.CreateFile” is called with the serial port’s path “\\.\COM7” its access is denied, and it returns an invalid handle and throws an InvalidOperationException. This is where MFDeploy says there was no response from the device.

So I made the change below to Streams.cs in the Microsoft.SPOT.Debugger namespace, which prevents it from opening the handle to the USB Serial Converter as a USB device. Now when I try to connect to COM7, I no longer get “ACCESS_DENIED”.:grinning:

Was:

    static private SafeFileHandle OpenHandle( string file, System.IO.FileShare share )
    {
        if(file == null || file.Length == 0)
        {
            throw new ArgumentNullException( "file" );
        }

        SafeFileHandle handle = Native.CreateFile(file, Native.GENERIC_READ | Native.GENERIC_WRITE, share, Native.NULL, System.IO.FileMode.Open, Native.FILE_FLAG_OVERLAPPED, Native.NULL);
        
        if(handle.IsInvalid)
        {
            throw new InvalidOperationException( String.Format( "Cannot open {0}", file ) );
        }

        return handle;
    }

Changed to:

    static private SafeFileHandle OpenHandle(string file, System.IO.FileShare share)
    {
        if (file == null || file.Length == 0)
        {
            throw new ArgumentNullException("file");
        }

        if (!file.Equals(@"\\?\usb#vid_0403&pid_6001#a60395nh#{a5dcbf10-6530-11d2-901f-00c04fb951ed}"))
        {
            SafeFileHandle handle = Native.CreateFile(file, Native.GENERIC_READ | Native.GENERIC_WRITE, share, Native.NULL, System.IO.FileMode.Open, Native.FILE_FLAG_OVERLAPPED, Native.NULL);

            if (handle.IsInvalid)
            {
                throw new InvalidOperationException(String.Format("Cannot open {0}", file));
            }

            return handle;
        }
        else
        {
            throw new InvalidOperationException(String.Format("Cannot open {0}", file));
        }
    }
2 Likes