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
Break;
}
If(lTmp>=DELAY_TIMES)
Return(FALSE);
Outportb(DATA_PORT,5);
Disable();
For(lTmp=0L;lTmp
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
}
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=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uAddress>>8) & 0x000f;
uSend=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uAddress>>12)&0x000f;
uSend=(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
Break;
}
If(lTmp>=DELAY_TIMES)
{
Return(FALSE);
}
Outportb(DATA_PORT,uSend[i]);
}
Disable();
For(lTmp=0;lTmp
Break;
}
If(lTmp>=DELAY_TIMES)
{
Enable();
Return(FALSE);
}
uReceive[0]=inportb(DATA_PORT);
If(uReceive[0]!=2)
{
Enable();
Return(FALSE);
}
For(i=1;i
Break;
}
If(lTmp>=DELAY_TIMES)
{
Enable();
Return(FALSE);
}
uReceive[i]=inportb(DATA_PORT);
}
Enable();
uSum=0;
For(i=1;i
uTmp=uSum&0xf;
uTmp=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
If((unsigned char)uTmp!=uReceive[number*4+3])return(FALSE);
uTmp=(uSum>>4)&0xf;
uTmp=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
If((unsigned char)uTmp!=uReceive[number*4+2])return(FALSE);
For(j=0;j
uRead_value[j]=(((((Recipive[j*4+3]<<4)+uReceive[j*4+4])<<4)+uReceive[j*4+1])<<4) +uReceive[j*4+2];
}
Return TRUE;
}
Int read_mdata_register(unsigned int uAddress,unsigned int number)
{int i;
For(i=0;i<3;i++)
If(_read_mdata_register(uAddress,number)==TRUE)
Return TRUE;
Return FALSE;
}
Int _read_mdata_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
}
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=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uAddress>>8) & 0x000f;
uSend=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uAddress>>12)&0x000f;
uSend=(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
Break;
}
If(lTmp>=DELAY_TIMES)
{
Return(FALSE);
}
Outportb(DATA_PORT,uSend[i]);
}
Disable();
For(lTmp=0;lTmp
Break;
}
If(lTmp>=DELAY_TIMES)
{
Enable();
Return(FALSE);
}
uReceive[0]=inportb(DATA_PORT);
If(uReceive[0]!=2)
{
Enable();
Return(FALSE);
}
For(i=1;i
Break;
}
If(lTmp>=DELAY_TIMES)
{
Enable();
Return(FALSE);
}
uReceive[i]=inportb(DATA_PORT);
}
Enable();
uSum=0;
For(i=1;i
uTmp=uSum&0xf;
uTmp=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
If((unsigned char)uTmp!=uReceive[number*4+3])return(FALSE);
uTmp=(uSum>>4)&0xf;
uTmp=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
If((unsigned char)uTmp!=uReceive[number*4+2])return(FALSE);
For(j=0;j
uRead_value[j]=(((((Recipive[j*4+3]<<4)+uReceive[j*4+4])<<4)+uReceive[j*4+1])<<4) +uReceive[j*4+2];
}
Return TRUE;
}
Int write_data_register(unsigned int uAddress,unsigned int number)
{int i;
For(i=0;i<3;i++)
If(_write_data_register(uAddress,number)==TRUE)
Return TRUE;
Return FALSE;
}
Int _write_data_register(unsigned int uAddress,unsigned int number)
{ unsigned char uSend[111];
Unsigned int uTmp, uSum, num;
Long lTmp;
Int i;
If(TESTING==1)return TRUE;
Init_plc();
uSend[0]=2;
uSend=0x31;
uSend[number*4+8]=3;
Num=(number*2)/16;
If(num>=10)uSend[6]=num+0x41-10;
Else uSend[6]=num+0x30;
Num=(number*2)%16;
If(num>=10)uSend[7]=num+0x41-10;
Else uSend[7]=num+0x30;
uAddress=0x1000+2*uAddress;
uTmp=uAddress&0x000f;
uSend[5]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uAddress>>4)&0x000f;
uSend=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uAddress>>8)&0x000f;
uSend=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uAddress>>12)&0x000f;
uSend=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
For(i=0;i
uTmp=uWrite_value[i]&0x000f;
uSend[i*4+9]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uWrite_value[i]>>4)&0x000f;
uSend[i*4+8]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uWrite_value[i]>>8)&0x000f;
uSend[i*4+11]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uWrite_value[i]>>12)&0x000f;
uSend[i*4+10]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
}
uSum=0;
For(i=1;i<9+number*4;i++)
uSum+=uSend[i];
uTmp=uSum&0x000f;
uSend[number*4+10]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uSum>>4)&0x000f;
uSend[number*4+9]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
For(i=0;i<11+number*4;i++)
{ for(lTmp=0L;lTmp
Break;
}
If(lTmp>=DELAY_TIMES)
{
/*enable();*/
Return(FALSE);
}
Outportb(DATA_PORT,uSend[i]);
}
Disable();
For(lTmp=0L;lTmp
Break;
}
If(lTmp>=DELAY_TIMES)
{
Enable();
Return(FALSE);
}
If(inportb(DATA_PORT)!=6)
{
Enable();
Return(FALSE);
}
Else
{
Enable();
Return(TRUE);
}
}
Int force_m_contact(unsigned uAddress,unsigned char ucOn_off)
{int i;
For(i=0;i<3;i++)
If(_force_m_contact(uAddress,ucOn_off)==TRUE)
Return TRUE;
Return FALSE;
}
Int _force_m_contact(unsigned uAddress,unsigned char ucOn_off)
{ unsigned uSend[]={2,0x37,0x30,0x30,0x30,0x30,3,0x30,0x30};
Unsigned uTmp, uSum, i;
Long lTmp;
If(TESTING==1)return TRUE;
Init_plc();
uAddress=uAddress+0x800;
uSend=ucOn_off;
uTmp=uAddress&0x000f;
uSend=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uAddress>>4)&0x000f;
uSend=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uAddress>>8)&0x000f;
uSend[5]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uAddress>>12)&0x000f;
uSend=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uSum=0;
For(i=1;i<7;i++)
uSum+=uSend[i];
uTmp=uSum&0x000f;
uSend[8]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uSum>>4)&0x000f;
uSend[7]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
For(i=0;i<9;i++)
{ for(lTmp=0L;lTmp
Break;
}
If(lTmp>=DELAY_TIMES)
{
Enable();
Return(FALSE);
}
Outportb(DATA_PORT,uSend[i]);
}
Disable();
For(lTmp=0L;lTmp
Break;
}
If(lTmp>=DELAY_TIMES)
{
Enable();
Return(FALSE);
}
If(inportb(DATA_PORT)!=6)
{
Enable();
Return(FALSE);
}
Else
{ enable();
Return(TRUE);
}
}
Int read_m_register(unsigned int uAddress,unsigned int number)
{int i;
For(i=0;i<3;i++)
If(_read_m_register(uAddress,number)==TRUE)
Return TRUE;
Return FALSE;
}
Int _read_m_register(unsigned int uAddress,unsigned int number)
{ unsigned char uSend[]={2,0x30,0x30,0x30,0x30,0x30,0x30,0x32,3,0x30,0x30};
Unsigned char uReceive[54];
Unsigned int uTmp;
Unsigned int uSum;
Unsigned int num;
Long lTmp;
Int i,j;
If(TESTING==1)
{ for(i=0;i
}
Init_plc();
Num=number;
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/8+0x100;
uTmp=uAddress & 0x000f;
uSend[5]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uAddress>>4) & 0x000f;
uSend=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uAddress>>8) & 0x000f;
uSend=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
uTmp=(uAddress>>12)&0x000f;
uSend=(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
Break;
}
If(lTmp>=DELAY_TIMES)
{
/*enable();*/
Return(FALSE);
}
Outportb(DATA_PORT,uSend[i]);
}
Disable();
For(lTmp=0;lTmp
Break;
}
If(lTmp>=DELAY_TIMES)
{
Enable();
Return(FALSE);
}
uReceive[0]=inportb(DATA_PORT);
If(uReceive[0]!=2)
{
Enable();
Return(FALSE);
}
For(i=1;i
Break;
}
If(lTmp>=DELAY_TIMES)
{
Enable();
Return(FALSE);
}
uReceive[i]=inportb(DATA_PORT);
}
Enable();
uSum=0;
For(i=1;i
uTmp=uSum&0xf;
uTmp=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
If((unsigned char)uTmp!=uReceive[number*2+3])return(FALSE);
uTmp=(uSum>>4)&0xf;
uTmp=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);
If((unsigned char)uTmp!=uReceive[number*2+2])return(FALSE);
For(j=0;j
uRead_value[j]=((uReceive[j*2+1])<<4)+uReceive[j*2+2];
}
Return TRUE;
}
Pharmaceuticals,2-Methyl- Propanoic Acid Monohydrate Price,2-Methyl- Propanoic Acid Monohydrate Free Sample,Pure 2-Methyl- Propanoic Acid Monohydrate
Zhejiang Wild Wind Pharmaceutical Co., Ltd. , https://www.wild-windchem.com