Sample drivers – Sensory Science 7405 User Manual

Page 6

Advertising
background image

Sensoray Model 7405 Instruction Manual — Page 6

Sample Drivers

These sample driver functions, written in C/C++, assume that all channels are configured for the voltage output mode. With
minor modification, these drivers can be made to work with channels that are set up for current output mode operation.

#define BUSY 0xC0

// Handshake status bit mask

typedef unsigned char UCHAR;

UCHAR InByte( UCHAR address )

{

// INSERT CODE HERE THAT WILL RETURN A VALUE FROM AN 8-BIT I/O PORT

}

void OutByte( UCHAR address, UCHAR value )

{

// INSERT CODE HERE THAT WILL WRITE A VALUE TO AN 8-BIT I/O PORT

}

void WriteVoltage( UCHAR baseport, UCHAR channel, double volts )

{

// Limit voltage to legal values.

double voltage = (volts > 9.995) ? 9.995 : ( (volts < -10.0) ? -10.0 : volts );

// Convert voltage value to binary value suitable for DAC.

short value = (short)( 2048 + voltage * 204.8 );

// Wait until Model 7405 board is ready to accept data.

do {} while ( InByte(baseport) & BUSY );

// Write binary value to Model 7405 board.

OutByte( baseport, value & 0xFF );

OutByte( baseport + 1, ((channel << 4) & 0x70) | ((value >> 8) & 0x0F) );

}

Advertising