Attribute VB_Name = "I332_DEF"
Option Explicit

'{ Konstanten für IFCMode: }
Public Const imNoIFC = 0            '{kein Interface}

Public Const imISA = &H8            '{ISA-Bus-Version}
Public Const imPCI = &HC            '{PCI-Bus-Version}
Public Const imUSB = &HD            '{USB-Version}

Public Const imCOM = &H10           '{serielle Version}
Public Const imCOM1 = imCOM + 1
Public Const imCOM2 = imCOM + 2
Public Const imCOM3 = imCOM + 3
Public Const imCOM4 = imCOM + 4

      '{ Fehlerkonstanten: }
Public Const ieNoErr = 0               '{Fehlernummern, neg.: fatal}
Public Const ieInternal = -1
Public Const ieNotImplemented = -2
Public Const ieUnknown = -3            '{unbekannter Fehler}

Public Const ieNoIFC = -10             '{Interface nicht initialisiert}

Public Const ieIFC = -11               '{unzulässige Interface-Nr.}
Public Const ieCOM = -12               '{keine Schnittstelle mit dieser Nr.}
Public Const ieDev = -12               '{keine Schnittstelle mit dieser Nr.}
Public Const ieInvalid = -13           '{Funktionsaufruf nicht zulässig}

Public Const ieNoI332 = -20
Public Const ieTimeOut = -21
Public Const ieSync = -22

'{********************************************************************}

'{ allgemeine Konstanten- und Typ-Vereinbarungen }

Public Const Axes = 8        '{ max. AnzahlPublic Const der I332-Achsen }
Public Const UndefL = &H80000000
Public Const Minus0 = &H80000000
Public Const FEilgang = 0    '{ Für i332_Ifc-Routinen: F = 0 --> Eilgang }

Public Const fAbs = &H1
Public Const fRel = &H0
Public Const fCW = &H4
Public Const fCCW = &H0

'TYPE TAxes = 0..Axes-1
'     TAxisArray = ARRAY [TAxes] OF LONGINT
'     TAxLbls   = ARRAY [TAxes] OF Char

Public Type TAxisArray
  Values(Axes) As Long
End Type

Public Type TAxLbls
  AxLbls As String * Axes
End Type

Public Type TI332ID
  I332ID As String * 16
End Type

Public Type TI332Info
    ifcMode As Long
    ifcPara As Long
    IFCErr As Long
    i332Ver As Long
    I332ID(16) As Byte
End Type

Public Type TI332InfoEx
    size As Long
    i332Ver As Long
    i332Dat As Long
    i332Axes As Long
    i332RAMSize As Long
    I332ID As Long
End Type

'{ Fehlernummern div. Routinen (fehlerhafte Daten/Parameter u.ä.) }
Public Const deNoError = 0
Public Const deAxisNo = 1
Public Const deSFAktiv = 2
Public Const deSFRtg0 = 3
Public Const deRtgLS = 4
Public Const deSFDist0 = 5
Public Const deIPL_OV = 6


'{**********************************}
'{ Command summary I332             }
'{**********************************}

'{********************************************************************}
'{ Command Table                                                      }
'{ numerical order                                                    }
'{ units for datawords specifiing                                     }
'{ - distances or paths : my (1/1000mm)                               }
'{ - speeds: mm/min                                                   }
'{ - accelerations/decelerations: mm/sec                              }
'{********************************************************************}

'{ commands related to axes: &Haa00..$aa7F   }
'{ aa = No of axis may be added to highword }

'{ axis registers for interpolation: }
Public Const icSetDist = &H0       '{W2 - set distance for next interpolation movement}
Public Const icSetPos = &H1        '{W2 - set present position counter}
Public Const icSetCP = &H2         '{W2 - set distance to center point (coordinates
                            '      of center point relativ to starting point)}

Public Const icGetPos = &H81       '{R2 - get present position counter}

Public Const icSetSFDist = &H10    '{W2 - set distance for next special function}
Public Const icSetSFVCmd = &H11    '{W2 - set speed for next special function}
Public Const icSetSFV = icSetSFVCmd

Public Const icGetRest = &H83      '{R2 - rest of distance of actual movement }
Public Const icGetPos0 = &H85      '{R2 - get present position counter (incl. axis lag) }

'{ special functions &Haa50..$aa5F: W1}
      '{ general datawords - special datawords may be added }
      '{ direction: }
  Public Const sfPos = &H0         '{ positive direction }
  Public Const sfNeg = &H80        '{ negative direction }
      '{ speed, may be added to sfPos or sfNeg: }
  Public Const sfStd = &H0         '{ standard speed for desired function, i.e. apVRef for icSFRef }
  Public Const sfVCmd = &H1        '{ speed is SFVCmd }
  Public Const sfVMax = &H3        '{ speed is apVMax }
  Public Const sfVSS = &H4         '{ speed is min (apVStart,apVStop) }

  Public Const sfBreak = &HFFFF  '{ dataword to break any special function }

  Public Const sfLSOff = &H10      '{ Limit switch results only in axis stop  stLSB will not be set }
  Public Const sfPotiOff = &H20    '{ Poti is not active for this special function }

Public Const icSFRef = &H50        '{W1 - special function: moving to ref position}
        '{ special datawords for icSFRef (may be added to sfXXX): }
  Public Const rm = &HF00        '{general mode for reference movement}
  Public Const rmRef = &H1000    '{also search refpuls and move to apRefOffs
                          '(with I332-DC only)}
  Public Const rmPos = &H2000    '{also set position counter as defined in
                          'register SFDist at ref position,
                          'otherwise set as defined in apRefPos}
  Public Const rmSWLS = &H4000   '{set SW-LS, if defined (apLSDeltaM <> apLSDeltaP)}

Public Const icSFAsync = &H51      '{W1 - special function: moving axis asynchronously }
  '{ special datawords for icSFAsync (may be added to sfXXX): }
  Public Const asAbs = &H8000      '{absolute position}

Public Const icSFHand = &H52       '{W1 - special function: moving axis with desired
                            '      speed until break}

      '{ available from V2.2.30: }
Public Const icSFJoystick = &H56     '{ W1 - special function: use ADC as Joystick-Input
                              '       for desired axis  datword.high = ADC input no}
Public Const icJSKennlinie = &H16    '{ W1 - dataword.high: Stützpunkt
                              '       dataword.low: value = -128..+127 = -100%..+100% }

Public Const icSFHandRad = &H54    '{ W1 - Highbyte Datenwort: DG-Nr }
                           '{      0..7:  DC-Karte           }
                           '{      &HA,$B: I332               }
                           '{      &HE,$F: PC - Quasi-DG      }

      '{ Drehgeber-Faktor: Umsetzung der Pulse in Achsbewegung  }
Public Const icSetDG_my = &H12      '{ W2 - 1000stel mm pro...       }
Public Const icSetDG_pls = &H13     '{ W2 - ...Anzahl Drehgeberpulse }

'{ general axis registers for special functions }
Public Const icGetSFDist = &H90    '{R2 - get present position relative to
                            '      start of current special function}
Public Const icGetSFVCur = &H91    '{R2 - get speed of axis}
Public Const icGetSFV = icGetSFVCur

'{ PID registers, only used by PID algorithm }
Public Const icGetPIDCmdPos = &HA0    '{R2 - PID controler: command position }
Public Const icGetPIDCurPos = &HA1    '{R2 - PID controler: current position counter}
Public Const icGetPIDFErr = &HA2      '{R2 - PID controler: following error }

'{ axis parameter: }
Public Const icSetAP = &H4000      '{W2 - set parameter - base command}
Public Const icGetAP = &H4080      '{R2 - get parameter - base command}

      '{ following Public Constants defining the parameter }
      '{ may be added to base command:              }
      '{                    Description                Default}
  Public Const apVMax = &H0       '{maximum speed                 1000}
  Public Const apVStart = &H1     '{start speed                    100}
  Public Const apVStop = &H2      '{stop speed                     100}
  Public Const apAcc = &H3        '{acceleration                   500}
  Public Const apDec = &H4        '{deceleration                   500}
  Public Const apMod = &H5        '{modulo in æm                     0}

  Public Const apStep = &H6       '{steps...                      1000}
  Public Const apmm = &H7         '{.....per mm                      1}

  Public Const apVRef = &H8       '{speed for reference movement   500}
  Public Const apVHys = &H9       '{speed to release limit switch  200}
  Public Const apVRefP = &HA      '{speed for searching Refpuls     20}

  Public Const apHys = &HB        '{hysteresis to limit switch    1000}
  Public Const apHysMax = &HC     '{maximum distance to release limit switch 50000}

  Public Const apLS = &HD           '{limit switch definitions,
                             'bits set to 1 mean:            Default}
    Public Const lsPInB = 0        '{LS at ES+ input                      1}
    'Public Const lsPInF   = 1 shl lsPInB
    Public Const lsPPolB = 1       '{+LS active high                      0}
    'Public Const lsPPolF  = 1 shl lsPPolB
    Public Const lsPRefB = 2       '{+LS only active during ref movement! 0}
    'Public Const lsPRefF  = 1 shl lsPRefB
    Public Const lsPHDirB = 4      '{+LS: releasing LS in neg. direction  1}
    'Public Const lsPHDirF = 1 shl lsPHDirB
    Public Const lsPRDirB = 5      '{+LS: searching refpuls in neg. dir.  1}
    'Public Const lsPRDirF = 1 shl lsPRDirB

    Public Const lsMInB = 8        '{LS at ES- input                      1}
    'Public Const lsMInF   = 1 shl lsMInB
    Public Const lsMPolB = 9       '{-LS active high                      0}
    'Public Const lsMPolF  = 1 shl lsMPolB
    Public Const lsMRefB = 10      '{-LS only active during ref movement! 0}
    'Public Const lsMRefF  = 1 shl lsMRefB
    Public Const lsMHDirB = 12     '{-LS: releasing LS in neg. direction  1}
    'Public Const lsMHDirF = 1 shl lsMHDirB
    Public Const lsMRDirB = 13     '{-LS: searching refpuls in neg. dir.  1}
    'Public Const lsMRDirF = 1 shl lsMRDirB

    Public Const lsChgB = 7        '{ changing physical <-> logical LS relation   0}
    'Public Const lsChgF   = 1 shl lsChgB
    Public Const lsRefMB = 15      '{ Ref-mov in negative direction       0}
    'Public Const lsRefMF  = 1 shl lsRefMB

          '{ all flags for pos. or neg. direction: }
    'Public Const lsDirF = lsPInF + lsPPolF + lsPRefF + lsPHDirF + lsPRDirF
    '               + lsMInF+lsMPolF+lsMRefF+lsMHDirF+lsMRDirF

        '{default summary = &H0131 -->
        ' - both LS connected, polarity = active low (or open connection),
        ' - releasing LS and searching refpuls in opposite direction respectivly }

  Public Const apLSMax = &HF      '{ max. LS braking distance,              0
                           ' 0 --> normal deceleration ramp }

  Public Const apChar = &H10      '{axis characteristics,
                           'bits set to 1 mean:            Default}
    Public Const acPathB = 0     '{axis defines path of movement    XYZ=1}
    'Public Const acPathF = 1 shl acPathB
    Public Const acSMB = 8       '{machine: stepper motor               1}
    'Public Const acSMF   = 1 shl acSMB
    Public Const acDCB = 9       '{machine: DC servomotor (PID-alg.)    0}
    'Public Const acDCF   = 1 shl acDCB
    Public Const acTypMsk = &H3
    Public Const acDrvMsk = &H700

        '{default summary = &H0101 for axes 0..2 (XYZ), &H0100 axes 3..7:
        ' - axes XYZ define path of movement, speed related to this axes
        ' - all stepper motors}

  Public Const apSM = &H11        '{characteristics of SM axes,
                           'bits set to 1 mean:         Default}
    Public Const smPlsPolB = 0   '{SM puls output active Low         1}
    'Public Const smPlsPolF = 1 shl smPlsPolB
    Public Const smDirPolB = 1   '{SM direction output active Low    0}
    'Public Const smDirPolF = 1 shl smDirPolB
        '{default summary = &H0001 for all axes:
        ' - puls output is active low
        ' - direction output is high for positiv direction}

  Public Const apDC = &H12        '{characteristics of DC axes,
                           'I332-DC board required,
                           'bits set to 1 mean:          Default}
    Public Const dcEnOutB = 0    '{axis uses enable output            0}
    'Public Const dcEnOutF  = 1 shl dcEnOutB
    Public Const dcEnPolB = 1    '{polarity of enable output          0}
    'Public Const dcEnPolF  = 1 shl dcEnPolB
    Public Const dcRdyInB = 2    '{axis uses ready input              0}
    'Public Const dcRdyInF  = 1 shl dcRdyInB
    Public Const dcRdyPolB = 3   '{polarity of ready input            0}
    'Public Const dcRdyPolF = 1 shl dcRdyPolB
    Public Const dcRefInB = 4    '{axis uses reference input          0}
    'Public Const dcRefInF  = 1 shl dcRefInB
    Public Const dcRefPolB = 5   '{polarity of reference input        0}
    'Public Const dcRefPolF = 1 shl dcRefPolB

    Public Const dcDGInvB = 8    '{ inverting evaluation of pos.counter  0}
    'Public Const dcDGInvF  = 1 shl dcDGInvB
    Public Const dcDACInvB = 9   '{ inverting DAC output signal          0}
    'Public Const dcDACInvF = 1 shl dcDACInvB

        '{default summary = &H0000 for all axes}

        '{ parameters defining machine positions, will be set during
        '  reference movement  see also icSFRef }
  Public Const apLSDeltaM = &H14    '{ SW-LS: distance to left }
  Public Const apLSDeltaP = &H15    '{        and right ref position }
  Public Const apRefOffs = &H16     '{ offset: axis will be moved after searching
                             ' ref puls by that distance}
  Public Const apRefPos = &H17      '{ position of ref puls / machine zero point
                             ' will be set after reference movement }

        '{axis parameters for PID-algorithm (with I332-DC only):}
  Public Const apPFac = &H18      '{P-factor                  20}
  Public Const apIFac = &H19      '{I-factor                   0}
  Public Const apDFac = &H1A      '{D-factor                   0}
  Public Const apVFac = &H1B      '{V-factor                   0}

  Public Const apInPos = &H1C     '{in position area          10}
  Public Const apFEMax = &H1D     '{maximum following error 1600}
  Public Const ap0Off = &H1E      '{zero offset for DAC        0}
  Public Const apAmpMax = &H1F    '{output limit to DAC    32000}

  Public Const apdFMax = &H20     '{similiarly as apFEMax controls differences in
                           'command/current position this parameter will
                           'control differences in subsequent current axis
                           'speed values            1600}

'{ axis overlay: }
Public Const icAxisOvl = &H6000  '{W0 - output of an desired axis (A) will also be
                          '      outputted to another motor (M) --> both
                          '      motors will move synchronously.
                          '      Same values of apStep/apmm is desired for
                          '      both axes. No of axis (A) may be added to
                          '     low byte, No of axis (M) may be added to
                          '      high byte, i.e. &H6102 means output of
                          '      axis No 1 will be the same as programmed for
                          '      No 2, but not vice versa!!!
                          '      programming (A) = (M) releases the overlay,
                          '      i.e. &H6101}

'{ miscellaneous commands: }

Public Const icIPL = &H8000
Public Const icIPLlin = &H8001     '{W0 - linear interpolation}
Public Const icIPLcw = &H8002      '{W1 - circular interpolation clockwise}
Public Const icIPLccw = &H8003     '{W1 - circular interpolation counter clockwise
                            '      dataword: highbyte/lowbyte = No of axis
                            '      defining X/Y-coordinates,
                            '      path will be the defined circular arc,
                            '      overriding path bits in apChar}
        '{adding one of the following Public Constants means:}
  Public Const iplModePos = &H80     '{positioning, speed = apVMax}
  Public Const iplModePath = &H0     '{interpolation, speed = VCmd}

Public Const icIPLWait = &H8004     '{W0 - wait a number of msec, specified as in icSetWait }

Public Const icSetID = &H8400      '{W2 - Ident-No. of interpolation moves}
Public Const icGetID = &H8480      '{R2 - Ident-No. of interpolation moves}

Public Const icSetStdM = &H8410    '{W2 - setting standard M functions, this command
                            '      requires definition of mpSP_Ports
                            '      highword / lowword: specifiing M func. at
                            '      beginning / at the end of movement
                            '      &H0000 : no function
                            '      &H0001 : M03 (spindle clockwise)
                            '      &H0002 : M04 (spindle counter clockwise
                            '      &H0003 : M05 (spindle stop)}
  Public Const m03Beg = &H10000
  Public Const m04Beg = &H20000
  Public Const m05Beg = &H30000
  Public Const m03End = &H1
  Public Const m04End = &H2
  Public Const m05End = &H3

Public Const icGetStdMCur = &HC885  '{R1 - getting currently active standard M
                             '      functions  bits as defined above}

Public Const icSetWait = &H8401    '{W2 - waiting time (in msec)      }
Public Const icGetWait = &H8481    '{R2 - waiting time left (in msec) }

Public Const icSetAccFac = &H8406  '{W1 - acceleration factor, &H8000 = 100%}
Public Const icSetDecFac = &H8407  '{W1 - deceleartion factor, &H8000 = 100%}

Public Const icSetVCmd = &H9000    '{W2 - Command speed for interpolation related
                            '      to axes with apPathB set
                            '      will be used until written again }
Public Const icGetVCmd = &H9080    '{R2 - get interpolation command speed }
Public Const icGetVCur = &H9081    '{R2 - get current interpolation speed }

Public Const icSetSCmd = &H9010    '{W2 - spindle speed (rpm), using this feature requires
                            '      definition of mpSP_Data and mpSP_SMax
                            '      speed will be always set at the beginning of
                            '      movement }
Public Const icGetSCmd = &H9090    '{R2 - defined spindle speed }
Public Const icGetSCur = &H9091    '{R2 - current spindle speed }

Public Const icSetOvr = &H9800     '{W0 - poti override, a value of 1..$FF
                            '      = 0.39%..200% may be added to lowbyte.
                            '      This will override the speed poti
                            '      connected to ADC0. A value of 0 will
                            '      activate the poti.}

Public Const icGetOvr = &H9084    '{R2 - Highword: actual overide, &H8000 = 100% }

      '{ machine data: defining base configuration of the machine }
      '{ base commands, number of machine data register may be added: }
Public Const icSetMP = &HB000      '{W2 - set machine data register }
Public Const icGetMP = &HB080      '{R2 - get machine data register }

      '{ machine data registers }
  Public Const mpCode = &H8            '{ identification number, 0..255 reserved }
  Public Const mpRAMSize = &H10        '{ on board RAM size }
  Public Const mpAxis = &H1F           '{ no of axis        }

  Public Const mpPotiInit = &H5B       '{ highword: OvrInit, lowword: Poti max.}

        '{ spindle data: }
  Public Const mpSP_Data = &H30      '{ &H00 | &H00 | spType | spPort }
                              '{spType 0: no spindle
                              '        1: -SMax..+SMax = &H8000..$7FFF
                              '      &H80: +SMax..-SMax = &H8000..$7FFF
                              ' spPort : 0..7 = DC_X..DC_C
                              ' }
  Public Const mpSP_MPorts = &H31    '{ spindle switches:
                              '  highword: right/left (cw/ccw - M03/M04)
                              '  lowword:  on/off (M03,M04 / M05)
                              '    lowbyte: portno
                              '    highbyte: Bit3..1 = port output for M05..M03}
  Public Const mpSP_SMax = &H33      '{ max. speed (rpm)}

        '{ Initialization of I332 related ports }
        '{ changing output values will only take effect, if the ports
        '  are not related to their specific axis function }

        '{ SM-Ports, puls/dir outputs are related to bits 0/1..14/15: }
  Public Const mpSMOutDef = &H3C       '{ Reset output value    }
  Public Const mpSMOutPAR = &H40       '{ Reset port assignment }

        '{ Enable port I332-DC, enable outputs are related to bits 16..23: }
  Public Const mpEnOutDef = &H3D       '{ Reset output value    }
  Public Const mpEnOutPAR = &H41       '{ Reset port assignment }

        '{ Initialization of I332-IO card (ports &H60..$7F): }
  Public Const mpIOOutDef = &H3F       '{ Reset output value    }
  Public Const mpIOOutPAR = &H43       '{ Reset port assignment }
                                '{ both registers:
                                '  lowword OUT17..32, highword OUT1..16!}

        '{ PID-Algorithm: }
  Public Const mpFEFatal = &H49        '{ fatal following error, 32000
                                '  results in setting statusregister stFEB }

        '{ configuring emergency stop input: }
  Public Const mpEmStop = &H6F         '{ Bit 15 = 1: activating emergency stop input
                                '  Lowbyte   : configuring emergency routine: }
    Public Const emActiveB = 15  ' emActiveF = 1 shl emActiveB
    Public Const emStop = &H0          '{ only clear stSSB and stSFB             }
    Public Const emBreak = &H1         '{ additionally clear all enable outputs  }

Public Const icStatus = &HC000     '{status word (bitregister):}
                           '{Public Constants brMode... may be added (see bottom)}
        '{ these status bits only can be read: }
  Public Const stLSB = 0     '{ limit switch stop, a restart command is necessary,
                      '  active limit switches may be read by command &HD001}
  Public Const stLSF = &H1      ' 1 shl stLSB
  Public Const stErrB = 1       '{ error occured, reset by reading ErrNo (icGetErrNo)}
  Public Const stErrF = &H2     ' 1 shl stErrB
  Public Const stOVB = 2        '{ overflow: movement buffer full}
  Public Const stOVF = &H4      ' 1 shl stOVB
  Public Const stMVB = 3        '{ at least 1 axis is moving}
  Public Const stMVF = &H8      ' 1 shl stMVB
  Public Const stFEB = 4        '{ following error stop, following err > mpFEFatal,
                                '  enable outputs to amplifier are set to 0
                                '  a restart command is necessary! }
  Public Const stFEF = &H10     ' 1 shl stFEB
  Public Const stBNEB = 5       '{ Buffer not empty (icGetBlockCnt = 0) }
  Public Const stBNEF = &H20    ' 1 shl stBNEB
  Public Const stFEMaxB = 6     '{ max. following error ( > apFEMax)}
  Public Const stFEMaxF = &H40  ' 1 shl stFEMaxB

        '{ these status bits may be read and written: }
  Public Const stSFB = 8        '{ start/stopbit for special functions}
  Public Const stSFF = &H100    ' 1 shl stSFB
  Public Const stSSB = 12       '{ start/stopbit for interpolation}
  Public Const stSSF = &H1000   ' 1 shl stSSB
  Public Const stSCB = 13       '{ single step/contingous movement:
                                ' stSSB will be cleared after every
                                ' interpolation movement}
  Public Const stSCF = &H2000   ' 1 shl stSCB

Public Const icGetBlockCnt = &HB100  '{R2 - Number of IPL-blocks downloaded to I332
                              '      and not yet executed }

Public Const icGetErrNo = &HC100   '{R1 - reading errno, resetting Status[stErrB]}
  Public Const ieROMChkSum = &H1      '{error in program memory}
  Public Const ieRefHys = &H11        '{ref movement: RefSwitch remains closed }
  Public Const ieEmergency = &H41     '{emergency stop input was active}
  Public Const ieEmergency0 = &H40    '{emergency stop, mode 0}
  Public Const ieEmergency1 = &H41    '{emergency stop, mode 1}
  Public Const iePID = &H20           '{timeout PID controler}
  Public Const ieIPL = &H21           '{timeout interpolation}
                              '{other values report internal errors,
                              ' please refer to handbook or
                              ' contact your distributor}

Public Const icGetPIDInfo = &HC800 '{R2 - informations from PID algorithm,
                            '      valid for servo axes only:
                            '      4 Bytes - Bit7..0 = axis7..0, Bit = 1 means:
                            '      MSB: axis enabled (enable output to amplifier)
                            '      .  : axis in position (refer to apInPos)
                            '      .  : following error > apFEMax
                            '      LSB: amplifier is ready}

Public Const icGetRefInfo = &HC883 '{R1 - Lowbyte: Bit = 1: axis was referenced }
Public Const icGetSFInfo = &HC900  '{R1 - informations about special function as
                            '      bitflags.
                            '      desired function (icSF...) may be added to
                            '      lowbyte of command.
                            '      Bitflags for the axes 0..7 mean:
                            '      MSB : desired special function is active
                            '      LSB : either special function is active
                            '      if no function is specified (i.e. command
                            '      low byte = 0), LSB is valid
                            '      LSB = 0: MSB also = 0, undefined otherwise }

Public Const icSFBreak = &HC9FF    '{R1 - breaks all active special functions
                            '      gets all active functions as bitflags
                            '      (LSB only).}

Public Const icSetPIDEn = &HCC00   '{W0 - Bitflags for the axes 0..7 may be added
                            '      to lowbyte of command enabling
                            '      the desired servo axes}

      '{limit switch of axes 0..7: bits 0..7  representing +LS,
      '                            bits 8..15 representing -LS}
Public Const icGetLS = &HD000      '{R1 - reading limit switch inputs directly}
Public Const icGetLSAkt = &HD001   '{R1 - active limit switches}
Public Const icLSOff = &HD0FF      '{W0 - toggles value of all LS inputs,
                            '      should only be used for testing purposes!!!}

      '{ Base commands accessing port bits, access modes: }
Public Const icMPorts = &HD200   '{ access synchronously to movement (a)             }
Public Const icPorts = &HD100    '{ direct port access (b), port assignment register }

      '{ general Public Constants accessing ports: }
      '{ accessing axis related ports will only take effect if there is no
      '  axis connected! }
        '{ Public Constants accessing portgroups }
  Public Const pgIO1 = &H60         '{ I332-IO card IN/OUT01..16}
  Public Const pgIO2 = &H70         '{ I332-IO card IN/OUT17..32}
  Public Const pgSM = &H0           '{ I332 SM-outputs Bits0..15: puls0/dir0..puls7/dir7 }
  Public Const pgLS = &H10          '{ I332 LSM/LSP inputs }
  Public Const pgRef = &H20         '{ I332-DC, Bits0..7: Ref inputs}
  Public Const pgEn = &H20          '{ I332-DC, Bits0..7: enable outputs}
  Public Const pgRdy = &H30         '{ I332-DC, Bits0..7: ready inputs}

  Public Const pmPut = &H0          '{ setting port bits accordingly to dataword  }
  Public Const pmClr = &H1          '{ clearing port bits accordingly to dataword }
  Public Const pmSet = &H2          '{ setting port bits accordingly to dataword  }
  Public Const pmChg = &H3          '{ changing port bits accordingly to dataword }
                            '{ (access mode b only)                       }

      '{ access mode a): additionally may be defined the effect of        }
      '{ port access at the beginning or the end of the movement          }
Public Const icSetMPorts = &HD200   '{W1 }
  Public Const psBeg = &H0          '{ port access takes effect at the beginning  }
  Public Const psEnd = &H8          '{ port access takes effect at the end        }

      '{ access mode b), defining port assignment registers (PAR), e.a.   }
Public Const icSetPorts = &HD100    '{W1 }
Public Const icGetPorts = &HD180    '{R1 }
  Public Const prOutBuf = &H4       '{ accessing output buffer            }
  Public Const prOutPAR = &H8       '{ accessing port assignment register }
  Public Const prPort = &HC         '{ direct port access                 }

Public Const icGetOutBuf = icGetPorts + prOutBuf '{R1 - actual output      }
Public Const icGetInPortC = icGetPorts + prPort  '{R1 - actual input       }
Public Const icGetInPort = icGetPorts + prPort
Public Const icSetOutBuf = icSetPorts + prOutBuf '{W1 - writing output port via buffer  }
                                          '{ "OutBuf"  only takes effect if      }
                                          '{ corresponding bit of PAR = 1        }
Public Const icSetOutPort = icSetPorts + prPort  '{W1 - writing output port directly    }
                                          '{ but will be overwritten immediately }
                                          '{ with OutBuf by I332...              }
Public Const icSetMOutBuf = &HD204
Public Const icGetMOutBuf = &HD284

Public Const icSetOutPAR = icSetPorts + prOutPAR '{W1 - writing PAR        }
Public Const icGetOutPAR = icGetPorts + prOutPAR '{W1 - reading PAR        }
                                          '{ Bit = 0/1: defining    }
                                          '{ accessmode a) / b)     }
      '{ other IO-Devices: }
Public Const icGetDG = &HD880     '{ R1 - Reading counter-reg. on I332-DC card,  }
                          '{      counter No may be added to low byte(!) }

Public Const icSetDAC = &HD840    '{ W1 - Writing DAC on I332-DC card,           }
                          '{      DAC No may be added to low byte(!)     }
Public Const icGetDAC = &HD8C0    '{ R1 - Reading DAC on I332 card               }
                          '{      DAC No may be added to low byte(!)     }

Public Const icGetADC = &HD890    '{ R1 - Reading ADC on I332 card (10bit)       }
                          '{      ADC No may be added to low byte(!)     }
                          '{      ADC0 is reserved (poti-reg.)           }

Public Const icGetVerNo = &HF000   '{R2 - version/revision-no, BCD-coded vv.vv.rrrr}
Public Const icGetVerDat = &HF001  '{R2 - date BCD-coded ddmmyyyy}

Public Const icGetVerStr = &HF100  '{R1 - version message: ASCII-string,
                            '      string index may be added to lowbyte
                            '      result of read1-operation are 2 ASCII chars
                            '      in high/low order.
                            '      to read the whole string increment lowbyte,
                            '      until result.lowbyte = 0 (note: result.highbyte
                            '      may contain the last valid char!}

Public Const icAPEnd = &HFE00      '{W0 - ends definition of axis parameters}

Public Const icRestart0 = &HFF00   '{W0 - (nearly) complet reinitialising of
                            '      I332 software}

Public Const icRestart1 = &HFF01   '{W0 - resetting PID-algorithm, clearing movement
                            '      buffer and position registers and all
                            '      internal memory locations, except of the
                            '      axis parameters, resets all outputs to
                            '      their defaults as in apXXDef }
Public Const icRestart2 = &HFF02   '{W0 - as icRestart1, present position counters
                            '      stay unchanged}
Public Const icRestart3 = &HFF03   '{W0 - as icRestart2, no initialisation of
                            '      PID-algorithm}
Public Const icRestart5 = &HFF05   '{W0 - as icRestart3, but clearing following errors}

      '{ the following reset commands will not reset any output }
Public Const icRestart11 = &HFF11  '{W0 - as icRestart1  }
Public Const icRestart12 = &HFF12  '{W0 - as icRestart5! }
Public Const icRestart13 = &HFF13  '{W0 - as icRestart3  }

Public Const icRestart14 = &HFF14  '{W0 - break interpolation and all special function    }
Public Const icRestart15 = &HFF15  '{W0 - as icRestart14, also clear all follwoing errors }

Public Const icClrFE = &HFF0A      '{W0 - only clears all following erros }

Public Const icInitMP = &HFF08     '{W0 - ends definitions of machine data and
                            '      axis parameters, internal reset similiar
                            '      icRestart0 }

Public Const icResetMP = &HFF0B    '{W0 - resets all machine data to its defaults,
                            '      but no internal initialisation is done,
                            '      so an additionally icInitMP is required,
                            '      even if no further command icSetMP or
                            '      icSetAP is invoked }

'{------------------------------------------------------------------------------}
'{ Public Constants specifiing bitregister commands (i.e. icStatus),
'  defining this command as W0/W1/W2/R1/R2
'  this Public Constants may be added to the command: }
  Public Const brModePutL = &H0       '{W1 - writing lowword of register}
  Public Const brModePutH = &H10      '{W1 - writing highword of register}
  Public Const brModePut = &H1        '{W2 - writing high and lowword of register}
  Public Const brModeGetL = &H80      '{R1 - reading lowword of register}
  Public Const brModeGetH = &H90      '{R1 - reading highword of register}
  Public Const brModeGet = &H81       '{R2 - reading high and lowword of register}

                            '{clearing all bits in bitregister
                            ' cleared in dataword}
  Public Const brModeClrL = &H20      '{W1 - clearing bits in lowword}
  Public Const brModeClrH = &H30      '{W1 - clearing bits in highword}
  Public Const brModeClr = &H21       '{W2 - clearing bits in high and lowword}

                            '{setting all bits in bitregister
                            ' set to 1 in dataword}
  Public Const brModeSetL = &H40      '{W1 - setting bits in lowword}
  Public Const brModeSetH = &H50      '{W1 - setting bits in highword}
  Public Const brModeSet = &H41       '{W2 - setting bits in high- and lowword}

                            '{toggle all bits of bitregister
                            ' set to 1 in dataword}
  Public Const brModeChgL = &H60      '{W1 - toggle bits in Lowword}
  Public Const brModeChgH = &H70      '{W1 - toggle bits in highword}
  Public Const brModeChg = &H61       '{W2 - toggle bits in high und lowword}

                            '{changing single bits
                            ' Bitno may be added, specifiing bit 0..15 will
                            ' return lowword, specifiing bit 16..31 will
                            ' return highword of register}
  Public Const brModeClrB = &HA0      '{R1 - clearing single bit}
  Public Const brModeSetB = &HC0      '{R1 - setting single bit}
  Public Const brModeChgB = &HE0      '{R1 - toggle single bit}
'{------------------------------------------------------------------------------}

