三菱plc用c语言写程序,三菱PLC编程口通信C语言源代码

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

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值