BNC 630 User Manual

Page 79

Advertising
background image

74

'------------------------- Send Binary data to 630 ------------------------
' This is the fastest way to send points to the 630 since it transfers
' the data point with only 2 characters. It is also the least forgiving
' as far as getting the data sent correctly.
'
' Each data point is a 16 bit word which is sent to the 630 in two bytes.
' The high byte is sent first, followed by the low byte.
' The 16 bit value is in "two's complement" format, which represents a number
' from -1.0 to +1.0 as follows:
'
' 8000 ---- E000 ---- FFFF,0 ---- 4000 ---- 7FFF
' -1.0 -.5 0.0 +.5 +1.0
'
' Although a 16 bit value is sent to the 630, the Arbitrary Waveform system
' uses a 12 bit D/A converter, so not all 16 bits are used. Only the uppermost
' 12 bits are used to form the arbitrary waveform point.
'
'
' Rules for Binary format:
'
' 1. IMMEDIATELY after the "B" character in the header the 630 expects the
' first high byte of data point 1. No whitespace is allowed after the "B"
' in Binary mode.
'
' 2. The high byte of each data point is sent first, followed by the low byte.
'
' 3. The SYNC Out output is controlled by bit #3 in the low byte. If this bit
' is set to 1, SYNC Out is set high. If this bit is set to 0, SYNC Out
' is set low.
'------------------------------------------------------------------------------

SendBinary:

IF PointNumber = 1 THEN PRINT #1, "WB"; ' Put header info before 1st data
' point. Must not have CR or LF after

' Convert the value in PointVal to a two's complement hex number
j = 32767
IF PointVal < 0 THEN PointVal = PointVal + 2: j = 32768!

a = INT(PointVal * j) ' Convert -1.0,+1.0 to 0,65535

a = INT(a / 16) ' Only the uppermost 12 bits are used, so
a = a * 16 ' Mask off the lower 4 bits (AND fff0)

IF PointNumber = 2 THEN a = a OR &H8 ' Set SYNC Out bit for second point

' If you let Basic send a 16 bit variable to a port, it will send the low byte
' first and then the high byte.
' The 630 expects the high byte first so we must reverse the two so we
' get the proper byte order (i.e. high byte then low byte)

high = INT(a / 256) ' Get the High byte of the 16 bit value
low = a MOD 256 ' Get the Low byte of the 16 bit value
a = low * 256 + high ' Switch hi and low bytes

IF a > 32767 THEN a = a - 32768 ' Make it signed for conversion to int.

b% = a ' Convert to a 16 bit variable type
PUT #1, , b% ' Write low byte, then hi byte to file

RETURN

Advertising