Serial and parallel port mapping


This is one of my favorite scripts.  It automatically detects any serial or parallel ports that you may have connected to your Sun Ray and creates a symlink(s) in your home directory for easy mapping.  These may be USB to Serial/Parallel adaptors, or in the case of the Sun Ray 170, the two built in serial ports.  Upon hot desking utaction invokes the script checks to see if the new Sun Ray has these ports then updates the symlinked entries. 

Why is this important? 

First of all these type of devices are tied to the physical Sun Ray device, it requires a fairly complex path to be entered into certain programs that you would want use these ports.  Wouldn't you agree that $HOME/utports/com1 is a lot easier to enter than /tmp/SUNWut/units/IEEE802.080020cf428a/dev/term/Digi-67a? 

Second, when you hot desk you want to make sure that these devices pointing to the correct device since the path will have changed due the MAC address of the new DTU or even a different type of port adaptor.

This script will work with both normal sessions and CAM sessions.  It makes it very easy to do things like serial port mapping using programs like rdesktop or Citrix since you only have to make one global setting for all users of something like $HOME/utports/com1 vs trying to figure out the path to the device for every single Sun Ray that may or may not have an adaptor.  The script also keeps track of physical to symlinked port names in $HOME/portmap.txt and if no devices are found, states so in this file as well.

Like other scripts that I do for Sun Ray Server this will be done in two parts.  The first script sets up utaction to call the second script which does all the real work.

You can download the sample scripts here


The first script can be called as a default CAM application, or could be called as a numbered startup file in /usr/dt/config/Xsession.d.  For CAM, I prefer to have it called by my main CAM application.

#!/bin/sh
BASEDIR=/opt/UTPorts

# UTACTIONS for COM and LPT port mapping
/opt/SUNWut/lib/utaction -i -c $BASEDIR/utports &


The second file should be stored in /opt/UTPorts and can be called utports.  Wherever you store it and whatever you call it, just make sure it's reflected in the first script.

#!/bin/sh
#
# utports - Written by Craig Bender, Sun Ray Engineering
#
# --Begin Script--
#
#set -x
# Make sure we are on a Sun Ray
#
if [ ! "$UTDEVROOT" ];then
echo "Not on a Sun Ray. Exiting.\\n"
exit
else

# Check to See if a ports directory exists. If it does, remove all com\* and lp\* entries,
# otherwise create the directory. Removal is done for HotDesking.
#
#
# Check to see what Com ports exist
if [ -d $UTDEVROOT/dev/term/ ];then
COMPORTS=`ls $UTDEVROOT/dev/term/`
fi
#
# Check to see what printer ports exist
if [ -d $UTDEVROOT/dev/printers/ ];then
LPPORTS=`ls $UTDEVROOT/dev/printers/`
fi

if [ ! "$COMPORTS" ] && [ ! "$LPPORTS" ];then
echo "No serial or parallel ports found connected to this Sun Ray" > $HOME/porterr.txt
exit 1
fi
#
# Set the port directory to store symbolic links
PORTDIR=$HOME/utports

if [ -d $HOME/utports ]; then
rm $PORTDIR/com\* > /dev/null 2>&1
rm $PORTDIR/lp\* > /dev/null 2>&1
else
mkdir $PORTDIR
fi

# Delete porterr.txt if we have gotten this far
rm $HOME/porterr.txt

# Create/Refresh $HOME/portmap.txt

if [ -f $HOME/portmap.txt ];then
rm $HOME/portmap.txt
else
touch $HOME/portmap.txt
fi

# Enumerate serial ports as com1-comx

comport=1
if [ ! "$COMPORTS" ];then
echo "No serial ports found connect to this Sun Ray" >> $HOME/portmap.txt
else
for comportname in $COMPORTS; do
ln -s $UTDEVROOT/dev/term/$comportname $PORTDIR/com$comport
echo "$UTDEVROOT/dev/term/$comportname = com$comport" >> $HOME/portmap.txt
comport=`expr $comport + 1`
done
fi

# Enumerate parallel ports as lp1-lpx

lpport=1
if [ ! "$LPPORTS" ];then
echo "No parallel ports found connect to this Sun Ray" >> $HOME/portmap.txt
else
for lpportname in $LPPORTS; do
ln -s $UTDEVROOT/dev/printers/$lpportname $PORTDIR/lp$lpport
echo "$UTDEVROOT/dev/printers/$lpportname = lp$lpport" >> $HOME/portmap.txt
lpport=`expr $lpport + 1`
done
fi
#
# close out the if statement for the Sun Ray check
fi
#
# --End script--


Let me know how this works for you. Have fun!
Comments:

It might help to avoid a disconcerting "file not found" error message when testing this for the first time on the command line to add a little checking around the line the deletes the porterr.txt, like: if [ -f $HOME/porterr.txt ]; then rm $HOME/porterr.txt fi

Posted by DougB on March 07, 2006 at 03:27 AM PST #

Hi, really nice scripts. However, I'm not quite there yet.
I try to make a HP LaserJet 1018 on USB work w m connector on a SR2. I got the utports alright (I guess) and the wrapper connects to windows and everything looks nice, no error messages, but no printout!

Here's the startline:
/opt/SUNWuttsc/bin/uttsc -A 24 -C -u lbennrup -p -r printer:"HP LaserJet 1018"=$HOME/utports/lp1 192.168.1.102

Here's the lp1:
lrwxrwxrwx 1 lars other 63 okt 21 23:49 lp1 -> /tmp/SUNWut/sessions/2/unit/dev/printers/Hewlett-PackardKP27XHC

Any hint's?
Best regards
Lars

Posted by Lars Bennrup on October 21, 2008 at 08:15 AM PDT #

Post a Comment:
Comments are closed for this entry.
About

Think Thin is a collection of bloggers that work with Oracle's Virtual Desktop portfolio of products.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today