fxnew.h
#define DELAY_TIMES 30000L
#define TRUE 1
#define FALSE 0
#define TRUE 1
#define FALSE 0
#define FORCE_ON 0x37
#define FORCE_OFF 0x38
void init_plc(void);
int check_plc(void);
int _read_data_register(unsigned int uAddress,unsigned int number);
int _read_mdata_register(unsigned int uAddress,unsigned int number);
int _write_data_register(unsigned int uAddress,unsigned int number);
int _force_m_contact(unsigned int uAddress,unsigned char ucOn_off);
int read_data_register(unsigned int uAddress,unsigned int number);
int read_mdata_register(unsigned int uAddress,unsigned int number);
int write_data_register(unsigned int uAddress,unsigned int number);
int force_m_contact(unsigned int uAddress,unsigned char ucOn_off);
int _read_m_register(unsigned int uAddress,unsigned int number);
int read_m_register(unsigned int uAddress,unsigned int number);
int TESTING=0;
unsigned int uRead_value[25];
unsigned int uWrite_value[25];
unsigned int COMM_PORT=1;
unsigned int STATS_PORT=0x2fd;
unsigned int DATA_PORT=0x2f8;
void init_plc(void)
{ _AX=0xfa;
_DX=COMM_PORT;
geninterrupt(0x14);
while((inportb(STATS_PORT)&1)!=0)inportb(DATA_PORT);
}
int check_plc(void)
{ long lTmp;
if(TESTING==1)return TRUE;
init_plc();
for(lTmp=0L;lTmp
{ if((inportb(STATS_PORT)&0x20)!=0)
break;
}
if(lTmp>=DELAY_TIMES)
return(FALSE);
outportb(DATA_PORT,5);
disable();
for(lTmp=0L;lTmp
{ if((inportb(STATS_PORT)&1)!=0)
break;
}
if(lTmp>=DELAY_TIMES)
{ enable();
return(FALSE);
}
if((lTmp=inportb(DATA_PORT))==6)
{ enable();
return(TRUE);
}
else
{ enable();
return(FALSE);
}
}
int read_data_register(unsigned int uAddress,unsigned int number)
{ int i;
for(i=0;i<3;i++)
if(_read_data_register(uAddress,number)==TRUE)
return TRUE;
return FALSE;
}
int _read_data_register(unsigned int uAddress,unsigned int number)
{ unsigned char uSend[]={2,0x30,0x30,0x30,0x30,0x30,0x30,0x32,3,0x30,0x30};
unsigned char uReceive[104];
unsigned int uTmp;
unsigned int uSum;
unsigned int num;
long lTmp;
int i,j;
if(TESTING==1)
{ for(i=0;i
return TRUE;
}
init_plc();
num=number*2;
if((num/16)>=10)
uSend[6]=(unsigned char)(num/16+0x41-10);
else
uSend[6]=(unsigned char)(num/16+0x30);
if((num%16)>=10)
uSend[7]=(unsigned char)((num%16)+0x41-10);
else
uSend[7]=(unsigned char)((num%16)+0x30);
uAddress=uAddress*2+0x1000;
uTmp=uAddress & 0x000f;
uSend[5]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uAddress>>4) & 0x000f;
uSend[4]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uAddress>>8) & 0x000f;
uSend[3]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uAddress>>12)&0x000f;
uSend[2]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uSum=0;
for(i=1;i<9;i++)
uSum=uSum+(unsigned char)uSend[i];
uTmp=uSum&0x000f;
uSend[10]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uSum>>4)&0x000f;
uSend[9]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
for(i=0;i<11;i++)
{ for(lTmp=0L;lTmp
{ if((inportb(STATS_PORT)&0x20)!=0)
break;
}
if(lTmp>=DELAY_TIMES)
{
return(FALSE);
}
outportb(DATA_PORT,uSend[i]);
}
disable();
for(lTmp=0;lTmp
{ if((inportb(STATS_PORT)&1)!=0)
break;
}
if(lTmp>=DELAY_TIMES)