📄 cx.c
字号:
#include<bur/plc.h>
#include <bur/plctypes.h>
#include<can_lib.h>
_LOCAL CANopen_typ CANopen_01;
_LOCAL CANread_typ CANread_01;
_GLOBAL USINT data_read[8];
_GLOBAL UDINT error_var;
_LOCAL CANwrite_typ CANwrite_01;
_GLOBAL UINT V1;
_GLOBAL UINT V2;
_GLOBAL BOOL START1;
_GLOBAL BOOL STOP1;
_GLOBAL BOOL START2;
_GLOBAL BOOL STOP2;
_INIT void init()
{
CANopen_01.enable = 1; /* enable functionblock CANopen */
CANopen_01.baud_rate = 25; /* define baud rate - 250KB/s */
CANopen_01.cob_anz = 5; /* define number of communication objects */
CANopen_01.device = 0; /* define CAN device */
CANopen_01.info = 0; /* define CAN info */
CANopen(&CANopen_01); /* activate CANopen */
if (CANopen_01.status != 0)
error_var = 1;
V1 = 0;
V2 = 0;
START1 = 0;
START2 = 0;
STOP1 = 0;
STOP2 = 0;
}
_CYCLIC void cyclic ()
{
if(CANopen_01.status == 0) /* start CANread only if CANopen_01 had no error */
{ CANread_01.enable = 1; /* enable functionblock CANread */
CANread_01.us_ident = CANopen_01.us_ident; /* define Ident number for CANread */
CANread_01.can_id = 100; /* set can_id number for receiving */
CANread_01.data_adr = (UDINT) &data_read; /* define address where received data is saved to */
CANread(&CANread_01); /* activate CANread */
if(CANopen_01.status == 0) /* start CANwrite only if CANopen_01 had no error */
{ CANwrite_01.enable = 1; /* enable CANwrite */
CANwrite_01.us_ident = CANopen_01.us_ident; /* define Ident number for CANwrite */
CANwrite_01.can_id = 100; /* set can_id number for transmission */
CANwrite_01.data_adr = (UDINT) &(data[0]); /* define data to send */
CANwrite_01.data_lng = 8; /* define length of data */
CANwrite(&CANwrite_01); /* activate CANwrite */
if (CANread_01.status != 0) /* in case of an error in function CANread - */
error_var = 2; /* set error_var = 2 */
else
error_var = 3;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -