ftp.nice.ch/pub/next/system/driver/ieee488/KPC488Driver.1.2.tar.gz#/KPC488Driver1.2/KPC488Inspector.m

This is KPC488Inspector.m in view mode; [Download] [Up]

/*
 * KPC488 Inspector implementation
 * Copyright (C) 1994  W. Eric Norum
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 * 
 * W. Eric Norum
 * Saskatchewan Accelerator Laboratory
 * University of Saskatchewan
 * 107 North Road
 * Saskatoon, Saskatchewan, CANADA
 * S7N 5C6
 * 
 * eric@skatter.usask.ca
 */

#import "KPC488Inspector.h"

#define DRIVERNAME_KEY	"Driver Name"
#define CONTROLLER_KEY	"Controller GPIB Address"
#define TIMEOUT_KEY		"Time Limit"
#define DMACHECK_KEY	"DMA Check Interval"

@implementation KPC488Inspector

- init
{
	char      buffer[MAXPATHLEN];
	NXBundle *myBundle = [NXBundle bundleForClass:[self class]];

	[super init];
	if (![myBundle getPath:buffer forResource:"KPC488" ofType:"nib"]) {
		[self free];
		return nil;
	}
	if (![NXApp loadNibFile:buffer owner:self withNames:NO]) {
		[self free];
		return nil;
	}
	return self;
}

- (BOOL)getDriverIntValue:(unsigned int *)value withKey:(const char *)key
{
	IOReturn r;
	unsigned int count;
	unsigned int i;

	count = 1;
	r = [deviceMaster getIntValues:&i
								forParameter:(char *)key
								objectNumber:deviceObjectNumber
								count:&count];
	if ((r != IO_R_SUCCESS) || (count != 1))
		return NO;
	*value = i;
	return YES;
}

- (BOOL)loadParametersFromDriver
{
	if (![self getDriverIntValue:&gpibController withKey:CONTROLLER_KEY])
		return NO;
	if (![self getDriverIntValue:&dmaCheckInterval withKey:DMACHECK_KEY])
		return NO;
	if (![self getDriverIntValue:&timeLimit withKey:TIMEOUT_KEY])
		return NO;
	return YES;
}

- (BOOL)getTableIntValue:(unsigned int *)value withKey:(const char *)key
{
	const char *cp;
	unsigned int i;

	cp = [table valueForStringKey:key];
	if ((cp == NULL) || (sscanf (cp, "%u", &i) != 1))
		return NO;
	*value = i;
	return YES;
}

- (BOOL)loadParametersFromTable
{
	if (![self getTableIntValue:&gpibController withKey:CONTROLLER_KEY])
		return NO;
	if (![self getTableIntValue:&dmaCheckInterval withKey:DMACHECK_KEY])
		return NO;
	if (![self getTableIntValue:&timeLimit withKey:TIMEOUT_KEY])
		return NO;
	return YES;
}

- (void)loadDefaultParameters
{
	gpibController = [[gpibControllerSelector selectedCell] tag];
	dmaCheckInterval = [dmaCheckIntervalSelector tag];
	timeLimit = [timeLimitSelector tag];
}

- (void)setButton:button to:(int)tag
{
	id items = [[button target] itemList];
	[items selectCellWithTag:tag];
	[button setTitle:[[items selectedCell] title]];
}

- (void)updateKPC488View
{
	[gpibControllerSelector selectCellWithTag:gpibController];
	[self setButton:dmaCheckIntervalSelector to:dmaCheckInterval];
	[self setButton:timeLimitSelector to:timeLimit];
}

- setTable:(NXStringTable *)anObject
{
	const char *name;
	IOReturn r;
	IOString kind;

	[super setTable:anObject];

	/*
	 * Try to connect to driver
	 */
	name = [table valueForStringKey:DRIVERNAME_KEY];
	if (name != NULL) {
		deviceMaster = [IODeviceMaster new];
		r = [deviceMaster lookUpByDeviceName:(char *)name
								objectNumber:&deviceObjectNumber
								deviceKind:&kind];
		if (r != IO_R_SUCCESS)
			deviceMaster = nil;
	}

	/*
	 * Load the values
	 */
	if ((deviceMaster == nil) || ![self loadParametersFromDriver])
		if (![self loadParametersFromTable])
			[self loadDefaultParameters];
	[self updateKPC488View];

	[self setAccessoryView:kpc488View];
	return self;
}

- (void)setDriverIntValue:(unsigned int)value forKey:(char *)key
{
	if (deviceMaster)
		[deviceMaster setIntValues:&value
								forParameter:key
								objectNumber:deviceObjectNumber
								count:1];
}

- gpibControllerChanged:sender
{
	unsigned int i = [[sender selectedCell] tag];

	sprintf (gpibControllerString, "%d", i);
	[table insertKey:CONTROLLER_KEY value:gpibControllerString];
	return self;
}

- dmaCheckIntervalChanged:sender
{
	unsigned int i = [[sender selectedCell] tag];

	sprintf (dmaCheckIntervalString, "%d", i);
	[table insertKey:DMACHECK_KEY value:dmaCheckIntervalString];
	[self setDriverIntValue:i forKey:DMACHECK_KEY];
	return self;
}

- timeLimitChanged:sender
{
	unsigned int i = [[sender selectedCell] tag];

	sprintf (timeLimitString, "%d", i);
	[table insertKey:TIMEOUT_KEY value:timeLimitString];
	[self setDriverIntValue:i forKey:TIMEOUT_KEY];
	return self;
}

@end

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.