How can I get USB friendly name in runtime

How can I get USB friendly name in runtime

Can I ask, why ? What reason do you want that within the device ?

we are developing a series of custom boards in which we will use G120 module. Our code will have slight differences on different hardware versions of these boards. We need to use “friendly name” option to capture the hardware version, while powering up.

The way we did this in the past was through connecting specific pins high or low.

use specific pins high or low is not posible at this stage. we need a soft detection method.

Add this to the task tracker if you like.

But here’s the thing. The END USER can overwrite the friendly name ! Do you really want to try to depend on something the customer can change ?

I’d go with a pin or two. Find a way to make it happen. (especially since there is no way in the firmware today to achieve anything like you have - but since you’re talking what appears to be “commercial” you might want to reach out to GHI and approach them to develop custom firmware for you that is specific to each variant and can therefore use the netmf internal product naming pieces… might be more cost but will potentially be more controllable… or just find a couple of pins :slight_smile: )


It would be nice to have a clean and standard way for this. So I just added an issue at Microsoft’s site:

Not sure if EWR is another way instead of friendly name

Accessing the friendly name is a great idea. This could also be a way to store a unique serial number for a device. While a user might be able to alter it, it would take some work on their part, and its a risk I could tolerate.
From programming PICs for many years, I miss a simple way to store non-volatile configuration settings in NETMF. Friendly name might provide such a way, although that is not the intention.

1 Like

@ all - In the 2015 R1 Pre-Release 2 SDK, we have added a way to get and set individual config entries. In 4.3 QFE2 today, USB friendly name can be accessed through the config entry “USB_NAME_CONFIG”. By default, it is not set, so it will be null if you try to read. Once you set it though, it will persist until you reflash the config. The below code shows how to do this. Make sure that the array you write to config is always 32 bytes, it won’t work otherwise.

using GHI.Processor;
using Microsoft.SPOT;
using System;
using System.Text;

public class Program {
	public static void Main() {
		var entry = Configuration.ReadEntry("USB_NAME_CONFIG");
		var newEntry = new byte[32];

		if (entry != null)
			Debug.Print(new string(Encoding.UTF8.GetChars(entry)));

		Array.Copy(Encoding.UTF8.GetBytes("test"), newEntry, 32);

		Configuration.WriteEntry("USB_NAME_CONFIG", newEntry);

While you can use this to identify a board or hardware revision, as hytgny was trying to do, it can be used to read and write any custom config entry. Just make sure the name you use is unique. Subsequent writes to an entry with the same name will overwrite the previous value, even if the size is different.

There is no way to know ahead of time how much space will be available though. Different devices have different config sizes and the information in the config varies. WriteEntry returns a bool if it was able to successfully write to the config.