[futurebasic] Re: [FB] keyspan

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : June 2004 : Group Archive : Group : All Groups

From: Walter Lenk <Walter_Lenk@...>
Date: Fri, 4 Jun 2004 13:26:46 -0400
Dealing with USB implemented serial ports can be a bit confusing, as 
the port's name contains it's place in the USB 'tree' as well as the 
device's name (and this name is different in OSX and OS9). The order 
of the port list can also vary (at least in OS9, I haven't checked in 
OSX) depending on whether a device is present at system boot or is 
added later.  There is an 'Open C'  demo application at 
<http://www.stazsoftware.com/fb_pak/more.html> that addresses some of 
these issues - this demo translates the serial port's full name into 
a standardized human readable name, and then builds a menu from these 
names. If you desire a port to be opened automatically at program 
start, there are 2 methods that I am familiar with:

1. Store the port's full name in a preferences file, and then use 
this name to open the port on startup. This approach has 2 drawbacks: 
1) It requires that the user identifies the port the 1st time the 
program is run, and 2) if the USB tree is changed the port's real 
name no longer matches. Virtual PC seems to use this approach, and it 
can get confused at times.

2. Translate the ports name to standardized human readable name (as 
in the example), and then use these 2 functions to open the port you 
want (in whatever pecking order) at program start -

LOCAL:DIM port%, p%
LOCAL FN Find_Port%(Name$)  ' Find the port with this name -> if it is there
   LET port% = 0
   FOR p% = 1 to gFBSerialPortCount%   ' search all the available ports
     IF Name$==gSerialName$(p%) THEN LET port% = p%: EXIT FOR ' a match found
   NEXT p%
END FN = port%

LOCAL:DIM TargetPort%
LOCAL FN Init_Serial_Port
   FN FBInitSerialPorts  '  Get the basic information
   FN Set_Port_Names     ' Into gSerialName$(P%), in Standard format.
   LET TargetPort% = 0
   IF TargetPort%==0 THEN LET TargetPort% = FN Find_Port%("Keyspan USA28X Port")
   IF TargetPort%==0 THEN LET TargetPort% = FN Find_Port%("Keyspan USA19W Port")
   IF TargetPort% THEN FN Open_Comm_Port(TargetPort%)
END FN

This 2nd approach has worked well for me, but it cannot distinguish 
between multiples of the same type of USB adapter.

Hope this helps,

Walter
-- 
===========================================
Walter Lenk    Cambridge Ma    617-547-7781
===========================================