Disable stdin/out/err on /dev/ttyS0 and use it in custom application

We need to connect the first serial port of a Digi Connect ME 9210 to an external device.

What is the correct way to do this:

  1. let the uboot + linux start using /dev/ttyS0 as default console
  2. free the /dev/ttyS0 (and redirect stdin/stdout/stderr to /dev/null)
  3. … here we can start our application that will open and lock the /dev/ttyS0 and use it to communicate with the external device. At the end it will close the serial port.
  4. re-enable stdin/stdout/stderr to /dev/ttyS0

NOTE: if possible, step 2 and 4 should be performed by a simple busybox script

Thank you in advance,