********************************************************************************************************
This is an extract from 'USB_Interface.c' from the 'Altera' directory.  Refer to that file for the latest and greatest.

/* USB Interface.
OVERVIEW:  This combined project (N-PULSE SELECTOR & PIEZO DRIVER) uses the same firmware.  This
	source file applies to both project, but the Piezo project ignores the Threshold DAC.
INS:	16-bit USB
		 1-bit Clock (6.25MHz)
		 1-bit Por (1 = Power On Reset)
		 1-bit Trigger (same as PD/Trigger input, to reset sleep timer)
		 1-bit Variant (1 = Piezo Driver, 0 = n-Pulse Selector)
OUTS:	12-bit n-Pulse:  HV DAC data (0x000 = 0V, 0xFFF = +4.0388KV)
		       Piezo:    Fine DAC data (0x000 = 0V, 0xFFF = +10.053V) 
		12-bit n-Pulse:  +160V supply DAC data (0x000 = +161.19V, 0xFFF = +2.53V)
		       Piezo:    Coarse DAC data (0x000 = +161.19V, 0xFFF = +2.53V)
		12-bit [n-Pulse only]:  Threshold DAC data (0x000 = 0V, 0xFFF = +2.5V)
		 1-bit nKeepAlives (low to turn on keep alive signals for pockels cell)
		 1-bit StatusLed:
				steady on = normal
				flashing  = supplies are asleep
				blink off = triggered
INPUT WORD:
	bit 15: Load (rising edge triggered while command and data setup and held valid)
	 14-12:	Commands (see below)
	  11-0:	Data
COMMANDS:
		0:	 Set HV Supply (n-Pulse) AKA Fine (Piezo) DAC data
		1:	 Set Driver (n-Pulse) AKA Coarse (Piezo) Supply DAC data
		2:	 Set Photodiode Threshold (n-Pulse) DAC data
		3:   Configuration Register.  bit0:KeepAlives, bits1-7:don't care.
		4-7: Unused, but will wake up sleeping HV supplies.
MODUS OPERANDI:
	1) Set the data and command, bit 15 is low.
	2) Toggle bit 15 high then low (no min or max times).
	3) In n-Pulse mode only (Variant = 0), if no PD (PhotoDiode) or USB update for a
	   while, the HV and +160V supplies go to sleep.  To just wake up supplies, blip
	   USB[15] high then low with any unused command.
KUDOS & QUIRKS:
	- bits 14:0 must be held steady while bit 15 rises to prevent racing.
	- bits 14:0 can change after bit 15 has risen but good procedures 
	  says that bit 15 should be brought low first.
	- bit 15 has no min or max high time or duty cycle.
	- config reg bit0 (KeepAlives) are active low to handle power up defaults.
Part of combined project:  N-PULSE SELECTOR & PIEZO DRIVER
	University of Toronto - Physics - Quantum optics
	Started 6 Dec 2005,  astummer_at_physics.utoronto.ca 
*/



********************************************************************************************************
Following is an extract from 'formPiezo.frm' VB6 file.

To get a serial number (and detect if USB is connected):
  Dim Packet As PacketStructure, Ret As RetPacketStructure, SN
  OpenDevice                                                       'GET THE DEVICE'S SERIAL NUMBER.
  Packet.MajorCmd = 11
  Packet.MinorCmd = 10
  Packet.DataLSB = 0
  Packet.DataMSB = 0
  Packet.Length = 0
  Ret = SendPacket(Packet)                                            ' Get the Version infomation.
  SN = ((Ret.B3 * &H1000000) + (Ret.B2 * &H10000) + (Ret.B1 * &H100) + (Ret.B0))
  CloseDevice


To load a DAC:
  OpenDevice
  Vpb = (Vfs - Vzero) / 4095                                                'volts per bit.
  HexData = CInt((Val(Vrequired) - Vzero) / Vpb)   'example only, the DAC can be reversed!
  Packet.MajorCmd = 10                                                            'write to device.
  Packet.MinorCmd = 10                                      'write LSB to port 0 and MSB to port 1.
  Packet.DataLSB = HexData Mod 256                                              'USB[7:0] (P0.0-7).
  Packet.DataMSB = Int(HexData / 256) + CMD1                                   'USB[15:8] (P1.0-7).
  Packet.Length = 0
  SendPacket Packet                                              ' Send the packet with Load false.
  Packet.DataMSB = Packet.DataMSB + &H80
  SendPacket Packet                                               ' Send the packet with Load true.
  Packet.DataMSB = Packet.DataMSB - &H80
  SendPacket Packet                                              ' Send the packet with Load false.
  CloseDevice