TCOM5. Примеры драйверов t11

  Драйвер для контроллера Ш711/1. TCOM5

  Драйвер для контроллера OMRON по протоколу HOSTLINK. TCOM5

Драйвер для контроллера Ш711/1. TCOM5

 

int first[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

int Prepare_xxx(int type,char *str,int &type_cnv,int &q_out)

{

strcpy(str,"SH-711-60");

return(0);

}

void Set_xxx(IA &ia, unsigned int &max_send, unsigned int &max_rec, int &q_rec, RSDATA *p,char *sbuf)

{

if (first[ia.c[0]]==0)

{

sbuf[0]=0x7c;

max_send=1;

max_rec=0;

first[ia.c[0]]=1;

}

else

{

sbuf[0]=0x67; //0x72 - 80

max_send=1;

max_rec=11+14*64;

}

return;

}

int Get_xxx(IA &ia,unsigned int &count_rec,int &q_rec,RSDATA *p,char *rbuf,int &type_cnv)

{

int i,h;

q_rec=64;

for (i=0;i<q_rec;i++)

p[i].F.fmt[1]=1;

i=11;

while(i<count_rec)

{

h=rbuf[i]-31+((rbuf[i+1]-35)/20)*15; // ch from S711

i+=2;

if (h<q_rec)

{

if ( (rbuf[i+1]<'0') || (rbuf[i+1]>'9') )

p[h].F.fmt[1]=1;

else

{

p[h].F.fmt[1]=0;

rbuf[i+7]=0;

p[h].V.v=(float)atof(rbuf+i);

}

}

i+=12;

}

type_cnv=3;

return(500);

}

int  Check_xxx(IA &ia,unsigned int &count_rec,unsigned int &max_rec,unsigned int &max_send,char *rbuf)

{

if (count_rec>11)

return(0);

else

{

max_rec=0;

max_send=0;

first[ia.c[0]]=0;

return(ERR_RT_RESP);

}

}

int  zCompare_xxx(IA &ia0,IA &ia1,int &count)

{

return(ia1.i[1]+1);

}

 

 

Драйвер для контроллера OMRON по протоколу HOSTLINK. TCOM5

 

int Prepare_xxx(int type,char *str,int &type_cnv,int &q_out)

{

strcpy(str,"Omron");

type_cnv=0;

return(0);

}

void Set_xxx(IA &ia,unsigned int &max_send,unsigned int &max_rec,int &q_rec,RSDATA *p,char *sbuf)

{

unsigned short int err;

int i;

sbuf[0]='@';

max_send=13;

sprintf(sbuf+1,"%.2d",ia.c[1]); //units

sprintf(sbuf+5,"%.4d",ia.i[1]);

switch(ia.c[4])

{

case 0: sbuf[4]='R'; break; //IR

case 1: sbuf[4]='H'; break;//HR

}

if (p[0].F.fmt[3]==1) // write

{

sbuf[3]='W';

if (p[0].F.fmt[0]==0)

sprintf(sbuf+9,"%.4x",(unsigned short int)p[0].V.v);

else

sprintf(sbuf+9,"%.4x",p[0].V.i[0]);

max_rec=11;

}

else // read

{

sbuf[3]='R';

sprintf(sbuf+9,"%.4d",q_rec+1);

max_rec=11+((q_rec+1)<<2);  

}

err=0;

for (i=0;i<max_send;i++)

err ^=sbuf[i];

sprintf(sbuf+max_send,"%.2x",err);

max_send+=2;

sbuf[max_send]='*';

max_send++;

sbuf[max_send]=13;

max_send++;

return; 

}

int Get_xxx(IA &ia,unsigned int &count_rec,int &q_rec,RSDATA *p,char *rbuf,int &type_cnv)

{

int i,j;

char good;

if ( p[0].F.fmt[3]==1) // out

{

p[0].F.fmt[1]=0;

return(0);

}

i=7;q_rec=-1;

while(i<count_rec)

{

good=rbuf[i+5]; rbuf[i+5]=0;

sscanf(rbuf+i,"%x",&j);

q_rec++;

p[q_rec].V.v=(float)j;

i+=4;

rbuf[i]=good;

}

type_cnv=0;

return(0);

}

int  Check_xxx(IA &ia,unsigned int &count_rec,unsigned int &max_rec,unsigned int &max_send,char *rbuf)

{

if ( count_rec < max_rec )

{

max_send=max_rec=0;

return(ERR_RT_TIMEOUT);

}

else

if ( (rbuf[5]!=48) || (rbuf[6]!=48) )

{

max_send=max_rec=0;

return(ERR_RT_RESP);

}

return(0);

}

int  zCompare_xxx(IA &ia0,IA &ia1,int &count)

{

if ( (count < 28) && (ia0.c[4]==ia1.c[4]) && (ia0.i[1]+count == ia1.i[1]) )

return(1);

else

return(0);

}