본문 바로가기
PLC

EasyBuilder Pro의 매크로

by 배굿맨 2022. 11. 15.

 

버튼을 누르면 PLC(STM32) 0x400013과 0x400011의 주소로 정수를 전송할 수 있다. 아래는 그 버튼의 등록정보이다.

 

이것을 매크로로 정의하려면 아래 절차를 따른다.

 

오브젝트중에서 세트비트(SetBit) 오브젝트를 클릭 한 후 속성을 편집한다.

 

세트비트의 설정화면에서 매크로>"매크로 실행"에 체크되어 있으며 매크로 id:001을 실행하도록 설정되어 있다.

 

아래는 매크로의 내용이다.

macro_command main()
short num1 = 3
short num2 = 1

SetData(num1,"MODBUS RTU",4x,13,1)
SetData(num2,"MODBUS RTU",4x,11,1)

end macro_command

 

매크로 해설

 

  • <short>

  • <4x>

이것을 이해하려면 Modbus를 조금 알아야 한다.

 

2022.11.17 - [PLC] - 모드버스(ModBus) 프로토콜(Protocol)

 

윗 글을 읽으면, 아래 EB Pro의 ModBus 주소 형식을 이해할 수 있을 것이다.

EasyBuilder Pro의 주소 형식

  • <SetData()>

[Description]
     Write data to a device and stop script execution if no response from this device.
[Usage]
     SetData(desti, PLC name, device type, address, data count)
[Example]
     char byData[10]
     short wData[6]

     FILL(byData[0], 0, 10) //  set buffers to a specified value
     FILL(wData[0], 0, 6)

     SetData(byData[0], "Local HMI", LW, 0, 10) //  send 10 bytes = 5 words
     SetData(wData[0], "Local HMI", LW, 0, 6) //  send 6 words
     SetData(wData[0], "Local HMI", "Pressure", 6 //  use user-defined tag - "Pressure" to indicate device type and

     address.

 

그리고 아래는 자주 사용하는 매크로 명령어를 적어 놓았다.

 

  • GetData() // address에 있는 값을 desti에 집어 넣는다.

 

[Description]
     Read data from a device.
[Usage]
     GetData(desti, PLC name, device type, address, data count)
[Example]
     char byData[10]
     short wData[6]

     GetData(byData[0], "Local HMI", LW, 0, 10) //  read 10 bytes = 5 words
     GetData(wData[0], "Local HMI", LW, 0, 6) //  read 6 words
     GetData(wData[0], "Local HMI", "Pressure", 6) //  use user-defined tag - "Pressure" to indicate device type and address.

 

  • SYNC_TRIG_MACRO() // 매크로를 실행한다.

 

[Description]
     This function will trigger the designated MACRO and wait for the end of the execution of this designated MACRO.
[Usage]
     SYNC_TRIG_MACRO(macro_id) //  macro_id is a constant or variable
     SYNC_TRIG_MACRO("macro_name") //  macro_name is a string
     
     SYNC_TRIG_MACRO(5) //  execute MACRO 5
     SYNC_TRIG_MACRO("check_status") //  if the name of macro 5 is "check_status", MACRO 5 will be triggered.

 

 

'PLC' 카테고리의 다른 글

PLC란?  (0) 2022.11.28
모드버스(ModBus) 프로토콜(Protocol)  (0) 2022.11.17
EasyBuilder Pro의 전역 화면전환 기능  (0) 2022.11.15
PLC의 COM(공통단자)의 의미  (3) 2022.11.14
WEINTEK HMI 화면 공유하기  (0) 2022.09.30