GithubHelp home page GithubHelp logo

Extended modbus library for Siemens PLC's.

Slava Ukraine!
For Rusian users of the library:
Don't belive the propaganda of your goverment! Sosial and foreign media has been blocked in Rusia to hide war crimes that is happening. There is no peaceful military operation, there is only death and destruction, so far by july 2023 more than hundreds of thousands people has been killed. If you use sosial media platform like Tiktok, you get totalt different videos, compared to Ukraine users. I know it's hard to belive a reality that it's so far from what get presented everyday to you in Rusian media. But please contact me if you like vpn-connection access to foreign media, wikipedia, youtube, etc. The rest of world isn't against the Russian people, but we condemn the regime that is controlling Russia.

For all other users of the library, please consider make a monthly donation to a organisation that help rebuild Ukraine. The devastation is immense and the reconstruction will take decades.

Extended modbus library for Siemens PLC's.

The library makes it possible to split a program into reusable function blocks for each modbus device. This blocks can later be reused and combined in new programs. Together with a clean and simple api this speed up devopment significantly. Other features include:

  • Reduce idle time, by skipping queries that has led to recurring timeouts, retries will be done occasionally.
  • More then 70 ready to use device profiles (Station blocks), similarities to profibus gsd-files.
  • Logging features for development and debugging.
  • Extend on the modbus blocks that comes along in TIA-portal, it isn't an attempt to reinvent the wheel, but to extend functionality.
  • Help share the bus efficient between the devices.
  • Data can be stored with optimized data access on.
  • Use little memory.
  • Free under the MIT-license.
// A simple modbus RTU example. 
// (Support for modbus TCP also available)

#mb_rtu1200_ctrl(hardware_id := "Local~CB_1241_(RS485)", 
                baud := 19200, // bps                
                mb_query := #mb_query ); 

// Use mb_rtu1500_ctrl for S7-1500 PLC's

#mb_query(mb_addr := 1,                  
          mode := #mb_query.c.read.input_reg, 
          data_addr := 123,                      
          data_ptr := #resault_data_1);                   

#mb_query(mb_addr := 1,                 
          mode := #mb_query.c.read.holding_reg, 
          data_addr := 456,                            
          data_ptr := #resault_data_2);
		  
// - The result will be stored in the connected variable 
//   of data_ptr. The variable can be any data types, 
//   including arrays and udt's.
// - Length will be calculated automatically. 
// - The library will take care of executing the 
//   queries, one by one. 
// - Queries belonging to one device can be grouped together 
//   into one FB, creating a reusable station block.

Station block (SB) example

This six lines of code bellow and the variable definition (not shown) is all that is needed to read the data from a MAG 6000 device.

// Siemens - SITRANS MAG 6000

"mb_station_block_header"(sb := #sb, mb_query := #mb_query);
#mb_query.mb_addr := #mb_addr;
	
#mb_query.mode := #mb_query.c.read.holding_reg;
#mb_query(data_addr := 2999, data_ptr := #flow);
#mb_query(data_addr := 3016, data_ptr := #totalizer);
	
"mb_station_block_footer"(sb := #sb, mb_query := #mb_query);

// - #flow is a struct that actually contain two variables. 
// - #mb_addr is a input 
// - #mb_query is a inOut on the block. 
// - #sb is a udt that come along with the library, with 
//   common information for the device.

Another station block example

This SB can be combined with the one above, and any others in the library. It's also fine to have more instaces of one SB in the same program. New queries can be added without changing anything in existing program.

// Telemecanique (Schneider) - Altivar 21 inverter - VFD (AC-drive)

"mb_station_block_header"(sb := #sb, mb_query := #mb_query);
#mb_query.mb_addr := #mb_addr;

#mb_query.mode := #mb_query.c.read.holding_reg;
#mb_query(data_addr := 16#fd00, data_ptr := #read1);
#mb_query(data_addr := 16#fe45, data_ptr := #read2);
#mb_query(data_addr := 16#fe91, data_ptr := #read3_alarm);
#mb_query(data_addr := 16#fe79, data_ptr := #read4_alarm2);
#mb_query(data_addr := 16#FC90, data_ptr := #read5_trip_code);

#write1.ref := REAL_TO_UINT(#ref * 100);
#write1.cmd.x10_Run := #ref <> 0;
#mb_query.mode := #mb_query.c.write.holding_reg;
#mb_query(data_addr := 16#fa00, data_ptr := #write1);

"mb_station_block_footer"(sb := #sb, mb_query := #mb_query);

Modbus tcp example

#ip[1] := 192;
#ip[2] := 168;
#ip[3] := 1;
#ip[4] := 2;
#mb_tcp_ctrl(interface := "Local~PROFINET_interface_1",
             conn_id := 123,
             ip_addr := #ip,
             tcp_port := 502,
             timeout := T#2s,
             mb_query := #mb_query);

#mb_query(mb_addr := 255,
          mode := #mb_query.c.read.holding_reg,
          data_addr := 123,
          data_ptr := #resault_data_1);

#mb_query(mb_addr := 255,
          mode := #mb_query.c.read.holding_reg,
          data_addr := 456,
          data_ptr := #resault_data_2);
	  
// - Unlimited number of queries can be added.
// - The same station blocks created for rtu can also be used 
//   for tcp. This is convenient when a tcp-rtu-gateway is used.
#telemecanique_altivar(mb_addr := 255, mb_query := #mb_query);

Ola Bjørnli's Projects

console.table icon console.table

Adds console.table method that prints an array of objects as a table in console

rexhip icon rexhip

Extended modbus library for Siemens PLC's.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.