NAME

Device registy library. Maps hardware ports to Tcl channels.

SYNOPSIS

typedef struct PortState {   
    short inputRef;			// Macintosh file reference numbers. 
    short outputRef;		// Added because serial ports have both
    						// an input and output reference.
    int		blocking;		// Enable/Disable Serial Blocking
		    
    Tcl_Channel devChan;	/* Pointer to the channel for this device. */
    
    int watchMask;		/* OR'ed set of flags indicating which events
    				 * are being watched. */
    int validMask;		/* OR'ed set of flags indicating which events
    				 * are able to be watched. */
    int pending;		/* 1 if message is pending on queue. */
    
    ClientData	devID;			// Internal Hardware Reference Number
	struct PortClass *portClass;	/* Procedures */    
    struct PortState *nextPtr;	/* Pointer to next registered file. */
} PortState;

typedef struct PortDesc {
	char *name;			/* Human Readable Device Name */
	char *desc;			/* Human Readable Device Description */
	ClientData	devID;			/* Port reference ID */	
	struct PortClass *portClass;	/* Procedures */
	struct PortDesc *nextPtr;
} PortDesc;

typedef struct PortClass {
	char *name;						/* Human Readable Class Name */
	Tcl_OpenDeviceProc	*openProc;	/* Function to open device */
	Tcl_CloseDeviceProc	*closeProc; /* Function to force closed device */
    Tcl_CheckDeviceProc	*readyProc; /* Function to check device for events */
} PortClass;

typedef struct PortEvent {
    Tcl_Event header;		/* Information that is standard for
				 * all events. */
    PortState *infoPtr;		/* Pointer to file info structure.  Note
				 * that we still have to verify that the
				 * file exists before dereferencing this
				 * pointer. */
} PortEvent;		

typedef Tcl_Channel
Tcl_OpenDeviceProc interp devID errorCodePtr

typedef void
Tcl_CloseDeviceProc devID

typedef int
Tcl_CheckDeviceProc portState

int
Device_Init interp
Inserts the device command into interp, and initialized the port table.

int
Device_SafeInit interp
Does Nothing

int
Tcl_DeviceObjCmd dummy interp objc objv
Impliments the device command

Tcl_Channel
Tcl_OpenDeviceChannel interp devName
Open an hardware based channel. Returns the new channel or NULL. If NULL, Tcl_SetErrno is called with the error.

int
Tcl_ResetDeviceChannel interp devName
Forces closed a hardware port. Returns TCL_OK on success or TCL_ERROR on failure.

int
Tcl_AddDeviceName interp devName devID devClass
Registers a new device name of an existing class

DESCRIPTION

These procedures are used to open channels to hardware devices. Once open channels are manipulated using the tcl commands puts, gets, close, read, fconfigure, fileevent, etc.

DEVICES

Devices can be registered with the Tcl_AddDeviceName function. Devices are grouped be a common class, which contains the code used by TCL to map the port to the channel. Developers adding new classes should adhere to the conventions listed in the table below for known device classes. This allows some consitency between platforms.

ClassDesc
serialRS-232 or RS-422 Serial ports
parallelCentronics(tm) style parallel ports
usbUniversal Serial Bus
adbApple Desktop Bus
scsiSmall Computer Simple Interface
ps2IBM PS/2 Style interface ports

New devices classes should have their own initialization function, which inserts supported device names into the device table. This is the only function that needs to be called from outside. All other methods are listed here. For a fully working example, refer to the odieMacSerialDevice.c

A template of a new device is provided in odieGenericDevice.c


For information regarding the TCL interface, refer to the Device Command document
Copyright © 1999 Woods Design Services.
Copyright © 1999 Sean Woods.