chinese国产hd中国熟女,青青草国产精品免费观看,亚洲日韩国产AV无码无码精品 ,欧美人成精品网站播放

0

購物車

客服

收藏

公眾號

公眾號

反饋

︿

頂部

首頁 > 工控資訊 > 產(chǎn)品資訊 >PLC>資訊詳情

三菱FX系列PLC編程口通信源代碼分享

2019-07-15 瀏覽量:143

點(diǎn)擊分享到微信
  三菱FX系列PLC編程口通信源代碼你會(huì)么?以上就是關(guān)于三菱FX系列PLC編程口通信源代碼分享。
三菱FX系列PLC編程口通信源代碼分享
  fx_comm.h

  #defineDELAY_TIMES30000L

  #defineTRUE1

  #defineFALSE0

  #defineTRUE1

  #defineFALSE0

  #defineFORCE_ON0x37

  #defineFORCE_OFF0x38

  voidinit_plc(void);

  intcheck_plc(void);

  int_read_data_register(unsignedintuAddress,unsignedintnumber);

  int_read_mdata_register(unsignedintuAddress,unsignedintnumber);

  int_write_data_register(unsignedintuAddress,unsignedintnumber);

  int_force_m_contact(unsignedintuAddress,unsignedcharucOn_off);

  intread_data_register(unsignedintuAddress,unsignedintnumber);

  intread_mdata_register(unsignedintuAddress,unsignedintnumber);

  intwrite_data_register(unsignedintuAddress,unsignedintnumber);

  intforce_m_contact(unsignedintuAddress,unsignedcharucOn_off);

  int_read_m_register(unsignedintuAddress,unsignedintnumber);

  intread_m_register(unsignedintuAddress,unsignedintnumber);

  intTESTING=0;

  unsignedintuRead_value[25];

  unsignedintuWrite_value[25];

  unsignedintCOMM_PORT=1;

  unsignedintSTATS_PORT=0x2fd;

  unsignedintDATA_PORT=0x2f8;

  voidinit_plc(void)

  {_AX=0xfa;

  _DX=COMM_PORT;

  geninterrupt(0x14);

  while((inportb(STATS_PORT)&1)!=0)inportb(DATA_PORT);

  }

  //返回頂部

  intcheck_plc(void)

  {longlTmp;

  if(TESTING==1)returnTRUE;

  init_plc();

  for(lTmp=0L;lTmp<DELAY_TIMES;lTmp++)

  {if((inportb(STATS_PORT)&0x20)!=0)

  break;

  }

  if(lTmp>=DELAY_TIMES)

  return(FALSE);

  outportb(DATA_PORT,5);

  disable();

  for(lTmp=0L;lTmp<DELAY_TIMES;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);

  }

  }

  //返回頂部

  intread_data_register(unsignedintuAddress,unsignedintnumber)

  {inti;

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

  if(_read_data_register(uAddress,number)==TRUE)

  returnTRUE;

  returnFALSE;

  }

  //返回頂部

  int_read_data_register(unsignedintuAddress,unsignedintnumber)

  {unsignedcharuSend[]={2,0x30,0x30,0x30,0x30,0x30,0x30,0x32,3,0x30,0x30};

  unsignedcharuReceive[104];

  unsignedintuTmp;

  unsignedintuSum;

  unsignedintnum;

  longlTmp;

  inti,j;

  if(TESTING==1)

  {for(i=0;i<number;i++)uRead_value[i]=0;

  returnTRUE;

  }

  init_plc();

  num=number*2;

  if((num/16)>=10)

  uSend[6]=(unsignedchar)(num/16+0x41-10);

  else

  uSend[6]=(unsignedchar)(num/16+0x30);

  if((num%16)>=10)

  uSend[7]=(unsignedchar)((num%16)+0x41-10);

  else

  uSend[7]=(unsignedchar)((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+(unsignedchar)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<DELAY_TIMES;lTmp++)

  {if((inportb(STATS_PORT)&0x20)!=0)

  break;

  }

  if(lTmp>=DELAY_TIMES)

  {

  return(FALSE);

  }

  outportb(DATA_PORT,uSend[i]);

  }

  disable();

  for(lTmp=0;lTmp<DELAY_TIMES;lTmp++)

  {if((inportb(STATS_PORT)&1)!=0)

  break;

  }

  if(lTmp>=DELAY_TIMES)

  {

  enable();

  return(FALSE);

  }

  uReceive[0]=inportb(DATA_PORT);

  if(uReceive[0]!=2)

  {

  enable();

  return(FALSE);

  }

  for(i=1;i<number*4+4;i++)

  {for(lTmp=0L;lTmp<DELAY_TIMES;lTmp++)

  {if((inportb(STATS_PORT)&1)!=0)

  break;

  }

  if(lTmp>=DELAY_TIMES)

  {

  enable();

  return(FALSE);

  }

  uReceive[i]=inportb(DATA_PORT);

  }

  enable();

  uSum=0;

  for(i=1;i<number*4+2;i++)

  uSum=uSum+(unsignedint)uReceive[i];

  uTmp=uSum&0xf;

  uTmp=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);

  if((unsignedchar)uTmp!=uReceive[number*4+3])return(FALSE);

  uTmp=(uSum>>4)&0xf;

  uTmp=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);

  if((unsignedchar)uTmp!=uReceive[number*4+2])return(FALSE);

  for(j=0;j<number;j++)

  {for(i=j*4+1;i<j*4+5;i++)

  uReceive[i]=(uReceive[i]>0x39)?uReceive[i]-0x41+0xa:uReceive[i]-0x30;

  uRead_value[j]=(((((uReceive[j*4+3]<<4)+uReceive[j*4+4])<<4)+uReceive[j*4+1])<<4)+uReceive[j*4+2];

  }

  returnTRUE;

  }

  //返回頂部

  intread_mdata_register(unsignedintuAddress,unsignedintnumber)

  {inti;

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

  if(_read_mdata_register(uAddress,number)==TRUE)

  returnTRUE;

  returnFALSE;

  }

  //返回頂部

  int_read_mdata_register(unsignedintuAddress,unsignedintnumber)

  {unsignedcharuSend[]={2,0x30,0x30,0x30,0x30,0x30,0x30,0x32,3,0x30,0x30};

  unsignedcharuReceive[104];

  unsignedintuTmp;

  unsignedintuSum;

  unsignedintnum;

  longlTmp;

  inti,j;

  if(TESTING==1)

  {for(i=0;i<number;i++)uRead_value[i]=0;

  returnTRUE;

  }

  init_plc();

  num=number*2;

  if((num/16)>=10)

  uSend[6]=(unsignedchar)(num/16+0x41-10);

  else

  uSend[6]=(unsignedchar)(num/16+0x30);

  if((num%16)>=10)

  uSend[7]=(unsignedchar)((num%16)+0x41-10);

  else

  uSend[7]=(unsignedchar)((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+(unsignedchar)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<DELAY_TIMES;lTmp++)

  {if((inportb(STATS_PORT)&0x20)!=0)

  break;

  }

  if(lTmp>=DELAY_TIMES)

  {

  return(FALSE);

  }

  outportb(DATA_PORT,uSend[i]);

  }

  disable();

  for(lTmp=0;lTmp<DELAY_TIMES;lTmp++)

  {if((inportb(STATS_PORT)&1)!=0)

  break;

  }

  if(lTmp>=DELAY_TIMES)

  {

  enable();

  return(FALSE);

  }

  uReceive[0]=inportb(DATA_PORT);

  if(uReceive[0]!=2)

  {

  enable();

  return(FALSE);

  }

  for(i=1;i<number*4+4;i++)

  {for(lTmp=0L;lTmp<DELAY_TIMES;lTmp++)

  {if((inportb(STATS_PORT)&1)!=0)

  break;

  }

  if(lTmp>=DELAY_TIMES)

  {

  enable();

  return(FALSE);

  }

  uReceive[i]=inportb(DATA_PORT);

  }

  enable();

  uSum=0;

  for(i=1;i<number*4+2;i++)

  uSum=uSum+(unsignedint)uReceive[i];

  uTmp=uSum&0xf;

  uTmp=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);

  if((unsignedchar)uTmp!=uReceive[number*4+3])return(FALSE);

  uTmp=(uSum>>4)&0xf;

  uTmp=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);

  if((unsignedchar)uTmp!=uReceive[number*4+2])return(FALSE);

  for(j=0;j<number;j++)

  {for(i=j*4+1;i<j*4+5;i++)

  uReceive[i]=(uReceive[i]>0x39)?uReceive[i]-0x41+0xa:uReceive[i]-0x30;

  uRead_value[j]=(((((uReceive[j*4+3]<<4)+uReceive[j*4+4])<<4)+uReceive[j*4+1])<<4)+uReceive[j*4+2];

  }

  returnTRUE;

  }

  //返回頂部

  intwrite_data_register(unsignedintuAddress,unsignedintnumber)

  {inti;

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

  if(_write_data_register(uAddress,number)==TRUE)

  returnTRUE;

  returnFALSE;

  }

  //返回頂部

  int_write_data_register(unsignedintuAddress,unsignedintnumber)

  {unsignedcharuSend[111];

  unsignedintuTmp,uSum,num;

  longlTmp;

  inti;

  if(TESTING==1)returnTRUE;

  init_plc();

  uSend[0]=2;

  uSend[1]=0x31;

  uSend[number*4+8]=3;

  num=(number*2)/16;

  if(num>=10)uSend[6]=num+0x41-10;

  elseuSend[6]=num+0x30;

  num=(number*2)%16;

  if(num>=10)uSend[7]=num+0x41-10;

  elseuSend[7]=num+0x30;

  uAddress=0x1000+2*uAddress;

  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);

  for(i=0;i<number;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<DELAY_TIMES;lTmp++)

  {if((inportb(STATS_PORT)&0x20)!=0)

  break;

  }

  if(lTmp>=DELAY_TIMES)

  {

  /*enable();*/

  return(FALSE);

  }

  outportb(DATA_PORT,uSend[i]);

  }

  disable();

  for(lTmp=0L;lTmp<DELAY_TIMES;lTmp++)

  {if((inportb(STATS_PORT)&1)!=0)

  break;

  }

  if(lTmp>=DELAY_TIMES)

  {

  enable();

  return(FALSE);

  }

  if(inportb(DATA_PORT)!=6)

  {

  enable();

  return(FALSE);

  }

  else

  {

  enable();

  return(TRUE);

  }

  }

  intforce_m_contact(unsigneduAddress,unsignedcharucOn_off)

  {inti;

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

  if(_force_m_contact(uAddress,ucOn_off)==TRUE)

  returnTRUE;

  returnFALSE;

  }

  //返回頂部

  int_force_m_contact(unsigneduAddress,unsignedcharucOn_off)

  {unsigneduSend[]={2,0x37,0x30,0x30,0x30,0x30,3,0x30,0x30};

  unsigneduTmp,uSum,i;

  longlTmp;

  if(TESTING==1)returnTRUE;

  init_plc();

  uAddress=uAddress+0x800;

  uSend[1]=ucOn_off;

  uTmp=uAddress&0x000f;

  uSend[3]=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);

  uTmp=(uAddress>>4)&0x000f;

  uSend[2]=(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[4]=(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<DELAY_TIMES;lTmp++)

  {if((inportb(STATS_PORT)&0x20)!=0)

  break;

  }

  if(lTmp>=DELAY_TIMES)

  {

  enable();

  return(FALSE);

  }

  outportb(DATA_PORT,uSend[i]);

  }

  disable();

  for(lTmp=0L;lTmp<DELAY_TIMES;lTmp++)

  {if((inportb(STATS_PORT)&1)!=0)

  break;

  }

  if(lTmp>=DELAY_TIMES)

  {

  enable();

  return(FALSE);

  }

  if(inportb(DATA_PORT)!=6)

  {

  enable();

  return(FALSE);

  }

  else

  {enable();

  return(TRUE);

  }

  }

  //返回頂部

  intread_m_register(unsignedintuAddress,unsignedintnumber)

  {inti;

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

  if(_read_m_register(uAddress,number)==TRUE)

  returnTRUE;

  returnFALSE;

  }

  //返回頂部

  int_read_m_register(unsignedintuAddress,unsignedintnumber)

  {unsignedcharuSend[]={2,0x30,0x30,0x30,0x30,0x30,0x30,0x32,3,0x30,0x30};

  unsignedcharuReceive[54];

  unsignedintuTmp;

  unsignedintuSum;

  unsignedintnum;

  longlTmp;

  inti,j;

  if(TESTING==1)

  {for(i=0;i<number;i++)uRead_value[i]=0;

  returnTRUE;

  }

  init_plc();

  num=number;

  if((num/16)>=10)

  uSend[6]=(unsignedchar)(num/16+0x41-10);

  else

  uSend[6]=(unsignedchar)(num/16+0x30);

  if((num%16)>=10)

  uSend[7]=(unsignedchar)((num%16)+0x41-10);

  else

  uSend[7]=(unsignedchar)((num%16)+0x30);

  uAddress=uAddress/8+0x100;

  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+(unsignedchar)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<DELAY_TIMES;lTmp++)

  {if((inportb(STATS_PORT)&0x20)!=0)

  break;

  }

  if(lTmp>=DELAY_TIMES)

  {

  /*enable();*/

  return(FALSE);

  }

  outportb(DATA_PORT,uSend[i]);

  }

  disable();

  for(lTmp=0;lTmp<DELAY_TIMES;lTmp++)

  {if((inportb(STATS_PORT)&1)!=0)

  break;

  }

  if(lTmp>=DELAY_TIMES)

  {

  enable();

  return(FALSE);

  }

  uReceive[0]=inportb(DATA_PORT);

  if(uReceive[0]!=2)

  {

  enable();

  return(FALSE);

  }

  for(i=1;i<number*2+4;i++)

  {for(lTmp=0L;lTmp<DELAY_TIMES;lTmp++)

  {if((inportb(STATS_PORT)&1)!=0)

  break;

  }

  if(lTmp>=DELAY_TIMES)

  {

  enable();

  return(FALSE);

  }

  uReceive[i]=inportb(DATA_PORT);

  }

  enable();

  uSum=0;

  for(i=1;i<number*2+2;i++)

  uSum=uSum+(unsignedint)uReceive[i];

  uTmp=uSum&0xf;

  uTmp=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);

  if((unsignedchar)uTmp!=uReceive[number*2+3])return(FALSE);

  uTmp=(uSum>>4)&0xf;

  uTmp=(uTmp<10)?(uTmp+0x30):(uTmp+0x41-0xa);

  if((unsignedchar)uTmp!=uReceive[number*2+2])return(FALSE);

  for(j=0;j<number;j++)

  {for(i=j*2+1;i<j*2+3;i++)

  uReceive[i]=(uReceive[i]>0x39)?uReceive[i]-0x41+0xa:uReceive[i]-0x30;

  uRead_value[j]=((uReceive[j*2+1])<<4)+uReceive[j*2+2];

  }

  returnTRUE;

  }

  //返回頂部

  更多PLC相關(guān)信息請?jiān)L問:易賣工控網(wǎng)(http://news.tpt0.cn)
文章圖片來源于網(wǎng)絡(luò)
免責(zé)聲明: 凡注明來源“易賣工控網(wǎng)”的所有作品,均為本站合法擁有版權(quán)或有權(quán)使用的作品,歡迎轉(zhuǎn)載,注明出處。非本站作品均來自互聯(lián)網(wǎng),轉(zhuǎn)載目的僅作為互聯(lián)網(wǎng)信息傳播之用,并不代表本網(wǎng)贊同其觀點(diǎn)和對其真實(shí)性、完整性、及時(shí)性不作任何保證或負(fù)責(zé)。

熱門產(chǎn)品資訊
最新產(chǎn)品資訊
相關(guān)資訊
產(chǎn)品推廣
為您推薦“PLC”相關(guān)產(chǎn)品