forked from optics/eib700
168 lines
7.4 KiB
C
168 lines
7.4 KiB
C
|
|
/***********************************************************************************************/
|
|
int EIB_Init_Axis(int axis_nr) /* initialize selected axis */
|
|
{
|
|
int enc_nr;
|
|
int err;
|
|
long LastRef; /* Read from file */
|
|
int iface;
|
|
EIB7_EncoderType EncType;
|
|
EIB7_Refmarks RefMarks;
|
|
int Lines;
|
|
DATA Data;
|
|
|
|
enc_nr = axis_nr-1;
|
|
|
|
if ((axis_nr<1) || (axis_nr>NUM_OF_AXIS)) // falls nicht connected belege ich die Axen trotzdem
|
|
{
|
|
printf("EIB_Init_Axis: wrong axis number %i, valid values are 1 ..%i\n",axis_nr,NUM_OF_AXIS);
|
|
MonError("Wrong axis number");
|
|
return(MON_ERROR);
|
|
}
|
|
|
|
iface=eib.enc[enc_nr].iface;
|
|
if ((iface < 1) || (iface > 3))
|
|
{
|
|
printf("EIB_Init_Axis: Invalid encoder type %i\n",iface);
|
|
MonError("EIB_Init_Axis: Invalid encoder type");
|
|
return(MON_ERROR);
|
|
}
|
|
|
|
|
|
LastRef= eib.enc[enc_nr].LastRef;
|
|
|
|
if (EIB_ReadRef(axis_nr,&LastRef))
|
|
{
|
|
printf("EIB_Init_Axis: Axis %i LastReference not read. Use %li\n",axis_nr,LastRef );
|
|
}
|
|
else
|
|
{
|
|
printf("EIB_Init_Axis: Axis %i LastReference at %li\n",axis_nr, LastRef);
|
|
}
|
|
|
|
|
|
eib.enc[enc_nr].LastRef = LastRef;
|
|
|
|
if (!eib.connected)
|
|
{
|
|
printf("EIB_Init_Axis: EIB not connected\n");
|
|
printf(" : Soll ich hier die Verbindung (wieder) herstellen?)/\n");
|
|
// monintGenerator(MONINT_EVNT_UPDATE);
|
|
|
|
return(MON_ERROR);
|
|
}
|
|
|
|
|
|
switch(iface) /* initialize selected axis */
|
|
{
|
|
case 1: fprintf(stderr, "EIB_Init_Axis: Initializing encoder %d for 1 Vpp\n", enc_nr+1);/* 1 Vpp */
|
|
|
|
EncType =eib.enc[enc_nr].EncType;
|
|
if ((EncType<0)|| (EncType>1))
|
|
{
|
|
printf("EIB_Init_Axis: invalid EncType %i, valid types 0=linear, 1 = rotary\n",EncType );
|
|
return(MON_ERROR);
|
|
}
|
|
|
|
RefMarks =eib.enc[enc_nr].RefMarks;
|
|
if ((EncType<0)|| (EncType>1))
|
|
{
|
|
printf("EIB_Init_Axis: invalid EncType %i, valid types 0=linear, 1 = rotary\n",EncType );
|
|
return(MON_ERROR);
|
|
}
|
|
Lines =eib.enc[enc_nr].Lines ;
|
|
|
|
err=EIB7InitAxis(eib.axishandles[enc_nr],
|
|
iface, /* incremental, Endat ... */
|
|
EncType, /* Linear, Rotary */
|
|
RefMarks, /* None, one or two reference mark */
|
|
Lines, /* Lines per revolution (only for rotational encoder)*/
|
|
0, /* nominal increment between two fixed reference marks */
|
|
EIB7_HS_None,
|
|
EIB7_LS_None,
|
|
EIB7_CS_CompActive, /* signal compensation on */
|
|
EIB7_BW_High, /* signal bandwidth: high */
|
|
EIB7_CLK_Default, /* not used for incremental interface */
|
|
EIB7_RT_Long, /* not used for incremental interface */
|
|
EIB7_CT_Long /* not used for incremental interface */
|
|
);
|
|
/* Check if EIB was only disconnected but not power cycled and still has a reference */
|
|
|
|
EIB_GetEncoderData(enc_nr,&Data); /* Get Value of Ref1-Mark */
|
|
|
|
if (Data.ref1 != 0) /* EIB hat noch eine Referenz */
|
|
eib.enc[enc_nr].Ref = 1;
|
|
else /* EIB hat vermutlich keine Referenz, es sei denn sie wäre bei 0 */
|
|
{
|
|
if ( eib.enc[enc_nr].LastRef == 0) /* Die Referenz liegt tatsächlich bei 0 */
|
|
eib.enc[enc_nr].Ref = 1;
|
|
else /* FALSE: Eib hat noch Keine Referenz gefunden */
|
|
eib.enc[enc_nr].Ref = 0;
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
case 2: fprintf(stderr, "EIB_Init_Axis: Initializing encoder %d for EnDat 2.1\n", enc_nr+1); /* EnDat 2.1 */
|
|
err=EIB7InitAxis(eib.axishandles[enc_nr] ,
|
|
EIB7_IT_EnDat21,
|
|
EIB7_EC_Linear,
|
|
EIB7_RM_None,
|
|
0, /* not used for EnDat */
|
|
0, /* not used for EnDat */
|
|
EIB7_HS_None,
|
|
EIB7_LS_None,
|
|
EIB7_CS_None, /* not used for EnDat */
|
|
EIB7_BW_High, /* not used for EnDat */
|
|
EIB7_CLK_Default, /* we use the default clock */
|
|
EIB7_RT_Long, /* not used for EnDat 2.1 */
|
|
EIB7_CT_Long /* encoder with long calculation timeout */
|
|
);
|
|
break;
|
|
|
|
case 3: fprintf(stderr, "EIB_Init_Axis: Initializing encoder %d for EnDat 2.2\n", enc_nr+1);/* EnDat 2.2 */
|
|
err=EIB7InitAxis(eib.axishandles[enc_nr],
|
|
EIB7_IT_EnDat22 | EIB7_IT_EnDatDelayMeasurement,/* with EnDat 2.2 we enable the EnDat propagation time compensation */
|
|
EIB7_EC_Linear,
|
|
EIB7_RM_None,
|
|
0, /* not used for EnDat */
|
|
0, /* not used for EnDat */
|
|
EIB7_HS_None,
|
|
EIB7_LS_None,
|
|
EIB7_CS_None, /* not used for EnDat */
|
|
EIB7_BW_High, /* not used for EnDat */
|
|
EIB7_CLK_Default, /* we use the default clock */
|
|
EIB7_RT_Long, /* long EnDat recovery time I */
|
|
EIB7_CT_Long /* encoder with long calculation timeout */
|
|
);
|
|
break;
|
|
|
|
default: break;
|
|
|
|
CheckError(err);
|
|
|
|
}
|
|
return(MON_NO_ERROR);
|
|
}
|
|
../../bin/linux-x86_64/eib
|
|
## You may have to change eib to something else
|
|
## everywhere it appears in this file
|
|
#< envPaths
|
|
## Register all support components
|
|
dbLoadDatabase("../../dbd/eib.dbd",0,0)
|
|
eib_registerRecordDeviceDriver(pdbbase)
|
|
CFG-File EIB.CFG Found
|
|
EIB.CFG opened successfull....
|
|
|
|
cfg-List
|
|
|
|
<E1_iface> <1>
|
|
<E1_RefMarks> <1>
|
|
<E1_EncType> <1>
|
|
<E1_Lines> <3600>
|
|
EIB_Connect : connect to <EIB741-639546320.psi.ch>
|
|
EIB_Connect : IP-address is 129.129.179.223 (2172761055)
|
|
|
|
Error A0000004 (EIB7_CantConnect): could not connect the socket to the device
|
|
Segmentation fault (core dumped)
|