Codesys Platform - Usage Guide (Example PLC: GCAN302)
1. Wiring Instructions
1.1 Servo Wiring
1.2 RS485 Servo Wiring
1.3 UC04 Wiring
2. Program Instructions
2.1 Add PLC Serial Port
2.2 Serial Initialization (Adjust instruction blocks based on your PLC controller)
2.3 Serial Data Write (via Function Block Library)
1) 0 ------- Servo ID
2) 3600 -- Target angle 360.0°
3) 3000 -- Reach target in 3000ms (3s)
4) 500 ---- Acceleration time 500ms
5) 500 ---- Deceleration time 500ms
Use function blocks to convert and pack the data into a custom send array.
2.4 Serial Data Send (Adjust instruction blocks based on your PLC controller)
1) Port: port number
2) TxData: send array
3) TxSize: send array length, i.e., packet byte length
2.5 Serial Data Receive (Adjust instruction blocks based on your PLC controller)
1) Port: port number
2) RxData: receive array
3) MaxSize: receive array length, i.e., response packet byte length
2.6 Function Block and Protocol Mapping
Protocol reference for Fashion Star bus servo communication:
https://wiki.fashionstar.com.hk/uartbasic/uart_rs485_protocols/
3. Importing Library Files
-
In Codesys, open the Library Manager, click Library Repository, then install FB libraries.
-
After installation, add the FB libraries you just installed.
-
After adding successfully, you can invoke these library files.
4. Function Block Description
4.1 Angle Control
-
ID: servo ID
-
Angle: target servo angle (3600 = 360.0°)
-
Interval: time to reach target angle (3000 = 3s)
-
AccInterval: acceleration time
-
DecInterval: deceleration time
-
Power: output power
Note: update the packet byte length for the corresponding command when sending via serial port.
4.2 Angle Readback
-
ID: servo ID
4.3 Turn Counter Reset
-
ID: servo ID
4.4 Home Position Set
-
ID: servo ID
4.5 Damping Mode
- ID: servo ID
-
Power: damping output power (mW)
4.6 Communication Test
-
ID: servo ID
4.7 Async Commands
-
Start async: fixed command, use directly.
-
End async:
State: 0 -- execute immediately after async ends; 1 -- cancel execution after async ends.
4.8 Data Monitoring
-
ID: servo ID
4.9 Stop Rotation (Three Modes: Release / Hold / Damping)
- ID: servo ID
-
Power: output power (mW)























