USB debugging somewhat flaky



  • It seems like there is something somewhat flaky about the USB support. I'm on OSX and using minicom, and at some point after enough resets and/or 'make install' I can't use the USB port anymore. There's a device in /dev, but minicom says that the port is not configured. I have figured out the magic incantations to make it work again. I've unplugged the cable from both the Mac and Mono, I've reset Mono, I've reinstalled the prog, etc., but to no avail. And then suddenly it works again. Any tips?



  • @allan said in USB debugging somewhat flaky:

    Any tips?

    Yes, it is a bug introduced in OS X El Capitan :-(

    Every time mono is reset the serial port is mounted with a new name:

    /dev/cu.usbmodem14
    /dev/cu.usbmodem15
    /dev/cu.usbmodem16
    /dev/cu.usbmodem17
    /dev/cu.usbmodem18
    /dev/cu.usbmodem19
    

    etc.

    I have written a small node.js script that monitor /dev/cu.usbmodem* and create a symlink to the port with the highest number at the end. The symlink is called mono-serial and is created in the current working dir.

    You can then open the symlink i minicom

    Here it is: (serial_helper.js)

    var fs = require("fs");
    var currentSource = null;
    
    var updateFile = function(file)
    {
    	if (file != currentSource)
    	{
    		fs.unlink("./mono-serial", function(){
    			console.log("creating new symlink for: "+file);
    			currentSource = file;
    			fs.symlinkSync("/dev/"+file,"./mono-serial");
    		});
    	}
    }
    
    var scanDir = function(files)
    {
    	var newest = null;
    	var regex = /^cu\.usbmodem([0-9]+)$/;
    	for (var f in files)
    	{
    		// if (files[f] == "cu.mono-serial")
    		// 	continue;
    		
    		if (regex.test(files[f]))
    		{
    			//console.log("Found file: "+files[f])
    			var match = regex.exec(files[f]);
    			if (newest == null)
    			{
    				newest = Number(match[1]);
    				continue;
    			}
    			else if (Number(match[1]) > newest)
    			{
    				newest = Number(match[1])
    			}
    		}
    	}
    	
    	if (newest == null)
    		return null;
    	
    	//console.log("Newest is: cu.usbmodem"+newest);
    	
    	return "cu.usbmodem"+newest;
    }
    
    var checkFiles = function()
    {
    	
    	//console.log("Checking for new files...");
    	var nFile;
    	
    	fs.readdir("/dev",function(err, files){ 
    		nFile = scanDir(files);
    		if (nFile == null)
    			return;
    		
    		updateFile(nFile);
    	});
    }
    
    var timer = setInterval(checkFiles,100)
    console.log("begin");
    


  • Ah, I hadn't noticed that. The same thing can be achieved by

    minicom `ls -c -l -1 /dev/cu.usbmodem1* | head -1`
    

    I'm still not able to connect to Mono though. But it's a different error message now.



  • @allan said in USB debugging somewhat flaky:

    Ah, I hadn't noticed that. The same thing can be achieved by

    minicom `ls -c -l -1 /dev/cu.usbmodem1* | head -1`
    

    I'm still not able to connect to Mono though. But it's a different error message now.

    I do not think this would work. Since ls and head is only executed once. If/when the serial port changes later - you need to exit minicom and execute the command again.

    With the node script, you can keep minicom open, and the new serial port is automatically routed from the newest file to minicom.



  • @stoffera ah, that's 100% true that it only works once. I didn't think the relinking of the device would work while minicom was open, but that's great


Log in to reply