1Modbus/TCP䙊䇟ᾲ䘠MODBUS/TCPᱟㆰঅⲴǃѝ・ল୶Ⲵ⭘Ҿ㇑⨶઼᧗ࡦ㠚ࣘॆ䇮༷ⲴMODBUS㌫ࡇ䙊䇟ॿ䇞Ⲵ⍮⭏ӗ૱ˈᆳ㾶ⴆҶ֯⭘TCP/IPॿ䇞Ⲵ“Intranet”઼“Internet”⧟ຳѝMODBUSᣕ᮷Ⲵ⭘䙄DŽॿ䇞Ⲵᴰ䙊⭘⭘䙄ᱟѪ䈨ྲPLC’sˈI/O⁑ඇˈԕ৺䘎᧕ަᆳㆰঅฏᙫ㓯ᡆI/O⁑ඇⲴ㖁ޣᴽ࣑ⲴDŽMODBUS/TCP֯MODBUS_RTUॿ䇞䘀㹼Ҿԕཚ㖁ˈMODBUS/TCP֯⭘TCP/IP઼ԕཚ㖁൘ㄉ⛩䰤Ր䘱MODBUSᣕ᮷ˈMODBUSTCP㔃ਸҶԕཚ㖁⢙⨶㖁㔌઼㖁㔌ḷ߶TCP/IPԕ৺ԕMODBUSѪᓄ⭘ॿ䇞ḷ߶Ⲵᮠᦞ㺘⽪ᯩ⌅DŽMODBUS/TCP䙊ؑᣕ᮷㻛ሱ㻵Ҿԕཚ㖁TCP/IPᮠᦞवѝDŽоՐ㔏ⲴѢਓᯩᔿˈMODBUS/TCPᨂޕањḷ߶ⲴMODBUSᣕ᮷ࡠTCPᣕ᮷ѝˈнᑖᴹᮠᦞṑ傼઼ൠ൰DŽˊ䙊䇟ᡰ֯⭘Ⲵԕཚ㖁৲㘳⁑රModbus/TCPՐ䗃䗷〻ѝ֯⭘ҶTCP/IPԕཚ㖁৲㘳⁑රⲴ5ቲ˖ㅜаቲ˖⢙⨶ቲˈᨀ䇮༷⢙⨶᧕ਓˈоᐲӻ䍘/㖁㔌䘲䝽ಘެᇩㅜҼቲ˖ᮠᦞ䬮䐟ቲˈṬᔿॆؑਧࡠⓀ/ⴞ⺜Ԧ൰ᮠᦞᑗㅜйቲ˖㖁㔌ቲˈᇎ⧠ᑖᴹ32սIP൰IPᣕ᮷वㅜഋቲ˖Ր䗃ቲˈᇎ⧠ਟ䶐ᙗ䘎᧕ǃՐ䗃ǃḕ䭉ǃ䟽ਁǃㄟਓᴽ࣑ǃՐ䗃䈳ᓖㅜӄቲ˖ᓄ⭘ቲˈModbusॿ䇞ᣕ᮷.ˊ䙊䇟ᡰ֯⭘Ⲵ৲㘳⁑රModbusᮠᦞ൘TCP/IPԕཚ㖁кՐ䗃ˈ᭟ᤱEthernetII઼802.3єᑗṬᔿDŽModbusTCPᮠᦞᑗवਜ਼ᣕ᮷ཤǃ࣏㜭ԓ⸱઼ᮠᦞ3䜘࠶ˈMBAPᣕ᮷ཤ(ModbusApplicationProtocolǃModbusᓄ⭘ॿ䇞)࠶4њ᧗ࡦฏˈޡ7њᆇ㢲ˈྲമ1ᡰ⽪˖മ1˖MODBUSTCPᣕ᮷⭡Ҿ֯⭘ԕཚ㖁TCP/IPᮠᦞ䬮䐟ቲⲴṑ傼ᵪࡦ؍䇱ҶᮠᦞⲴᆼᮤᙗˈMODBUS/TCPᣕ᮷ѝнᑖᴹᮠᦞṑ傼”CHECKSUM”ˈᴹᣕ᮷ѝⲴ“ADDRESS”ҏ㻛“UNITID”ᴯԓ㘼࣐൘MODBUSᓄ⭘ॿ䇞ᣕ᮷ཤѝDŽˊ䙊䇟ᡰ֯⭘Ⲵ৲㘳⁑ර൘Modbusᴽ࣑ಘѝ᤹㕪ⴱ֯⭘Port502䙊ؑㄟਓ,൘Modusᇒᡧಘ〻ᒿѝਟԕ䇮㖞ԫ䙊ؑㄟਓˈѪ䚯ݽоަԆ䙊䇟ॿ䇞Ⲵߢケа㡜ᔪ䇞֯⭘2000ԕਾⲴㄟਓˊ4Modbus/TCP֯⭘Ⲵ࣏㜭ԓ⸱᤹➗֯⭘⭘䙄४࠶,ޡᴹ3㊫ර࠶࡛Ѫ˖1)ޜޡ࣏㜭ԓ⸱˖ᐢᇊѹྭ࣏㜭⸱ˈ؍䇱ަୟаᙗˈ⭡Modbus.org䇔ਟ˗2)⭘ᡧ㠚ᇊѹ࣏㜭ԓ⸱ᴹє㓴ˈ࠶࡛Ѫ65̚72઼100̚110ˈᰐ䴰䇔ਟˈնн؍䇱ԓ⸱֯⭘ୟаᙗ,ྲਈѪޜޡԓ⸱ˈ䴰ӔRFC䇔ਟ˗3)؍⮉࣏㜭ԓ⸱ˈ⭡ḀӋޜਨ֯⭘ḀӋՐ㔏䇮༷ԓ⸱ˈнਟѪޜޡ⭘䙄DŽ᤹➗ᓄ⭘␡⍵ˈਟ࠶Ѫ3њ㊫࡛1)㊫࡛0,ᇒᡧᵪ/ᴽ࣑ಘᴰሿਟ⭘ᆀ䳶˖䈫ཊњ؍ᤱᇴᆈಘ(fc.3)˗߉ཊњ؍ᤱᇴᆈಘ(fc.16)DŽ2)㊫࡛1ˈਟᇎ⧠สᵜӂ᱃ᑨ⭘ԓ⸱˖䈫㓯സ(fc.1)˗䈫ᔰޣ䟿䗃ޕ(fc.2)˗䈫䗃ޕᇴᆈಘ(fc.4)˗߉㓯സ(fc.5)˗߉অаᇴᆈಘ(fc.6)DŽ3)㊫࡛2ˈ⭘ҾӪᵪ⭼䶒ǃⴁ᧗㌫㔏ֻ㹼઼ᮠᦞՐ䘱࣏㜭˖ᕪࡦཊњ㓯സ(fc.15)˗䈫䙊⭘ᇴᆈಘ(fc.20)˗߉䙊⭘ᇴᆈಘ(fc.21)˗ቿ㭭߉ᇴᆈಘ(fc.22)˗䈫߉ᇴᆈಘ(fc.23)Modbus/TCP֯⭘Ⲵ࣏㜭⸱ሩᓄࡇ㺘ྲлമ2ᡰ⽪˖മ2˖Modbus/TCPᡰ֯⭘Ⲵ࣏㜭⸱ˊ5Modbus/TCP䙊䇟ᓄ⭘Ѯֻ൘䈫ᇴᆈಘⲴ䗷〻ѝ,ԕModbusTCP䈧≲ᣕ᮷Ѫֻ,ާփⲴᮠᦞՐ䗃䗷〻ྲл:1)Modbus/TCPᇒᡧㄟˈ⭘Connect()ભԔᔪ・ⴞḷ䇮༷TCP502ㄟਓ䘎᧕ᮠᦞ䙊ؑ䗷〻2)߶༷Modbusᣕ᮷ˈवᤜ7њᆇ㢲MBAP䈧≲3)֯⭘send()ભԔਁ䘱4)਼а䘎᧕ㅹᖵᓄㆄ5)䙊䗷recv()䈫ᣕ᮷ˈᆼᡀа⅑ᮠᦞӔᦒ䗷〻6)ᖃ䙊ؑԫ࣑㔃ᶏᰦˈޣ䰝TCP䘎᧕ˈ֯ᴽ࣑ಘਟԕѪަԆᴽ࣑࣏㜭⸱⸱ᆀ⸱˄ॱޝ䘋ᮠᦞ䇯䰞ս䇯䰞⢙⨶ᮓ䟿䈫ᮓ䟿䗃ޕ0202䜘սᡆ⢙⨶㓯സ䈫㓯സ0101߉অњ㓯സ0505߉ཊ㓯സ150F16ս䇯䰞䗃ޕᇴᆈಘ䈫䗃ޕᇴᆈಘ0404䜘ᇴᆈಘᡆ⢙⨶䗃ࠪᇴᆈಘ䈫؍ᤱᇴᆈಘ0303߉অᇴᆈಘ0606߉ཊᇴᆈಘ1610䈫/߉ཊᇴᆈಘ2317ቿ㭭߉ᇴᆈಘ2216䈫FIFO䱏ࡇ2418᮷Ԧ䇠ᖅ䇯䰞䈫᮷Ԧ䇠ᖅ20614߉᮷Ԧ䇠ᖅ21615䇺ᯝ䈫ᔲᑨ⣦ᘱ07䇺ᯝ0800-18㧧ᗇ䙊ؑһԦ䇑ᮠಘ11OB㧧ᗇ䙊ؑһԦ䇠ᖅ120CᣕӾㄉID1711䈫䇮༷䇶࡛⸱43142Bަᆳሱ㻵᧕ਓՐ䗃432B2TIAঊ䙄V11ᒣਠS7-1200Modbus/TCPᓃ࠭ᮠᾲ䘠TIAঊ䙄ޘ䳶ᡀ㠚ࣘॆ䖟Ԧᱟᵚᶕ㾯䰘ᆀޘ䳶ᡀ㠚ࣘॆ㌫ࡇᡰᴹ⭘Ҿᐕ〻ǃ㕆〻઼䈳䈅㠚ࣘॆ䇮઼༷傡ࣘ㌫㔏ⲴสˈӾTIAঊ䙄䖟ԦV11SP1ᔰˈ൘S7-1200Ⲵᓃ࠭ᮠѝݽ䍩፼྇ҶModbus/TCP࣏㜭ඇᓃˈᇒᡧਟԕ࡙⭘䈕ᓃ࠭ᮠᆼᡀоањㅜйᯩ䇮༷ⲴModbus/TCP䙊䇟ˈྲлമᡰ⽪˖മ3˖TIAঊ䙄V11ѝS7-1200䙊䗷፼ⲴModbus/TCPᓃ࠭ᮠоㅜйᯩ䇮༷䙊䇟TIAঊ䙄V11ѝ፼ⲴS7-1200Modbus/TCPᓃ࠭ᮠާᴹྲл⢩⛩˖1˅वਜ਼ҶServer઼ClientⲴᓃ࠭ᮠˈ਼ᰦ൘ањS7-1200ѝਟԕ਼ᰦѪServer઼ClientDŽ2˅䙊䗷S7-1200CPUⲴ䳶ᡀProfinet᧕ਓ䘋㹼䙊䇟3˅ਟԕ᭟ᤱཊњServer઼ClientⲴ䘎᧕ˈնᱟ䴰㾱⌘ԕлࠐњᯩ䶒˖gᴰབྷ᭟ᤱњ䘎᧕䙊䗷OpenIEᯩᔿࡋᔪTCP䘎᧕)g⇿њ䘎᧕ᗵ享䈳⭘ањ“MB_Block”ඇg⇿њ䘎᧕䈳⭘Ⲵ“MB_Block”ඇѝ֯⭘Ⲵ䘎᧕ID઼ㄟਓਧᗵ享ୟал䶒ሶ䈖㓶ӻ㓽ྲօ֯⭘䈕ᓃ࠭ᮠ䝽㖞S7-1200ѪModbus/TCPⲴServer઼Clientоㅜйᯩ䇮༷䘋㹼䙊䇟DŽ3⍻䈅ֻᆀѝ֯⭘Ⲵ⺜Ԧ઼䖟ԦԕлⲴ䝽㖞ᇎֻѝᡰ֯⭘ࡠⲴ⺜Ԧ䝽㖞ྲл㺘1ᡰ⽪˖㺘˖䝽㖞ᇎֻѝ⭘ࡠⲴ⺜Ԧࡇ㺘䝽㖞ᇎֻѝ⭘ࡠⲴ䖟Ԧྲл㺘ᡰ⽪:㺘˖䝽㖞ᇎֻѝ⭘ࡠⲴ䖟Ԧࡇ㺘༷⌘:(1)SIMATICStep7V11वਜ਼єњ⡸ᵜˈ࠶ѪStep7BasicV11઼Step7ProfessionalV11ˈሩҾS7-1200Ⲵ㓴ᘱӵ䴰㾱Step7BasicV11ণਟˈᵜֻѝⲴPCᵪᆹ㻵ҶStep7ProfessionalV11ˈਖཆྲ᷌ᆹ㻵ҶStep7ProfessionalV11ˈሶⴤ᧕፼྇ᆹ㻵ҶWinCCBasicV11ˈ㜭ཏ⭘Ҿ㓴ᘱоS7-1200३䝽ⲴаӋBasicPanel4൘TIAঊ䙄V11ѝ䝽㖞S7-1200ѪModbus/TCPClientˊ1൘Step7ProfessionalV11ѝ㓴ᘱS7-1200൘STEP7ProfessionalV11ѝࡋᔪањS7-1200Ⲵ亩ⴞˈᵜֻѝ亩ⴞѪS7-1200_Modbus_TCP_Clientˈ࠷ᦒࡠ亩ⴞ㿶മ⭼䶒ˈᨂޕањS7-1200CPUˈӾ⺜Ԧⴞᖅѝᨂޕ1214CPUAC/DC/Rlyˈᒦ䘹ᤙപԦ⡸ᵜѪV2.1ሩަᙗ㓴ᘱˈྲлമ4ᡰ⽪〠ᮠ䟿䇒䍗ਧSIMATICS7-1200,PM1207,2,5A16EP1332-1SH71SIMATICS7-1200CPU1214CപԦ⡸ᵜV2.116ES7214-1BD30-0XB0ԕཚ㖁䘎᧕⭥㔶㤕ᒢ㕆〻ಘެPC䖟Ԧ⍻䈅ᵪ1〠ᮠ䟿䇒䍗ਧSIMATICStep7ProfessionalV11SP2(1)16ES7822-1AA01-0YA5SIMATICWinCCProfessionalV11SP216AV2103-0XA01-0AH5ModScan32V4.0ˈᆹ㻵൘PCᵪ⁑ᤏModbus/TCPⲴClient1ਟԕӾޣ㖁ㄉݽ䍩л䖭MbslaveV4.3.0ˈᆹ㻵PCᵪ⁑ᤏModbus/TCPⲴServer1ਟԕӾޣ㖁ㄉݽ䍩л䖭മ4˖ᨂޕањS7-1200亩ⴞ⛩ࠫ“OKāਾ䘋ޕࡠ“Deviceviewā⭼䶒ˈ൘“Deviceviewā⭼䶒ѝ䘹ѝCPU1214CⲴԕཚ㖁ਓˈ൘л䶒Ⲵ᧕ਓᙗѝ䇮㖞CPU1214CⲴԕཚ㖁᧕ਓⲴIPൠ൰Ѫ192.168.0.10ˈᒦሶަ䘎᧕ࡠањᯠᔪⲴԕཚ㖁кˈྲлമ5ᡰ⽪˖മ5˖䇮㖞S7-1200CPUԕཚ㖁᧕ਓⲴIPൠ൰ˊ2Step7ProfessionalV11ѝ䈳⭘S7-1200Modbus/TCPClientᓃ࠭ᮠ൘亩ⴞṁѝᢃᔰS7-1200亩ⴞⲴ“Programblockāˈѻਾᢃᔰѫᗚ⧟ඇOB1ˈӾਣ䗩Ⲵ〻ᒿᓃ࠭ᮠѝⲴ“Instruction-Communication-Communicationprocessor-ModbusTCP”лሶ“MB_CLIENT”ᤆࡠOB1⭼䶒ѝˈѻਾሶՊ㠚ࣘᕩࠪᯠⲴ⭼䶒ˈ䇮㖞䈳⭘FB“MB_CLIENTā࣏㜭ඇⲴ㛼Ჟᮠᦞඇˈᵜֻѝ䇮㖞ѪDB1ˈྲлമ6ᡰ⽪˖മ6˖ᤆModbus/TCPⲴ“MB_CLIENTāඇࡠOB1ѝѻਾ䴰㾱䇮㖞“MB_CLIENTāⲴ㇑㝊৲ᮠˈᵜֻѝሶ“MB_CLIENTā࣏㜭ඇⲴ᧗ࡦ㇑㝊৲ᮠ൷᭮൘DB2(Client_Control)ѝˈ䙊䇟⍻䈅ᮠᦞ४᭮൘DB3ѝ(Client_Data)ˈਖཆѪҶׯҾ䘋㹼᭵䳌䇺ᯝˈ䙊ᑨᛵߥлਟԕሶ“MB_CLIENTā࣏㜭ඇⲴ“STATUSā䙊䗷“ERRORāؑਧ䗃ࠪ䘋㹼㕃ᆈˈྲлമ7ᡰ⽪˖മ7˖䇮㖞“MB_CLIENTā࣏㜭ඇ㇑㝊“MB_CLIENTā࣏㜭ඇ㇑㝊৲ᮠⲴ䈖㓶ਜ਼ѹྲл㺘3ᡰ⽪˖৲ᮠ༠᰾㊫රᮠᦞ㊫ර䈖㓶᧿䘠REQInputBOOLੁModbus/TCPServerㄟ䘎᧕䈧≲ˈкॷ⋯ᴹ᭸ˈᵜֻѝሶ৲ᮠ᭮൘DB2ѝDISCONNECTInputBOOL⭘Ҿ᧗ࡦоModbus/TCPServerㄟ䘎᧕ˈަѝ0Ѫ؍ᤱ䘎᧕˗1Ѫᯝᔰ䘎᧕ˈᵜֻѝሶ৲ᮠ᭮൘DB2ѝCONNECT_IDInputWORD䘎᧕IDਧˈ⇿њ䘎᧕ⲴIDᗵ享Ѫ1ˈᵜֻѝሶ৲ᮠ᭮൘DB2ѝˈᒦ䇮㖞㕪ⴱ٬Ѫ1IP_OCTET_1InputBYTEModbus/TCPServerⲴIPൠ൰ㅜ1䜘࠶ˈᵜֻѝѪ192IP_OCTET_2InputBYTEModbus/TCPServerⲴIPൠ൰ㅜ2䜘࠶ˈᵜֻѝѪ168IP_OCTET_3InputBYTEModbus/TCPServerⲴIPൠ൰ㅜ3䜘࠶ˈᵜֻѝѪ0IP_OCTET_4InputBYTEModbus/TCPServerⲴIPൠ൰ㅜ4䜘࠶ˈᵜֻѝѪ10IP_PORTInputWORDServerㄟㄟਓਧˈᵜֻѝѪ֯⭘㕪ⴱㄟਓਧ502MODEInputUSINT䈧≲⁑ᔿˈवᤜ䈫߉৺䇺ᯝˈާփਜ਼ѹਟԕ৲㘳㺘4ˈᵜֻѝሶ৲ᮠ᭮൘DB2ѝˈᒦ䇮㖞㕪ⴱ٬Ѫ0MB_DATA_ADDRInputUDINTModbus䎧ൠ൰ˈާփਜ਼ѹਟԕ৲㘳㺘4ˈᵜֻѝሶ৲ᮠ᭮൘DB2ѝˈᒦ䇮㖞㕪ⴱ٬Ѫ40001MB_DATA_LENInputUINT䈧≲ⲴᇴᆈಘᡆսⲴ䮯ᓖˈާփਜ਼ѹਟԕ৲㘳㺘4ˈᵜֻѝሶ৲ᮠ᭮൘DB2ѝˈᒦ䇮㖞㕪ⴱ٬Ѫ5MB_DATA_PTRInputVARIANTоModbus/TCPServer䘋㹼䙊䇟Ⲵᮠᦞᆈۘ४ˈ᭟ᤱᤷ䪸ˈᵜֻѝሶᮠᦞ᭮൘DB3ѝˈᒦ䇮㖞㕪ⴱ٬ѪP#DB3.DBX0.0WORD10DONEOutputBOOLᖃѪ1ᰦ㺘⽪ᆼᡀа⅑ъˈᵜֻѝሶ৲ᮠ᭮൘DB2ѝBUSYOutputBOOLъ䘋〻ḷᘇˈ0㺘⽪ᖃࡽ⋑ᴹԫօъˈ1㺘⽪↓൘䘋㹼ъERROROutputBOOLъᱟࠪ䭉ˈ0㺘⽪↓ᑨˈ1㺘⽪᭵䳌STATUSOutputWORDъ⣦ᘱᆇˈ⭘Ҿ᭵䳌䇺ᯝˈާփਟԕ৲㘳㺘5ˈᵜֻѝሶ৲ᮠ᭮൘DB2ѝ㺘3˖“MB_CLIENTā࣏㜭ඇ㇑㝊৲ᮠӾк䘠৲ᮠѝਟԕⴻࡠˈ“MB_CLIENTā࣏㜭ඇѝᒦ⋑ᴹᇊѹ࣏㜭⸱Ⲵⴤ᧕ޣ৲ᮠˈާփ࣏㜭⸱ሶ⭡৲ᮠMODEǃMB_DATA_ADDRǃMB_DATA_LENⲴ㓴ਸޡ਼ᇊѹˈ↔ཆ䘈वਜ਼ҶаӋ䇺ᯝ࣏㜭ˈྲл㺘4ᡰ⽪˖MB_MODEModbus࣏㜭⸱MB_DATA_LEN࣏㜭઼ᮠᦞ㊫රMB_DATA_ADDR0011-2000䈫㓯സ˖1-2000Bit1-99990021-2