Realization of Siemens 1200 PLC positioning control case based on ModbusTCP

1. Citation

In the last article, we mainly explained the wiring part and the PLC program part of "Siemens 1200 PLC practical positioning control program case". [ Public account dotNet industrial control host computer: thinger_swj]

[C# host computer] Siemens 1200PLC practical positioning control program case

This article mainly elaborates on the development of the upper computer part.

2. Project communication variable table

Modbus address PLC address Variable name instruction manual
40001 DB1.DBW0 Forward jog 1=True,0=False
40002 DB1.DBW2 Reverse jog 1=True,0=False
40003 DB1.DBW4 Relative motion 1=True,0=False
40004 DB1.DBW6 Absolute movement 1=True,0=False
40005 DB1.DBW8 Back to origin 1=True,0=False
40006 DB1.DBW10 System reset 1=True,0=False
40007 DB1.DBW12 System pause 1=True,0=False
40008-40009 DB1.DBD14 Jog speed Floating point
40010-40011 DB1.DBD18 Relative velocity Floating point
40012-40013 DB1.DBD22 relative distance Floating point
40014-40015 DB1.DBD26 Absolute speed Floating point
40016-40017 DB1.DBD30 Absolute position Floating point
40018-40019 DB1.DBD34 Real-time location Floating point

 

3. Function development of host computer

  • First create a Windows Forms application project, the project name is thinger.com.MotionPro, and complete the UI interface construction according to the functions.

  • Develop ModbusTCP communication library by yourself or use an open source library. The library should have the functions of establishing connection, disconnecting, presetting registers, and reading registers. The open source Modbus communication library NModbus4 is used here, and the NModbus communication library is downloaded and installed through NuGet. [ Public account dotNet industrial control host computer: thinger_swj]

  • Establish connection and disconnection: Here, two functions of establishing connection and disconnection are realized by buttons, the code is as follows:

  • Real-time display of parameters: The parameters that need to be displayed in real-time include jog speed, relative speed, relative distance, absolute speed, absolute position and real-time position. Therefore, a timer needs to be started to read 12 registers starting from 40008 in real time. Then parse it into floating-point data, the code is as follows:

  • Relative position movement: Set the relative movement speed and relative movement distance to realize the relative movement of the motor. The relative movement only needs to write 1 and then 0 to the relative movement variable 40003.

  • Absolute position movement: Set the absolute movement speed and absolute movement position to realize the absolute movement of the motor. The absolute movement only needs to write 1 and then 0 to the absolute movement variable 40004.

  • Jog movement mode: set the jog movement speed, press and hold the forward jog or reverse jog to realize the jog movement of the motor, the code is as follows:

  • Back to origin mode: Click back to origin, you can control the object to return to the origin position and stop. To return to origin, you only need to write 1 and then 0 to the back to origin variable 40005.

  • Motion pause and reset related functions.

  • Parameter setting: The parameters that need to be set include jog speed, relative speed, relative distance, absolute speed, and absolute position. Here, the set floating point number is converted into ushort array, and then realized by calling WriteMultipleRegisters, taking jog speed setting as an example , The code is as follows:

Guess you like

Origin blog.csdn.net/xiketangAndy/article/details/108408211