Modbus ×ܽáѧϰ
Modbus ÊÇÒ»¸ö»ùÓÚ RS485 µÄ¹¤Òµ±ê׼ͨѶÐÒ飬¹ã·ºµÄÓ¦ÓÃÔÚ¹¤Òµ¿ØÖÆÖУ¬Ö÷ÒªµÄ Ó¦ÓÃÕÕ¾ÉÔÚ PLC µÈµÈÉ豸ÖС£ÏêϸµÄ¿´·¨ÕâÀï¾Í²»×ö˵Ã÷£¬Ö»¶ÔʹÓýøÐÐÏêϸ˵Ã÷
1¡¢modbus µÄһЩÌصã
(1)¡¢ÔÚͬһ¸ö modbus ÍøÂçÖУ¬Ö»ÄÜÓÐ 1 ̨Ö÷»ú£¬¶ą̀´Ó»ú¡£
(2)¡¢modbus ´Ó»ú²ÅÐèÒªµØµã£¬Ö÷»úûÓеص㣬²»ÐèÒª³õʼ»¯µØµã
(3)¡¢modbus ÓеÄͨѶ¶¼ÊÇÓÉÖ÷»úÌᳫµÄ£¬Ò²¾ÍÊÇ˵´Ó»ú²»¿ÉÄÜÖ÷¶¯·¢Êý¾Ý¸ø´Ó»ú¡£modbus ÊÇÖ÷´ÓµÄ£¬Ö»ÄÜÖ÷ÎʴӴ𣬴ӻú²»¿ÉÖ÷¶¯ÉÏËÍ¡£
2¡¢modbus ÓÐÁ½ÖÖͨÐÅ·½·¨£º
(1)¡¢RTU µÄ·½·¨ --- Õâ¸öÊÇÎÒÃǵÄʹÓõķ½·¨£¬ÏÂÃæ˵ÓеĽéÉܶ¼ÊÇ»ùÓÚ RTU ÕâÖÖ·½·¨ (2)¡¢ASCLL ÂëµÄ·½·¨ --- ËûµÄÊý¾Ý×Ö½ÚÊÇ 7bit 룬ÎÒÃÇÆÕͨµÄ mcu ²»Ì«ºÃʵÏÖ¡£ÁíÍâÊг¡ÉÏ ÓõıȽÏÉÙ¡£ËùÒÔÕâÖÖ·½·¨£¬ÕâÀï²»×öÑо¿
¶þ¡¢RTU ģʽ
1¡¢RTU ģʽµÄÊý¾ÝÖ¡»¨Ñù˵Ã÷
(1)¡¢ÆðʼλºÍ½áÊø·ûÊÇÒ»ÑùµÄ
(2)¡¢T1-T2-T3-T4 ´ú±íµÄÒâ˼£¿
Õâ¸öÎÊÌâÊÇÕë¹ØÓÚ modbus rtu ÐÒéµÄ£¬ÕâÊÇ modbus rtu ÐÒéµÄÊý¾Ý»¨Ñù¡£ÆäÖÐ T1-T2-T3-T4 ÌåÏÖ 4 ¸ö×Ö½ÚµÄͨѶ¼ä¸ô¡£ÔÚ modbus rtu ÐÒéÖÐÒªÇóÿ¸öÊý¾Ý°üµÄÇ°ºóÓÐÖÁÉÙ´«Êä 3.5 ¸ö×Ö ½ÚµÄʱ¼ä¼ä¸ô£¬ÓÃÀ´¼ä¸ô¶àÌõÊý¾Ý
(3)¡¢CRC16 УÑé²ÎÕÕ±ðÈËÏֳɵľͿÉÒÔÁË£¬²»ÏêϸÉ
(4)¡¢É豸µØµã£ºÕâ¸öºÃÀí½â¡£Modbus Ö÷»úµÄµØµã²»ÐèÒªÉ趨£¬´Ó»úµÄµØµã¿ÉÉ趨Ϊ 1~247¡£
(5)¡¢¹¦Ð§´úÂ룺°Ý¼ûÏÂÃæµÄÏêϸ˵Ã÷
(6)¡¢Êý¾Ý£º°Ý¼ûÏÂÃæÏêϸ˵Ã÷
2¡¢RTUģʽÏÂÈçºÎÅжÏÊý¾ÝµÄ¿ªÊ¼
Èý¡¢¹¦Ð§´úÂë˵Ã÷
1¡¢³£Óù¦Ð§´úÂë
(1)¡¢03 ¹¦Ð§´úÂë¡£Õâ¸ö¹¦Ð§´úÂë¾ÍÊǶÁÈ¡Ö¸¶¨µÄ¼Ä´æÆ÷µÄÊý¾Ý¡£
==>Æäʵ˵°×ÁË£¬ÕâÀïÃæµÄ¼Ä´æÆ÷ÊÇ×Ô¼ºËù½ç˵µÄ¡£
==>Ó¦Óõ½ÎÒÃǵIJúÆ·ÖУ¬Æäʵ¾ÍÊǶÁȡϵͳµÄ״̬¡¢ÒÔ¼°Îļþ×ÜÊýµÈµÈÊý¾Ý.
==>Ò²¾ÍÊÇÎÒÃÇËù˵µÄÅÌÎʹ¦Ð§¡£
(2)¡¢06 ¹¦Ð§´úÂë¡£Õâ¸ö¹¦Ð§´úÂë¾ÍÊÇдÈëÊý¾Ýµ½¼Ä´æÆ÷ÖС£
==>Æäʵ˵°×ÁË£¬Õâ¸ö¾ÍÊÇÖ÷»ú·¢ËÍÊý¾Ý£¬¶ø´Ó»ú½ÓÊܵ½Ö®ºó£¬Ð´Èëµ½×Ô¼ºÉ趨µÄ¼Ä´æÆ÷ÖС£
==>Ó¦Óõ½ÎÒÃǵIJúÆ·ÖУ¬Æäʵ¾ÍÊÇÖ÷»ú·¢ËÍÒ»¸öÖ¸Áî¸øÎÒÃÇоƬ£¬¶øÎÒÃǵÄоƬ½«Õâ¸öÖ¸Áî´æ´¢µ½Ëù½¨Á¢µÄ¼Ä´æÆ÷ buffer ÖУ¬ÔÙ¶ÔÕâ¸öÖ¸Áî½øÐÐÏàÓ¦µÄÐж¯
==>Ò²¾ÍÊÇÎÒÃdz£ËµµÄ“¿ØÖƹ¦Ð§”
ËÄ¡¢¾ÙÀý˵Ã÷
1¡¢06 ¹¦Ð§Âë
Èçͼ£ºÎÒÃÇµÄ USB ת 485 Ä£¿éÐéÄâ³öµÄÊÇ COM5£¬²¨ÌØÂÊ 9600£¬ÎÞУÑé룬Êý¾ÝλÊÇ 8 룬
1 λֹͣ룬É豸µØµã¼ÙÉèΪ 1¡£
(1)¡¢Ð´¼Ä´æÆ÷µÄʱºò£¬Èç¹ûÎÒÃÇÒª°Ñ 01 дµ½Ò»¸öµØµãÊÇ 0000 µÄ¼Ä´æÆ÷µØµãÀµãһϓд
È딣¬¾Í»á·ºÆð·¢ËÍÖ¸Á01 06 00 00 00 01 48 0A¡£ (2)¡¢ÎÒÃÇÀ´ÆÊÎöÒ»ÏÂÕâÖ¡Êý¾Ý£¬ÆäÖÐ 01 ÊÇÉ豸µØµã£¬06 Êǹ¦Ð§Â룬´ú±íд¼Ä´æÆ÷Õâ¸ö¹¦ ÄÜ£¬ºó±ß¸ú 00 00 ÌåÏÖµÄÊÇҪдÈëµÄ¼Ä´æÆ÷µÄµØµã£¬00 01 ¾ÍÊÇҪдÈëµÄÊý¾Ý£¬48 0A ¾ÍÊÇ CRC УÑéÂ룬ÕâÊÇÈí¼þ×Ô¶¯Ëã³öÀ´ÁË¡£
(3)¡¢¶øƾ¾Ý Modbus ÐÒ飬µ±Ð´¼Ä´æÆ÷µÄʱºò£¬´Ó»úÀÖ³ÉÍê³É¸ÃÖ¸ÁîµÄ²Ù×÷ºó£¬»á°ÑÖ÷»ú ·¢Ë͵ÄÖ¸ÁîÖ±½Ó·µ»Ø£¬ÎÒÃǵĵ÷ÊÔ¾«Áé»á½ÓÊÕµ½ÕâÑùÒ»Ö¡Êý¾Ý£º01 06 00 00 00 01 48 0A¡£
2¡¢03 ¹¦Ð§Âë
¼ÙÈçÎÒÃÇÏÖÔÚÒª´Ó¼Ä´æÆ÷µØµã 0002 ¿ªÊ¼¶ÁÈ¡¼Ä´æÆ÷£¬²¢ÇÒ¶ÁÈ¡µÄÊýÁ¿ÊÇ 2 ¸ö¡£ÈçÉÏͼ
(1)¡¢µãһϓ¶Á³ö”£¬¾Í»á·ºÆð·¢ËÍÖ¸Á01 03 00 02 00 02 65 CB¡£
(2)¡¢ÆäÖÐ 01 ÊÇÉ豸µØµã£¬03 Êǹ¦Ð§Â룬´ú±íд¼Ä´æÆ÷Õâ¸ö¹¦Ð§£¬00 02 ¾ÍÊǶÁ¼Ä´æÆ÷µÄÆð ʼµØµã£¬ºóÒ»¸ö 00 02 ¾ÍÊÇÒª¶ÁÈ¡ 2 ¸ö¼Ä´æÆ÷µÄÊýÖµ£¬65 CB ¾ÍÊÇ CRC УÑé¡£ (3)¡¢¶ø½ÓÊÕµ½µÄÊý¾ÝÊÇ£º01 03 04 00 00 00 00 FA 33¡£ÆäÖÐ 01 ÊÇÉ豸µØµã£¬03 Êǹ¦Ð§Â룬
04 ´ú±íµÄÊǺó±ß¶Áµ½µÄÊý¾Ý×Ö½ÚÊýÊÇ 4 ¸ö£¬00 00 00 00 »®·ÖÊǵصãΪ 00 02 ºÍ 00 03 µÄ¼Ä´æ Æ÷ÄÚ²¿µÄÊý¾Ý£¬¶ø FA 33 ¾ÍÊÇ CRC УÑéÁË¡£751697315
Îå¡¢ÅäÖÃÎļþµÄ˵Ã÷
1¡¢ÈçÉÏͼ£¬ÎÒÃÇн¨µÄÒ»¸ö read.cfg Îļþ£¬ÀïÃæÌîÈëµÄÊý×ÖÊÇ¡°030010¡±£¬´ú±í¼ÄÒåÈçÏÂ
(1)¡¢µÚ1λ 0£¬´ú±íµÄÒâ˼ÊÇ°´¼üģʽÅäÖÃΪ 0£¬ÏêϸµÄ¹¦Ð§Çë²éÕÒ±í¸ñ
(2)¡¢µÚ¶þλ 3 ºÍµÚÈýλ 0£¬ÅäºÏ×é³ÉÁËÒôÁ¿Îª 30 ¼¶£¬Èç¹ûÕâÀïΪ 21 µÄ»°£¬ÊÇ 21 ¼¶ÒôÁ¿
(3)¡¢µÚËÄλ 0 ºÍµÚÎåλ 1£¬ÅäºÏ×é³ÉÁË modbus µÄÉ豸µØµã£¬ÕâÀïµØµãÉ趨Ϊ 01 µØµã Èç¹ûÒªÉ趨Ϊ 10 µØµãµÄ»°£¬ÕâÀïÁ½Î»ÌîÈë 10 ¼´¿É
(4)¡¢ºóһλ´ú±íµÄÊÇ busy ½ÅÊä³öÐźţ¬
01 06 00 01 00 00 D8 0A --- ´ú±íÏÂÒ»ÇúµÄÃüÁî
01 06 00 03 00 02 F8 0B --- Ö¸¶¨²¥·ÅµÚ¶þÇú
6¡¢²âÊÔ˵Ã÷
ÎÒÃÇÓÐµÄ modbus µÄÖ¸Áî²âÊÔ£¬¶¼ÊÇͨ¹ýµçÄԶ˵Ť¾ß²âÊԵģ¬Ê¹ÓõÄÊÇ“MODBUS µ÷ÊÔÖúÊÖ.exe”£¬Õâ¸öÈí¼þ¿ÉÒÔÎÊÎÒÃÇË÷È¡
²âÊÔ˵Ã÷ÈçÏ£º
ÎÒÃÇÖ»ÐèÒªÓõ½ 03 ºÍ 06 ÕâÁ½¸ö¹¦Ð§Âë
²âÊÔÎÒÃÇËùÉ趨µÄµØµãΪ 02
ÍêÈ«Ö§³Ö modbus µÄ±ê×¼ÐÒé
1¡¢²âÊÔ 06 ¹¦Ð§Âë
Modbus ¹ØÓÚ 06 ¹¦Ð§ÂëÒªÇ󣺴ӻúÊÕµ½Êý¾ÝÖ®ºó£¬½«Ö÷»ú·¢Ë͵ÄÊý¾ÝÔٴη¢¸øÖ÷»ú£¬×÷ Ϊ´Ó»úÊÕµ½Ö÷»úµÄÖ¸ÁîµÄÓ¦´ð
(1)¡¢0x01 Ö¸Áî²âÊÔ
ÕâÀï modbus Ö÷»ú·¢Ë͵ÄÊý¾ÝÊÇ“02 06 00 01 00 00 D8 39 ” ´ú±íµÄ¼ÄÒåÊÇ£ºÖ¸¶¨ÏÂÒ»Çú²¥·Å
(2)¡¢0x03 Ö¸Áî²âÊÔ
ÕâÀï modbus Ö÷»ú·¢Ë͵ÄÊý¾ÝÊÇ“02 06 00 03 00 02 F8 38 ” ´ú±íµÄ¼ÄÒåÊÇ£ºÆ¾¾ÝÎïÀí˳ÐòÖ¸¶¨µÚ¶þ¶ÎÓïÒô²¥·Å
(3)¡¢0x08 Ö¸Áî²âÊÔ
ÕâÀï modbus Ö÷»ú·¢Ë͵ÄÊý¾ÝÊÇ“02 06 00 08 00 02 89 FA” ´ú±íµÄ¼ÄÒåÊÇ£ºÆ¾¾ÝÎïÀí˳ÐòÖ¸¶¨µÚ¶þ¶ÎÓïÒôÑ»·²¥·Å
(4)¡¢0x0F Ö¸Áî²âÊÔ
ÕâÀï modbus Ö÷»ú·¢Ë͵ÄÊý¾ÝÊÇ“02 06 00 0F 01 01 79 AA ” ´ú±íµÄ¼ÄÒåÊÇ£ºÖ¸¶¨ 01 Îļþ¼ÐÏÂÃæµÄ 001xxx.mp3 Îļþ²¥·Å
ÁªÏµÈË£ºÀîÊï¹â
ÊÖ »ú£º17266260250
ÓÊ Ï䣺Lur@yxin18.com
¹« ˾£º¹ãÖÝÄϹ¬28NGµç×ӿƼ¼ÓÐÏÞ¹«Ë¾
µØ Ö·£º¹ãÖÝÊл¨¶¼ÇøÉÌÒµ´óµÀ334ºÅ