Arduino + Java = error “Serial Port Already in Use”

If you try to run the Arduino IDE and the RXTX Java library on MacOS Lion and you are hitting a “Serial Port Already in Use” error,  try:

$ sudo mkdir /var/lock
$ sudo chmod 777 /var/lock

That should hopefully allow you to run them both (though only one at a time!)

If you want  interface your Arduino with the Java, see the Arduino documentation.

Marking files as binary in CVS

When multiple people are working with CVS, what can sometimes happen when you do a “cvs update” is that binary files get “merged” as if they were text files. Naturally, this can cause some file types to become corrupt.

To avoid this happening, type:

$ cvs admin -kb path/to/binary.file

Usually, you have a large number of these files (in my case, I had about ~1000 zip files). So combining the above with Bash’s find can be very useful. Assuming you are in the working directory:

$ find . -name "*.ext" -exec cvs admin -kb {} ;

The “{}” substitutes the found file, which CVS marks as binary for you.

There is also a handy guide on working with binary files in CVS.

Finding the value of “xml:lang” of an element

XML Spec says that when someone declares xml:lang somewhere in the ancestor chain of an XML document, element nodes in the DOM are supposed to inherit the value of xml:lang. However, although xml:lang is an inherent part of XML, the DOM Core level 3 specs lacks means to easily find what value of xml:lang an element has inherited (or explicitly has been assigned).

From section 2.12 Language Identification of the XML spec :

The language specified by xml:lang applies to the element where it is specified (including the values of its attributes), and to all elements in its content unless overridden with another instance of xml:lang. In particular, the empty value of xml:lang is used on an element B to override a specification of xml:lang on an enclosing element A, without specifying another language. Within B, it is considered that there is no language information available, just as if xml:lang had not been specified on B or any of its ancestors. Applications determine which of an element’s attribute values and which parts of its character content, if any, are treated as language-dependent values described by xml:lang.

Below is a little useful code snippet to help you find the value of xml:lang. The code simply recurses up the tree till it finds an xml:lang attribute to inherit the value from. If it can’t find one, it just returns an empty string:

function xmlLang(element){
  var xmlns = "";
  var value = element.getAttributeNS(xmlns,"lang");
  //check if we are at the root 
  if(element === element.ownerDocument.documentElement){ 
      //no xml:lang? 
          return ""; 
       //we have it, so return it. 
       return value; 
   //this is an element in the tree 
       //no xml:lang? recurse upwards 
	    return xmlLang(element.parentNode); 
  //we have a value, so return it
   return value;

To make it more useful, it would be good to validate the value derived from the code above against the IANA language tag registry.