Habréã«ã¯ãASU TPã«é¢ããççŽãªèšäºã¯ã»ãšãã©ãããŸããã ããã«ãã»ãšãã©ã®ããããã¹ã¯åžæ°åãã®ç£æ¥ãªãŒãã¡ãŒã·ã§ã³æ¥çã§ã®ããã°ã©ãã³ã°ã¯ãå¥åŠãªäŒèª¬ãçãç©ãããéæ³ã®ãããªæã森ã ãšæããŸãã ã§ããããæè²ç®çã§ãã®æ£®ã®çããã¢ãŒãå®æœãããã£ãã®ã§ãããæè²ç®çã«éå®ããããšã¯ãããããã»ã¹å¶åŸ¡ã·ã¹ãã ã§äœæ¥ãå§ããã°ããã®äººãåé¡ã®çš®é¡ã®ã³ã³ãããŒã©ãŒã«æåã«åºäŒã£ã人ãã¡ã«ãã®è³æã圹ç«ãŠãããšããŸãã
ã ãããç¥ãåãã«ãªãã ããã¯ãSchneider ElectricïŒæ§Control MicrosystemsïŒã®SCADAPackãšåŒã°ããããã°ã©ããã«ããžãã¯ã³ã³ãããŒã©ãŒïŒPLCïŒã§ãã
ããã°ã©ããã«ããžãã¯ã³ã³ãããŒã©ãŒïŒPLCãšç¥èšãè±èªã®ããã°ã©ããã«ããžãã¯ã³ã³ãããŒã©ãŒãPLCãšç¥èšããã·ã¢èªãžã®ããæ£ç¢ºãªç¿»èš³ã¯ããã°ã©ããã«ããžãã¯ãåããã³ã³ãããŒã©ãŒïŒãããã°ã©ããã«ã³ã³ãããŒã©ãŒã¯æè¡ããã»ã¹ãèªååããããã«äœ¿çšãããç£æ¥çšã³ã³ãããŒã©ãŒã§ãã PLCã®äž»ãªåäœã¢ãŒãã¯ãæ·±å»ãªã¡ã³ããã³ã¹ãªãã§ãå®è³ªçã«äººéã®ä»å ¥ãªãã§ãå€ãã®å Žåãæªç°å¢äžã§ã®é·æçãªèªåŸäœ¿çšã§ãã [ãŠã£ãããã£ã¢]
ãããã®PLCã¯ããã®ä¿¡é Œæ§ãšè±å¯ãªããã°ã©ãã³ã°æ©èœã§å声ãåŸãŠããŸãã ã³ã³ãããŒã©ãŒã®å éšã«ã¯ãã·ãªãŒãºã«å¿ããŠãVxWorksãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ãå®è¡ããARMããã»ããµãŒããããŸãã
ç£æ¥ãªãŒãã¡ãŒã·ã§ã³ã§ã¯ãLD / LADãFDBãSTãªã©ã®IECèšèªãèªèãããŠããæšæºã§ãã ãããã®æåã®ãã®ã¯ããªã¬ãŒè«çåè·¯ã«äŒŒãåè·¯ã«ãããŸããã 2ã€ç®ã¯ãè«ççŽ åãšé»åéšåïŒã¿ã€ããŒãã«ãŠã³ã¿ãŒãªã©ïŒãåããåè·¯ã«äŒŒãåè·¯ã«ãããŸããã 3çªç®ã¯ããã¹ã«ã«ã®æãåºãåŒã³èµ·ããããã¹ãèšèªã§ãã ããããä»æ¥ã¯ãããã«ã€ããŠïŒãã€ã§ãã°ãŒã°ã«ã§æ€çŽ¢ã§ããïŒã«ã€ããŠã§ã¯ãªãããããã®ã³ã³ãããŒã©ãŒãCã§éçºããããšã«ã€ããŠèª¬æããŸãããŸãããåçŽãªããã°ã©ããŒãã«éåžžã«è¿ãã次ã«ãå¿ èŠã«å¿ããŠè€éãªæ°åŠèšç®ã®ããã°ã©ãã³ã°ãéæšæºã®éä¿¡ãããã³ã«ã®å®è£ ãç¯çŽããŸãã
ã³ã³ãã€ã«ã«ã¯ãå®éã«ã¯ã³ã³ãã€ã©ãããããŒãã¡ã€ã«ãããã³æšæºã³ã³ãããŒã©ãŒã©ã€ãã©ãªãå¿ èŠã§ãã ããã¯ãã¹ãŠã C Toolsãšãã補é å ã®Webãµã€ãã§èŠã€ããããšãã§ãã APIã®èª¬æãããã«ãããŸãã
éçºã¯ãMakefileïŒãœãŒã¹ãããã€ããªãã¡ã€ã«ã«ãããžã§ã¯ãããã«ãããããã®ã¹ã¯ãªããïŒã®äœæããå§ãŸããŸãã ãµã³ãã«ã®ã¡ã€ã¯ãã¡ã€ã«ã¯ãC Toolsãã£ã¬ã¯ããªã«ãããŸãã
C:\Program Files\Control Microsystems\CTools\Controller\Framework Applications\TelePACE
main.cppãšappstart.cppãã¡ã€ã«ã®äŸããããŸãïŒã¢ã»ã³ããªã«ãå¿ èŠã§ãïŒã
Ctools.h C:\Program Files\Control Microsystems\CTools\Controller\TelePACE
3ã€ã®äŸ¡å€ãããããšã«æ³šæããŠãã ããã
objects = appstart.o main.o
ãã®è¡ã¯ããã¡ãŒã ãŠã§ã¢ããã«ãããããã«ã©ã®ãã¡ã€ã«ãã³ã³ãã€ã«ããå¿ èŠãããããèšå®ããŸãã ãããžã§ã¯ããããããŒä»ãã®.cãŸãã¯.cppãã¡ã€ã«ïŒ.hãŸãã¯.hppãã¡ã€ã«ïŒã«åå²ãããŠããïŒããã³åå²ãããŠããå¿ èŠãããïŒå Žåããã®ã»ã¯ã·ã§ã³ã«ãªã¹ãããå¿ èŠããããŸãã çªç¶äœããå¿ãããšãã³ã³ãã€ã©ã¯æªå®çŸ©ã®åç §ãšã©ãŒã§ãããæãåºãããŸãã
CTOOLS_PATH = C:\Program Files\Control Microsystems\CTools
ãããCtoolsãžã®éã§ãã ç°ãªãå Žåã¯ä¿®æ£ããŠãã ããã
TARGET = SCADAPack350
ãã®è¡ã¯ããã¡ãŒã ãŠã§ã¢ãã³ã³ãã€ã«ããã³ã³ãããŒã©ãŒã®ãã¡ããªãŒã決å®ããŸãã å¯èœãªãªãã·ã§ã³ïŒ
SCADAPack350 ( 357, ..), SCADAPack33x, 4203
ãã¡ãŒã ãŠã§ã¢ã®ã³ã³ãã€ã«ã¯ãã³ãã³ãã©ã€ã³ãã
make
ã³ãã³ãã«ãã£ãŠå®è¡ãããŸãã
ãã®ã³ãã³ããèŠã€ãããªããšããã¡ãã»ãŒãžã衚瀺ãããå Žåã¯ãPATHã·ã¹ãã å€æ°ã«C-Toolsã©ã€ãã©ãªãžã®ãã¹ãããããšã確èªããŠãã ããã
C:\Program Files\Control Microsystems\CTools\Arm7\host\x86-win32\bin
ã·ã³ãã«ãªã¢ããªã±ãŒã·ã§ã³
ã·ã³ãã«ãªïŒãããŠç©ºã®ïŒãã¡ãŒã ãŠã§ã¢ãã³ã³ãã€ã«ããã«ã¯ã
Makefile
ãappstart.cppããã³main.cppãã¡ã€ã«ãå¿ èŠã§ãã
ãããã®äŸã¯ãäžèšã®åãC Toolsãã£ã¬ã¯ããªã«ãããŸãã Appstart.cppã¯ããŒããŠã§ã¢ãšã©ã³ã¿ã€ã ã®åæåãæ åœããmain.cppã§å¿ èŠãªã³ãŒããæ¢ã«èšè¿°ã§ããŸãã
SPã®Cããã°ã©ã ã®äžè¬çãªæ§é ã¯æ¬¡ã®ããã«ãªããŸãã
#include <ctools.h> #include "nvMemory.h" int main(void) { // - , , , , .. while (TRUE) { // release_processor(); } }
release_processorïŒïŒåŒã³åºãã¯åãµã€ã¯ã«ã§å¿ èŠã§ããããã¯ãããã°ã©ã ã«å ããŠãã³ã³ãããŒã©ãŒOSãä»ã®ãµãŒãã¹ããã»ã¹ïŒããŒãããã³ãããã³ã«ãã³ãã©ãŒãã©ã³ã¿ã€ã ãªã©ïŒãå®è¡ããããã§ãã ããšãã°ããã®é¢æ°ãåŒã³åºããªããšãããã°ã©ã ãèµ·åããåŸãããã°ã©ã ãåæ¢ããããã³ã³ãããŒã©ãŒãåãã©ãã·ã¥ãããããããšã¯ã§ããŸããã
æ²ããããªãC Toolsã®ã³ãŒãã£ã³ã°ã¹ã¿ã€ã«ã«ã¯å€ãã®èŠæããããŸãïŒé¢æ°ã®åœåã«ã¯ç°ãªãã¹ã¿ã€ã«ããããŸãïŒprocess_ioïŒïŒãšrelease_processorïŒïŒããããŸãããioReadDin16ïŒïŒãšaddRegAssignmentïŒïŒãããã³åæ§ã®é¢æ°ã§ã¯getclockïŒïŒ/ setclockïŒïŒïŒåãåŒæ°ã䜿çšãããšããããã®åãåŒæ°ã¯å ¥ãæ¿ãããŸããèŠããã«ã泚æããŠãã ããã
ä¿¡é Œæ§ã®é«ãçµã¿èŸŒã¿ã·ã¹ãã ãéçºããããã®äžè¬çãªãã³ãïŒã§ããã ãã·ã³ãã«ã§ç°¡åãªã³ãŒããèšè¿°ããéžæããã³ãŒãã£ã³ã°æšæºã«æºæ ããåå€æã«æ³šæããåçã¡ã¢ãªå²ãåœãŠãšãã€ã³ã¿ãŒæŒç®ãããŸãå¿ èŠãšããªãããã«ããŸãã
ã«ãŒã«ã®åºç€ãšããŠãMISRAæšæºïŒèªåè»ãã¡ãŒã ãŠã§ã¢éçºæšæºïŒãŸãã¯JSFïŒèªç©ºçšïŒã®åã ã®æ¡é ã䜿çšã§ããŸãã
ããã°ã©ã ãã³ã³ãããŒã©ãŒã«ããŠã³ããŒããã
ãã®ããã«ã¯TelePACEãå¿ èŠã§ãã RS232 / 485ãã€ãŒãµããããããã«ã¯USBïŒã¹ã«ãããã¯ã®äœ¿çšã¢ãã«ã«æèŒãããŠããå ŽåïŒãä»ããŠã³ã³ãããŒã©ãŒã«æ¥ç¶ã§ããŸãã
ååã¯ã»ãŒåãã§ãã
- [ãããã³ã«]ãã£ãŒã«ãã§ãå¿ èŠãªãããã³ã«ïŒModbus RTUãModbus TCPãŸãã¯Modbus USBïŒãéžæããŸã
- [èšå®ã®æ§æ]ãã¯ãªãã¯ããŠãå¿ èŠãªãã¹ãŠã®ããŒã¿ïŒRTUã¢ãã¬ã¹ãRS232 / 485ã®ããŒãé床ããŸãã¯TCPã®IPã¢ãã¬ã¹ïŒãèšå®ããŸãã
- [æ¥ç¶]ãã¯ãªãã¯ããã³ã³ãããŒã©ãŒã«æ¥ç¶ããŠãã ããã
- [åæå]ã¿ãã§ãã³ã³ãããŒã©ãŒãå ã®åœ¢åŒã«ãªã»ããã§ããŸãããã¹ãŠã®ããã°ã©ã ãLADãããžã§ã¯ããããŒãèšå®ãããã³ã¬ãžã¹ã¿ãŒå²ãåœãŠãåé€ããŸãã
- C / C ++ã¿ãã§ã¯ãããã°ã©ã ãã©ã®ããã«ã³ã³ãããŒã©ãŒã«ããŒããããããåæ¢/éå§ãæ°ãããã®ãããŒãããæ¹æ³ã確èªã§ããŸãïŒã¿ãäžéšã®ãã¿ã³ã調ã¹ãŠãã ããïŒïŒã
ã¡ãªã¿ã«ããŠã§ãäžã§ã¯ãããã»ã¹ã瀺ããããªããããŸããã
ã¿ã€ããŒãæäœãã
æãåçŽãªããã°ã©ã ã§ããHello Worldããå§ããŸããããã€ãŸããã³ã³ãããŒã©ãŒã®LEDãç¹æ» ãããŸãã
#include <ctools.h> #include "nvMemory.h" // ID . 10, primitiv.h #define TIMER1EVENT 10 int main(void) { int led_state = 0; // , 1 1 ( 0.1 ) startTimedEvent(TIMER1EVENT,10); while (TRUE) { // , if (poll_event(TIMER1EVENT)) { if (led_state == 0) ledPower(LED_ON); else ledPower(LED_OFF); led_state = led_state ^ 1; } release_processor(); } }
modbusã¬ãžã¹ã¿ãŒã®æäœ
Modbusã¯ããã¹ã¿ãŒã¹ã¬ãŒãã¢ãŒããã¯ãã£ã«åºã¥ããªãŒãã³ãªéä¿¡ãããã³ã«ã§ãã é»åæ©åšéã®éä¿¡ãæŽçããããã«æ¥çã§åºã䜿çšãããŠããŸãã ã·ãªã¢ã«éä¿¡ã©ã€ã³RS-485ãRS-422ãRS-232ãããã³TCP / IPãããã¯ãŒã¯ïŒModbus TCPïŒãä»ããããŒã¿äŒéã«äœ¿çšã§ããŸãã UDPã䜿çšããéæšæºã®å®è£ ãå©çšã§ããŸãã ãã®èŠæ Œã®äž»ãªå©ç¹ã¯ãéæŸæ§ãšãã¹ãã£ã©ã¯ã¿ãŒã§ãã æ¥çã¯çŸåšãã»ã³ãµãŒãã¢ã¯ãã¥ãšãŒã¿ãä¿¡å·åŠçããã³æ£èŠåã¢ãžã¥ãŒã«ãªã©ã®å€ãã®ã¿ã€ããšã¢ãã«ãçç£ããŠããŸããã»ãšãã©ãã¹ãŠã®ç£æ¥çšç£èŠããã³å¶åŸ¡ã·ã¹ãã ã«ã¯ãMODBUSãããã¯ãŒã¯ã§åäœãããœãããŠã§ã¢ãã©ã€ããŒããããŸãã [ãŠã£ãããã£ã¢]
SCADAPackã§ã¯ãModbusãšã®é£æºãçŸãã䟿å©ã«å®è£ ãããŠããŸãã
ã³ã³ãããŒã©ã®modbusã¬ãžã¹ã¿ã®ã¡ã¢ãªã¯äžæ®çºæ§ã§ãããåèµ·åãŸãã¯é»æºé害ãçºçããŠã倱ãããŸããã äžæ¹ã§ãããã¯å°ãäžäŸ¿ã§ãïŒå¿ èŠã«å¿ããŠãèµ·åæã«ã¬ãžã¹ã¿ãã¯ãªã¢ãŸãã¯åæåããããšãå¿ããªãã§ãã ããïŒããäžæ¹ã§ãããã«ãããèšå®ãèšå®ãããã«ã¯å°ããªã¢ãŒã«ã€ããmodbusã¢ãã¬ã¹ç©ºéã«ä¿åããããšãã§ããŸãã
ããã«ãããŸããŸãªã³ãã³ãã®çµæïŒãã£ã¹ã¯ãªãŒãããã³ã¢ããã°å ¥åã®ã¹ããŒã¿ã¹ã®èªã¿åããå€éšããã€ã¹ã®ããŒãªã³ã°ãªã©ïŒãmodbusã¬ãžã¹ã¿ã«é 眮ãããŸãã
ããã¯ã¢ããããã±ãŒãžã®modbusããã»ããµã¯ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã¬ãã«ã§å®è£ ãããŠãããããããã°ã©ã ãéå§ããåŸããã¹ãŠã®COMããŒãïŒããã³ã€ãŒãµãããïŒã«ã€ããŠãããã«modbassã§ã³ã³ãããŒã©ãŒã«åãåãããããšãã§ããŸãïŒããŒãèšå®ã«ã€ããŠã¯å°ãåŸã§èª¬æããŸãïŒã ããã«ãããã°ã©ã ãåæ¢ããŠããŠããã³ã³ãããŒã©ãŒã¯modbusèŠæ±ã«å¿çããŸãã
modbusã¬ãžã¹ã¿ã®æžã蟌ã¿ãšèªã¿åãã¯ãããšãã°æ¬¡ã®ããã«ãdbaseïŒïŒããã³setdbaseïŒïŒé¢æ°ã«ãã£ãŠè¡ãããŸãã
request_resource(IO_SYSTEM); a = dbase(MODBUS, 30001); b = dbase(MODBUS, 30002); setdbase(MODBUS, 40020, a * b); release_resource(IO_SYSTEM);
ãã®äŸã§ã¯ãå ¥åãŸãŒã³ã®0001ããã³0002ã¬ãžã¹ã¿ãã2ã€ã®æ°å€ãèªã¿åãããããã®ä¹ç®çµæãä¿æãŸãŒã³ã®0020ã¬ãžã¹ã¿ã«æ ŒçŽããŸãã ãã¹ãŠãã·ã³ãã«ã§ãã
I / Oä¿¡å·ãæäœãã
å ¥åã¢ãžã¥ãŒã«ãšåºåã¢ãžã¥ãŒã«ãæäœããã«ã¯ã3ã€ã®æ¹æ³ããããŸãã
æåã®æ¹æ³
æåã®ãªãã·ã§ã³ã¯ããã¬ãžã¹ã¿å²ãåœãŠããäœæããããšã§ãã DINããã³AINã¢ãžã¥ãŒã«ã®å ¥åãã£ã³ãã«ã®ç¶æ ïŒé¢æ£ããã³ã¢ããã°å€ïŒã¯modbusã¬ãžã¹ã¿ã«èªåçã«ããããã³ã°ããããéããŸãåæ§ã«ãDOUTããã³AOUTã¢ãžã¥ãŒã«ã®å Žåãåºåã®ç¶æ ã¯ã¬ãžã¹ã¿ã«èšé²ãããå€ã«ãã£ãŠæ±ºå®ãããŸãã ãããè¡ãã«ã¯ãclearRegAssignmnetïŒãã¹ãŠã®å€ãå²ãåœãŠãã¯ãªã¢ïŒããã³addRegAssignmentïŒæ°èŠäœæïŒé¢æ°ã䜿çšãããŸãã
addRegAssignmenté¢æ°ã®æåã®åŒæ°ã¯ã¢ãžã¥ãŒã«ã®ã¿ã€ãã§ãïŒå®æ°ã®ãªã¹ãã¯TelePACEã®ããã¥ã¡ã³ããšããããŒãã¡ã€ã«ã«ãããŸããDIN_5401ãDIN_5404ãAIN_5301ãªã©ããããŸãïŒã2çªç®ã¯ã¢ãžã¥ãŒã«ã®ã¢ãã¬ã¹ã§ãïŒéåžžã¯ã¢ãžã¥ãŒã«èªäœã®ãžã£ã³ããŒã§æå®ãããçµã¿èŸŒã¿ã®å Žåã¯SPå ¥åãããã¯0ã«çããïŒããããŠèšé²ãè¡ãããã¹ãã¬ãžã¹ã¿ã®ã¢ãã¬ã¹ããããŸãïŒã¢ãžã¥ãŒã«ãç°ãªãã¿ã€ãã®ããŒã¿ãæäŸããå Žåãã¬ãžã¹ã¿ã®ããã€ãã®ã°ã«ãŒãããããŸã-ã³ã€ã«ãã¹ããŒã¿ã¹ãå ¥åãªã©ïŒ
// IO_SYSTEM // - modbus- request_resource(IO_SYSTEM); // assignments clearRegAssignment(); // IO 5601 10001 30001 // DOUT 1 (00001) addRegAssignment(SCADAPack_lowerIO, 0, 1, 10001, 30001, 0); // , SCADAPack_upperIO - ( ) // 5604: // , AOUT, 40001 // addRegAssignment(SCADAPack_5604IO, 0, 1, 10001, 30001, 40001 ); // AOUT ( 1): // , modbus 40001 addRegAssignment(SCADAPack_AOUT, 1, 40001, 0, 0, 0); // IO_SYSTEM release_resource(IO_SYSTEM);
ã©ã³ã¿ã€ã ã匷å¶çã«åæ¢ãããšïŒrunTargetïŒFALSEïŒïŒãåäœããªããªããŸãããæé©åã®ããã«æšæºã®appstart.cãã¡ã€ã«ã«å€æŽãå ããªãã£ãå Žåãå¿é ããããšã¯ãããŸããã
clearRegAssignmentïŒïŒãå¿ããã«å®è¡ããŠãã ããã ããªãããããã䜿çšããªããŠããããªããããã°ã©ã ãéå§ãããšã-誰ãããªãã®åã«ãã®ã³ã³ãããŒã©ãŒã§èª°ãäœãããããç¥ã£ãŠããŸãã
ãã¡ãŒã ãŠã§ã¢ãèµ·åããã³ã³ãããŒã©ãŒã«ã©ã®I / OããŒãããããæ£ç¢ºã«ããããªãå Žåã¯ã OZNAã¹ãã·ã£ãªã¹ããææ¡ãããœãªã¥ãŒã·ã§ã³ã䜿çšã§ããŸãã
第äºã®æ¹æ³
æå®ãããmodbusã¬ãžã¹ã¿ã«ããŒã¿ãä¿åããé¢æ°ãæ瀺çã«èªã¿åããŸãã
é¢æ°ioRead8DinãioRead8AinãioRead16DinãioRead16AinãioRead5604InputsãioWrite16DoutãioWrite5604OutputsãioRead4CounterïŒå ¥åã®ã«ãŠã³ãçšïŒãioReadSP2ïŒã³ã³ãããŒã©ãŒã®çµã¿èŸŒã¿å ¥åã®èªã¿åãçšïŒã䜿çšã§ããŸãã ãããã®ã³ãã³ãã®è©³çŽ°ãšæ§æã¯ãC Toolsã®ããã¥ã¡ã³ãã«èšèŒãããŠããŸããéåžžãæåã®åŒæ°ã¯ã¢ãžã¥ãŒã«ã®ã¢ãã¬ã¹ïŒçµã¿èŸŒã¿å ¥åã®å Žåã¯0ïŒã2çªç®ãš2çªç®ã¯modbusã¬ãžã¹ã¿ã®ã¢ãã¬ã¹ã§ãããããããä¿¡å·å€ãä¿åããå¿ èŠãããïŒãŸãã¯æžã蟌ã¿ã®ããã«ããããååŸããå ŽæïŒé±æ«ã®ãã£ã³ãã«ãžïŒã
äŸïŒ
// 5607 (0, .. ) int Module5607Addr = 0; // IO_SYSTEM request_resource(IO_SYSTEM); // ioRequest(MT_5607Inputs, Module5607Addr); ioRequest(MT_SP2Inputs, 0); // // , ( wait_event poll_event) ioNotification(IO_COMPLETE); wait_event(IO_COMPLETE); // 5607, â 10001, â 30001 ioRead5607Inputs(Module5607Addr, 10001, 30001); // , â 10101, â 30101 ioReadSP2Inputs(10101,30101); // IO_SYSTEM release_resource(IO_SYSTEM);
ioWrite *é¢æ°ãåŒã³åºããšãåæ§ã«å¿ èŠãªå€ãmodbusã¬ãžã¹ã¿ãŒããã³ã³ãããŒã©ãŒãšã¢ãžã¥ãŒã«ã®åºåãã£ã³ãã«ã«èšå®ãããŸãã
第äžã®æ¹æ³
åãã§ãããçµæãmodbusã¬ãžã¹ã¿ã§ã¯ãªãå€æ°ãŸãã¯é åã«ä¿åããŸãã é¢æ°ãåãããã«åŒã³åºãããŸãããä»ã®åŒæ°ã䜿çšããå®è£ ããªãŒããŒããŒããããŠããŸãã
int Module5607Addr = 0; // IO_SYSTEM, - request_resource(IO_SYSTEM); // , 5607 UCHAR DIData [3]; // , 5607 INT16 AIData [8]; // UCHAR DIData2 [2]; // INT16 AIData2 [8]; // ioRequest(MT_5607Inputs, Module5607Addr); ioRequest(MT_SP2Inputs, 0); // // , ( wait_event poll_event) ioNotification(IO_COMPLETE); wait_event(IO_COMPLETE); // ioRead5607Inputs(Module5607Addr,DIData,AIData); ioReadSP2Inputs(DIData2,AIData2); release_resource(IO_SYSTEM);
åæ§ã®ããšããåºåãã£ãã«ã«æžã蟌ãããŒã¿ã§å®è¡ã§ããŸãïŒããšãã°ããªã¬ãŒåºåãéããŸãïŒã
UINT16 InputType[8]; for(int i=0;i < 8; i++) InputType[i] = 3; UINT16 InputFilter = 3; UINT16 ScanFrequency = 0; UINT16 OutputType = 1; UINT16 Mask2 = 0; ioWrite5607Outputs(Module5607Addr,DOData,AOData,InputType,InputFilter,ScanFrequency,OutputType); ioRequest(MT_5607Outputs, Module5607Addr);
䜿çšãããã¢ãžã¥ãŒã«ã®ããŒã¿ãèªã¿æžãããããã®ç¹å®ã®é¢æ°ãšå®æ°ã«ã€ããŠã¯ãããã¥ã¡ã³ããšC ToolsããããŒãã¡ã€ã«ãåç §ããŠãã ããã ããšãã°ã5607ã¢ãžã¥ãŒã«ã®æ©èœã«ã¯ãäžèšã®ããã«ãå ¥åã¿ã€ãããã£ã«ã¿ãŒãã©ã¡ãŒã¿ãŒãªã©ãèšå®ããããã®è¿œå ãªãã·ã§ã³ããããŸãã ãããã¯ããã¥ã¡ã³ãã«ãèšèŒãããŠããŸãã
çŸåšã®ã³ã³ãããŒã©ãŒã®æž©åºŠãšããããªãŒé»å§ãååŸããé¢æ°ããããŸã-readThermistorïŒT_CELSIUSïŒãreadBatteryïŒïŒã äºçŽ°ãªããšã§ããã䟿å©ã§ãã
AIã¹ã±ãŒãªã³ã°
ã³ã³ãããŒã©ã¢ãžã¥ãŒã«ã®ã¢ããã°å ¥åãã£ã³ãã«ã¯ãããŸããŸãªã¢ãŒãã§åäœã§ããŸãïŒããšãã°ãå ¥åç¯å²ã0ã20ãŸãã¯4ã20 mAã®å Žåãããã¯ã¢ãžã¥ãŒã«ã®ãžã£ã³ãã«ãã£ãŠæ±ºå®ãããŸãïŒã ãããã¯ããŒã¿ãADCåäœã§æäŸããããããå¿ èŠãªã¹ã±ãŒã«ã«å€æããŸãïŒããšãã°ã4-20 mAã¯0-100ïŒ ã«å¯Ÿå¿ããŸãïŒïŒ
// , AI, #define AIWaterLevelReg 30001 float WaterLevelScaled = ((float)dbase(MODBUS, AIWaterLevelReg) - 6554) / 26214 * 100; // 4-20 // float WaterLevelScaled = (float)dbase(MODBUS, AIWaterLevelReg) / 32767 * 100; // 0-20
åœç¶ã100ã®ä»£ããã«ãå¿ èŠãªã¹ã±ãŒã«ã®äžéãæ°å€ã«æããããšãã§ããŸãã
RS-232 / RS-485ããŒãã®æ§æ
ããã§ããéæ³ã¯ãããŸããïŒ
PROTOCOL_SETTINGS comsettings; pconfig portSettings; // COM2, getProtocolSettings(com2, &comsettings); // modbus-, comsettings.station = 1; comsettings.type = MODBUS_RTU; comsettings.mode = AM_standard; get_port(com2,&portSettings); // , 38400 portSettings.baud = BAUD38400; portSettings.duplex = HALF; portSettings.parity = PARITY_NONE; portSettings.data_bits = DATA8; portSettings.stop_bits = STOP1; portSettings.flow_tx = TFC_NONE; portSettings.flow_rx = RFC_MODBUS_RTU; portSettings.type = RS232; setProtocolSettings(com2, &comsettings); set_port(com2,&portSettings);
ããŒãèšå®ã¯EEPROMã«ä¿åãããŸãããã³ã³ãããŒã©ãŒã®æ§æãã©ã€ãã©ãªã®ããŒãžã§ã³ãªã©ã«å¿ããŠãããšãã°ç¹å®ã®ã€ãã³ãïŒã³ãã³ãããžã£ã³ããŒã¯ããŒãžã£ãªã©ïŒã®åãmodbusã¬ãžã¹ã¿ããèªã¿åããèªåçã«åæ§æããããããæŽæ°ããŸãã
Modbusã§ã®ããŒãªã³ã°ããã€ã¹
ã¹ã¬ãŒãããã€ã¹ãšããŠåäœããã ãã§ãªããä»ã®ã³ã³ãããŒã©ãŒãã»ã³ãµãŒã«èªåã§åãåããããå Žåã¯ãmodbassã§å€éšããã€ã¹ãããŒãªã³ã°ããçµæãã¬ãžã¹ã¿ã«ä¿åããŠãããããèªã¿åã£ãŠäœ¿çšã§ããããã«ããmaster_messageïŒïŒãšãã圢åŒã®é¢æ°ããããŸãã¢ã«ãŽãªãºã ã§ïŒãŸãã¯åã«äžäœã¬ãã«ãæäŸããïŒã ããã¥ã¡ã³ãã«ã¯äŸããããŸããã2ã€ã®ãã¥ã¢ã³ã¹ãèæ ®ããŠãã ããïŒ2çªç®ã®ãªã¯ãšã¹ããéä¿¡ããããåä¿¡ããããŒã¿ãæäœããåã«get_protocol_statusïŒïŒã³ãã³ãã§é¢æ°å®è¡ã®çµæã確èªããå¿ èŠãããã2çªç®ã®ãã¥ã¢ã³ã¹ïŒäœ¿çšããããŒãã§modbusããã»ããµããªãã«ãããããã®ã¢ãã¬ã¹ãããŒãªã³ã°ãããããã€ã¹ã®ã¢ãã¬ã¹ãšäžèŽããªãããã«ããŸãïŒããããªããšãæªå®çŸ©ã®åäœãå¥åŠãªãšã©ãŒãçºçããå¯èœæ§ããããŸãïŒã
extern unsigned master_message(FILE * stream, unsigned function, unsigned slave_station, unsigned slave_address, unsigned master_address, unsigned length);
streamã¯ããŒã¿ã®äº€æã«äœ¿çšãããããŒãïŒcom1ãªã©ïŒãfunctionã¯ãªã¯ãšã¹ãã®modbusæ©èœçªå·ïŒ3ãªã©ïŒãslave_stationã¯ããŒãªã³ã°ãããããã€ã¹ã®RTUã¢ãã¬ã¹ãslave_addressã¯èªã¿åããããªã¢ãŒãããã€ã¹ã®ã¬ãžã¹ã¿ã®éå§ã¢ãã¬ã¹ãmaster_address -ããŒã¿ãæžã蟌ãŸããã³ã³ãããŒã©ãŒã®ã¬ãžã¹ã¿ãŒã®éå§ã¢ãã¬ã¹ãé·ã-èªã¿åãã¬ãžã¹ã¿ãŒã®æ°ïŒã
äŸïŒ
request_resource(IO_SYSTEM); // com2 3- modbus- ( Holding ) 1 0001 (40001) 17 , 513 master_message(com2, 3, 1, 40001, 40513, 17); // struct prot_status polling_status; polling_status = get_protocol_status( com2); if (polling_status.command == MM_SENT) { // , . // , , } else if (polling_status.command == MM_RECEIVED) { // , ! // } else { // - . } release_resource(IO_SYSTEM);
ç¬èªã®Modbusãã±ãããã³ãã©ãŒïŒinstallModbusHandlerïŒïŒïŒãã€ã³ã¹ããŒã«ããŠããããã³ã«æ¡åŒµæ©èœãå®è£ ããããšãã§ããŸãã
ã·ã¹ãã ã¯ã亀æã®çµ±èšïŒåä¿¡/éä¿¡ããšã©ãŒæ°ãªã©ïŒãä¿æããŸããããã¯ã察å¿ããæ§é ããèªã¿åãããšãã§ããŸãã
ã³ãã¥ãã±ãŒã·ã§ã³ãº
COMããŒãçµç±ã§åä¿¡ããããŒã¿ã®ç¬èªã®ãã³ãã©ãŒïŒinstall_handleïŒïŒïŒãã€ã³ã¹ããŒã«ããŠãããã€ãã®éæšæºãããã³ã«ãå®è£ ããããšãã§ããŸãã
TCP / IPã§ã¯ããã¹ãŠãããŸããããŸãã BSDãœã±ããã®æšæºæ©èœãå©çšå¯èœã§ãïŒbindïŒïŒãgetsockoptïŒïŒãªã©ã ã³ã³ãããŒã©ã®ãããã¯ãŒã¯èšå®ã¯ãããã°ã©ã ã§èªã¿æžãã§ããŸãïŒethernetGetIPïŒïŒãethernetSetIPïŒïŒïŒã
ã¢ãŒã«ã€ã
ãããã®ç®çã®ããã®SCADAPackããã¥ã¡ã³ãã§ã¯ãC Toolsã©ã€ãã©ãªã®DataLogã䜿çšããããšãææ¡ãããŠããŸãããæ®å¿µãªãããå€ãã®æ¬ ç¹ããããŸãããã®äž»ãªçç±ã¯ãã¢ãŒã«ã€ããšã³ããªãžã®çŽæ¥ã®äžè²«æ§ã®ãªãã¢ã¯ã»ã¹ãæäŸããªãããšã§ãã äžéšã®éçºè ã¯ã¢ãŒã«ââã€ããã¬ãžã¹ã¿ã¡ã¢ãªã«çŽæ¥ä¿åããããšãã§ããŸãããã³ã³ãããŒã©ãŒã®ä¿ææ°ãšå ¥åæ°ïŒå¿ èŠã«å¿ããŠäœ¿çšããããšãã§ããŸãïŒãéãããŠããããšãèæ ®ãããšããã®ãœãªã¥ãŒã·ã§ã³ãåžžã«æ©èœãããšã¯éããŸããã
å®éãã³ã³ãããŒã©ãŒã®ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã¯éåžžã«POSIXäºæã§ãããã³ã³ãããŒã©ãŒèªäœãããŒãäžã«å®å šã«éåžžã®ãã¡ã€ã«ã·ã¹ãã ãæèŒããŠããããïŒããã«ãUSBãã©ãã·ã¥ãã©ã€ããæ¿å ¥ãããªãã·ã§ã³ããããŸãïŒãããŒãäžã®ãã©ãã·ã¥ãã©ã€ãäžã®ãã¡ã€ã«ã«ã¢ãŒã«ã€ããä¿åã§ããŸãã³ã³ãããŒã©ãŒã¯ãããã¥ã¡ã³ãã§éåžžã«ç°¡åã«èšåãããŠããŸããã
Cããã°ã©ã ãšåæ§ã«ãã¡ã€ã«ãæäœã§ããŸãã
FILE *mdata; char* file_mdata = "/d0/logs.dat"; mdata = fopen(file_mdata, "w"); fputs("test log string", mdata); fclose(mdata);
ã€ãŸããïŒãªãã·ã§ã³ãšããŠ-åšæçãªã¢ãŒã«ã€ããä¿æããïŒã·ãªã¢ã«åãããæ§é ããã¡ã€ã«ã«æžã蟌ã¿ã次ã«èªç±ã«ããã²ãŒãããã¢ãŒã«ã€ãã®ç¹å®ã®éšåãmodbusã¬ãžã¹ã¿ãŒã®ã¹ããŒã¹ã«ãããã³ã°ãããããŠãŒã¶ãŒïŒã«ã¹ã¿ã ïŒmodbusã«äžããããšã«ããããŠãŒã¶ãŒã«æäŸããã®ã«é害ã¯ãããŸãã倧ããªãããã¯ã§æ©èœããŸãã
ãã¡ã€ã«ã·ã¹ãã ã¯ãã€ã³ã/ d0 /ã«ããŠã³ããããå€éšUSBãã©ãã·ã¥ãã©ã€ãã¯/ bd0 /ã«ããŠã³ããããŸããç¹°ãè¿ãã«ãªããŸãããã³ã³ãããŒã©ã®ãã¿ã³ãã¯ãªãã¯ãããšãã«ãå èµã¡ã¢ãªããUSBãã©ãã·ã¥ãã©ã€ãã«ã¢ãŒã«ã€ããã³ããŒããããšãããã³ä»ã®å€ãã®ãªãã·ã§ã³ãå®è£ ããŠãåé¡ã¯ãããŸããã
TelePACEã§ã¯ããã¡ã€ã«ã·ã¹ãã ã¯éåžžã«ç©ããã«è¡šç€ºããããããã°ãããŒã¿åéã«åœ¹ç«ã¡ãŸãã
äžæ®çºæ§ã¡ã¢ãª
ãã§ã«è¿°ã¹ãããã«ãäžæ®çºæ§ã¡ã¢ãªã«ã¯ããŸãModbusã¬ãžã¹ã¿ã®ããŒã¿ãä¿åãããŸããã€ãŸããä¿åãããå€ã¯ãã³ã³ãããŒã©ãåèµ·åãããåŸã§ã䜿çšå¯èœã«ãªããŸãã
ããã«ãnvMemory.hãã¡ã€ã«ã§å®£èšãããæ倧ãµã€ãº8ãããã€ãã®å¥ã®s_nvMemoryæ§é ããããå¿ èŠã«å¿ããŠïŒå¿ èŠãªãã£ãŒã«ããäœæããããšã«ããïŒç·šéããåé»ãåèµ·ååŸãäžè²«æ§ãä¿ã€å¿ èŠãããããŒã¿ãä¿åã§ããŸãã³ã³ãããŒã©ãŒãããã§ååã§ãªãå Žåãããã«allocateMemoryïŒïŒã¡ãœããã¯ãåèšãµã€ãºãæ倧1ã¡ã¬ãã€ãã®äžæ®çºæ§ã¡ã¢ãªãããã¯ãå²ãåœãŠãŠãã¢ãŒã«ã€ãããã°ãªã©ãä¿åã§ããŸãããã®å Žåã®æãéèŠãªããšã¯ãã¡ã¢ãªãããã¯ãå²ãåœãŠãåŸãåè¿°ã®s_nvMemoryæ§é äœã«ãã€ã³ã¿ãä¿åããããšãå¿ããªãã§ãã ãããããããªããšãå²ãåœãŠãããã¡ã¢ãªã倱ããã䜿çšãŸãã¯è§£æŸã§ããªããªããŸãïŒfreeMemoryïŒïŒïŒããŸããäžæ®çºæ§ã¡ã¢ãªã«ã¢ã¯ã»ã¹ãããšãã¯ãDYNAMIC_MEMORYãªãœãŒã¹ãååŸããããšãå¿ããªãã§ãã ããã
ãã«ãã¿ã¹ã¯ãšãã«ãããã»ãã·ã³ã°
è€æ°ã®ç°ãªãããã°ã©ã ãåæã«å®è¡ããããè€æ°ã®ç°ãªãã¡ãœãããåæã«å®è¡ãããïŒcreateTaskïŒïŒãgetTaskInfoïŒïŒé¢æ°ãªã©ïŒããããã®åªå é äœãèšå®ããããããã»ã¹éã§ã¿ã¹ã¯ãšã¡ãã»ãŒãžéã§ã·ã°ãã«ãéä¿¡ãããããããšãã§ããŸããå°çãïŒã
ãã«ãã¿ã¹ã¯ã¯å調çã§ããã€ãŸããã¿ã¹ã¯ãšããã°ã©ã ã®åãæ¿ãã¯ããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã«ãã匷å¶ã§ã¯ãªããå®è¡ãããã«è»¢éããæºåãã§ãããšãããŸãã¯ç¹å®ã®ã€ãã³ããçºçãããšãã«äº€äºã«å®è¡ãããŸããäžæ¹ã§ãããã¯ããŒã¿ãå ±æãããšãã®æäœã®ååæ§ã®åé¡ã解決ããŸããä»æ¹ã§ãrelease_processorïŒïŒãåŒã³åºããŠããªãœãŒã¹ãé·ãååŸããªãããšãå¿ããªãã§ãã ããããã«ãã¿ã¹ã¯ããã°ã©ã ã®äŸãšãã€ãã³ãçºçæã®ç¶æ å€åã®ã°ã©ãã¯ããRTOSãµã³ãã«ã¢ããªã±ãŒã·ã§ã³ããã°ã©ã ãããã³ãã¿ã¹ã¯å®è¡ã®èª¬æãã®ç« ã®ããã¥ã¡ã³ãã«èšèŒãããŠããŸãã
åçã¡ã¢ãª
mallocïŒïŒããã³freeïŒïŒã¯ãnewããã³deleteãšåæ§ã«æ©èœããŸããå¯äžéèŠãªãã¥ã¢ã³ã¹ã¯ãããã°ã©ã ãåæ¢ããå ŽåïŒããšãã°ã[åæ¢]ãã¿ã³ãæŒããŠïŒãå²ãåœãŠãããã¡ã¢ãªãã·ã¹ãã ã«æ»ããªãããšã§ããããã°ã©ã çµäºãã³ãã©ãŒïŒinstallExitHandlerïŒãæèçã«ã€ã³ã¹ããŒã«ããèŠæ±ããããããã¯ããã¹ãŠããŒããã解æŸããå¿ èŠããããŸãã
ãªã¢ã«ã¿ã€ã ã¯ããã¯ã䜿çšãã
ã³ã³ãããŒã©ã«ã¯ããªã¢ã«ã¿ã€ã ã¯ããã¯ãæèŒãããŠããŸãã
çŸåšã®æå»ãååŸããgetclockããã³setclocké¢æ°ã䜿çšããŠèšå®ã§ããŸããããã¥ã¡ã³ãã«ã¯è©³çŽ°ãªäŸããããŸãã
ç°¡åãªã¢ã«ãŽãªãºã ã®äŸ
éé»å®¹éã®ã¢ããã°ã¬ãã«ã»ã³ãµãŒãæ¥ç¶ãããŠããAI 2ãã£ãã«ã«ãã³ãã¹ã¿ãŒã¿ãŒãªã¬ãŒãæ¥ç¶ãããŠããDO1ãã£ãã«ã«ãI / OããŒã5604ãåããã³ã³ãããŒã©ããããšããŸãã
ã¿ã³ã¯å ã®æå®ããã液äœã¬ãã«ãç¶æããå¿ èŠããããŸãïŒå¿ èŠãªã¬ãã«ã¯SCADAãŸãã¯HMIããã«ããèšå®ãããŸãïŒãã€ãŸããã¬ãã«ãé«ãããå Žåã¯ãå¿ èŠãªã¬ãã«ã«éãããšãã«éå°ããã³ãã³ã°ãããã³ãã®ãªã³ãšãªããåãæ¿ããå¿ èŠããããŸãã
ããŒã«ãã£ã³ã°ãŸãŒã³ïŒ40020ïŒã®ã¬ãžã¹ã¿0020ã«ãSCADAãŸãã¯HMIããã«ã«è¡šç€ºããããã®äœæžã¬ãã«å€ãæžã蟌ã¿ãŸãã
ãŸããã¬ãã«ãç®çã®ã¬ãã«ä»è¿ã§å€åããå Žåã«ãã³ããªã¬ãŒããã¯ãªãã¯ãããä¿è·ãããããã«ãå°ããªãã¹ããªã·ã¹ãæäŸããå¿ èŠããããŸãã
ã³ã³ãããŒã©ã¯COM2ããŒããä»ããŠããŒãªã³ã°ãããŸãã
#include <ctools.h> #include "nvMemory.h" /** * @brief 5604 modbus- */ void initialize_io() { request_resource(IO_SYSTEM); clearRegAssignment(); addRegAssignment(SCADAPack_5604IO, 0, 1, 10001, 30001, 40001); release_resource(IO_SYSTEM); } /** * @brief COM2 Modbus Slave, = 1, = 9600 */ void initialize_ports() { request_resource(IO_SYSTEM); PROTOCOL_SETTINGS comsettings; pconfig portSettings; getProtocolSettings(com2, &comsettings); comsettings.station = 1; comsettings.type = MODBUS_RTU; comsettings.mode = AM_standard; get_port(com2,&portSettings); portSettings.baud = BAUD9600; portSettings.duplex = HALF; portSettings.parity = PARITY_NONE; portSettings.data_bits = DATA8; portSettings.stop_bits = STOP1; portSettings.flow_tx = TFC_NONE; portSettings.flow_rx = RFC_MODBUS_RTU; portSettings.type = RS232; setProtocolSettings(com2, &comsettings); set_port(com2,&portSettings); request_resource(IO_SYSTEM); } /** * @brief AI- * @param ai_value "" AI * @param max AI ( ) * @return */ float scale_ain(int ai_value, float max) { return ((float)ai_value - 6554) / 26214 * max; } /* . #include */ #define AILevelReg 30002 // , AI (2- AI) #define LevelScaledReg 40020 // , #define PumpLevelTriggerReg 40050 // , SCADA ( ) #define PumpOutReg 1 // DO, (1- DO) #define LevelHyst 50 // . , #define MaxLevelMeters 500 // ( ), int main(void) { // COM initialize_ports(); // - initialize_io(); while (TRUE) { request_resource(IO_SYSTEM); // AI , int level_raw = dbase(MODBUS, AILevelReg); float level_scaled = scale_ain(level_raw, MaxLevelMeters); setdbase(MODBUS, LevelScaledReg, (int)level_scaled); // , if (level_scaled > (dbase(MODBUS, PumpLevelTriggerReg) + LevelHyst)) setdbase(MODBUS, PumpOutReg, 1); else // - if (level_scaled < (dbase(MODBUS, PumpLevelTriggerReg) - LevelHyst)) setdbase(MODBUS, PumpOutReg, 0); release_resource(IO_SYSTEM); release_processor(); } }
ããã ãã§ã
ãã¹ãŠã®é¢æ°ã®èª¬æãšãã®äœ¿çšäŸã¯ãCããŒã«ã®ããã¥ã¡ã³ãã«ãããŸãã
ã³ãŒããçŸããããšã©ãŒãªãèšè¿°ããããã«ãCã®å®å šãªç¥èãããïŒããšãã°ãã¢ã«ãŽãªãºã ãå®è£ ããå Žåãããã¯åå€æã«é©çšãããïŒããšã¯éåžžã«è¯ãããšã§ãã
åŠã³ãå®éšãããã¹ãŠãããŸãããïŒ
ææãšè²Žéãªã³ã¡ã³ãã®æºåã«ååããŠãããããã¹ã«æè¬ããŸã:)