Benutzer-Werkzeuge

Webseiten-Werkzeuge


becki:linux:modbus

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Nächste Überarbeitung
Vorhergehende Überarbeitung
becki:linux:modbus [2010-07-22 15:46]
becki created
becki:linux:modbus [2013-06-13 13:56] (aktuell)
becki
Zeile 1: Zeile 1:
 ====== Modbus TCP == ====== Modbus TCP ==
  
-Collected informations for using [[wp>​Modbus]] on TCP/IP. Libmodbus is used as master on any Linux computer ([[Sheevaplug]]). Wago fieldbuscouplers [[http://​www.wagocatalog.com/okv3/index.asp?​strBestNrID=7500342|750-342]] are used as slaves.+Collected informations for using [[wp>​Modbus]] on TCP/IP. Libmodbus is used as master on any Linux computer ([[Sheevaplug]]). Wago fieldbuscouplers [[http://​www.wago.com/wagoweb/documentation/​750/​ger_manu/​342/​m034200d.pdf|750-342]] ​(or alternatively [[http://​www.wago.com/​wagoweb/​documentation/​750/​ger_manu/​841/​m084100d.pdf|750-841]]) ​are used as slaves. 
 + 
 +===== Modbus Command Overview == 
 + 
 +^ Code ^ Target ^ Count ^ Direction ^  Name in Spec             ^ Libmodbus 3 fkt name                ^  libmodbus 2 fkt name         ^ 
 +|  ''​01 0x01''​ |  DO   ​| ​ many  |  read     | Read Coils                | ''​modbus_read_bits'' ​               | ''​read_coil_status'' ​         | 
 +|  ''​02 0x02''​ |  DI   ​| ​ many  |  read     | Read Discrete Inputs ​     | ''​modbus_read_input_bits'' ​         | ''​read_input_status'' ​        | 
 +|  ''​03 0x03''​ |  AO   ​| ​ many  |  read     | Read Holding Registers ​   | ''​modbus_read_registers'' ​          | ''​read_holding_registers'' ​   | 
 +|  ''​04 0x04''​ |  AI   ​| ​ many  |  read     | Read Input Register ​      | ''​modbus_read_input_registers'' ​    | ''​read_input_registers'' ​     | 
 +|  ''​05 0x05''​ |  DO   ​| ​ one   ​| ​ write    | Write Single Coil         | ''​modbus_write_bit'' ​               | ''​force_single_coil'' ​        | 
 +|  ''​06 0x06''​ |  AO   ​| ​ one   ​| ​ write    | Write Single Register ​    | ''​modbus_write_register'' ​          | ''​preset_single_register'' ​   | 
 +|  ''​15 0x0f''​ |  DO   ​| ​ many  |  write    | Write Multiple Coils      | ''​modbus_write_bits'' ​              | ''​force_multiple_coils'' ​     | 
 +|  ''​16 0x10''​ |  AO   ​| ​ many  |  write    | Write Multiple registers ​ | ''​modbus_write_registers'' ​         | ''​preset_multiple_registers''​ | 
 +|  ''​23 0x17''​ | AI/AO |  many  |  both     | Wrt/Rd Multiple registers | ''​modbus_write_and_read_registers''​ |  :?:  | 
 + 
 +Sources [[http://​www.modbus.org/​docs/​Modbus_Application_Protocol_V1_1b.pdf|Spec]] [[http://​libmodbus.org/​site_media/​html/​libmodbus.html|Manpage]] 
 + 
 +More information sources: 
 +  * http://​www.anybus.de/​technologie/​modbustcp.shtml 
 +  * http://​www.modbus.org/​docs/​PI_MBUS_300.pdf 
 +  * http://​jamod.sourceforge.net/​kb/​protocol.html
  
 ===== Wago 750-342 == ===== Wago 750-342 ==
Zeile 27: Zeile 47:
 ipNumber= bootpEnabled ? getIpNumberFromBootpServer() : getIpNumberFromEeprom() ipNumber= bootpEnabled ? getIpNumberFromBootpServer() : getIpNumberFromEeprom()
 </​code>​ </​code>​
 +
 +Web access to 750-342 is ''​admin / wago''​
  
 See also: [[http://​www.wago.com/​wagoweb/​documentation/​750/​ger_manu/​841/​m084100d.pdf|Wago manual]] p.82ff and [[man>​bootptab]] See also: [[http://​www.wago.com/​wagoweb/​documentation/​750/​ger_manu/​841/​m084100d.pdf|Wago manual]] p.82ff and [[man>​bootptab]]
  
 ===== Libmodbus == ===== Libmodbus ==
 +==== Usage / Doc  ==
 +
 +See http://​libmodbus.org/​site_media/​html/​libmodbus.html
 +
 ==== Installation == ==== Installation ==
 +
 +Download the [[http://​github.com/​downloads/​stephane/​libmodbus/​libmodbus-3.0.2.tar.gz|source]] and use the [[http://​think-deep.com/​becki/​slackbuilds/​pack.php?​n=libmodbus|Slack build script]].
 +
 +<note warning>​The rest of this section is obsolete</​note>​
  
 Note: You could get the latest devel release with ''​git clone http://​github.com/​stephane/​libmodbus.git'',​ but this has no ''​configure''​ script, so we use the lataest stable release instead. Note: You could get the latest devel release with ''​git clone http://​github.com/​stephane/​libmodbus.git'',​ but this has no ''​configure''​ script, so we use the lataest stable release instead.
  
-Download v 2.0.3 from [[http://copyleft.free.fr/wordpress/​index.php/​libmodbus/|here]] and do the usual ''​./​confiure;​ make; su; make install;''​. This installs the following objects to ''/​usr/​local/'':​+Download v 2.0.3 from [[http://libmodbus.org/download/|here]] 
 + 
 +Libmodbus has the unpleasant behaviour, that it prints error messages to ''​stdout''​ instead of ''​stderr''​. If you plan to build your application like a filter which commuicates over ''​stdin / stdout''​ to the world, than you will get problems, in that libmodbus may interfere your protocoll or whatever with error messages. Therfore we patch the source a little bit and are writing error messages to ''​stderr''​ instead of ''​stdout''​. Look for the function ''​error_treat''​ in ''​modbus/​modbus.c''​ and replace the ''​printf''​ function with ''​fprintf'':​ 
 + 
 +<code c> 
 +static void error_treat(modbus_param_t *mb_param, int code, const char *string) 
 +
 +        printf("​\nERROR %s (%d)\n",​ string, code); 
 +</​code>​ 
 + 
 +<code c> 
 +static void error_treat(modbus_param_t *mb_param, int code, const char *string) 
 +
 +        fprintf(stderr,​ "​\nERROR %s (%d)\n",​ string, code); 
 +</​code>​ 
 + 
 +Now do the usual ''​./​confiure;​ make; su; make install;''​. This installs the following objects to ''/​usr/​local/'':​
  
   lib/​libmodbus.so   lib/​libmodbus.so
Zeile 44: Zeile 90:
   include/​modbus/​modbus.h   include/​modbus/​modbus.h
  
-Then do ''​ldconfig''​ to update the library system info. +Then do ''​ldconfig''​ to update the library system info. 
 + 
 + 
 +===== Wago Adressing in Libmodbus == 
 +==== Bit-based access to digital IOs == 
 + 
 +  * Bit-based function codes are # 1,2,5,15 
 +  * The first digital input and output bits have both address 0 
 +  * The 2nd digital input and output bits have both address 1 
 +  * Addressing of inputs and outputs are independent (ie. there exists DI 0 and DO 0) 
 +  * Each input/​output bit consumes one member of the ''​uint8_t dest[]''​ array. I.e. each bit consumes one byte. 
 + 
 +==== Register-based access to analog IOs == 
 + 
 +  * Register-based (16bit) function codes are # 3,4,6,16 
 +  * The first analog input and output register have both address 0 
 +  * Contrary to the Wago manuals the 2nd analog input and output registers have address 1 :!: 
 + 
 +==== Register-based access to digital IOs ==
  
 +  * Access to digital inputs and outputs is also possible with the register-based function codes
 +  * Digital input and output addresses are automatically appended after the analog addresses. This means the digital addresses are dependend of the number of the analog devices.
 +  * Each digital IO consumes on //bit// in the ''​uint16_t dest[]''​ array
becki/linux/modbus.1279813593.txt.gz · Zuletzt geändert: 2010-07-22 15:46 von becki

Impressum - Datenschutzerklärung