Skip to content

Codesys Platform - Usage Guide (Example PLC: GCAN302)


1. Wiring Instructions

1.1 Servo Wiring

Servo Wiring

1.2 RS485 Servo Wiring

RS485 Servo Wiring

1.3 UC04 Wiring

UC04 Wiring

2. Program Instructions

2.1 Add PLC Serial Port

Add Serial Port

2.2 Serial Initialization (Adjust instruction blocks based on your PLC controller)

Serial Initialization

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.

Serial Write

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

Serial Send

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

Serial Receive

2.6 Function Block and Protocol Mapping

Protocol reference for Fashion Star bus servo communication:

https://wiki.fashionstar.com.hk/uartbasic/uart_rs485_protocols/

Function Block and Protocol Mapping

3. Importing Library Files

  1. In Codesys, open the Library Manager, click Library Repository, then install FB libraries.
    Library Import 1
  2. After installation, add the FB libraries you just installed.
    Library Import 2
  3. After adding successfully, you can invoke these library files.
    Library Import 3

4. Function Block Description

4.1 Angle Control

  1. ID: servo ID

  2. Angle: target servo angle (3600 = 360.0°)

  3. Interval: time to reach target angle (3000 = 3s)

  4. AccInterval: acceleration time

  5. DecInterval: deceleration time

  6. Power: output power

Note: update the packet byte length for the corresponding command when sending via serial port.

Angle Control

 

4.2 Angle Readback

  1. ID: servo ID
    Angle Readback

 

4.3 Turn Counter Reset

  1. ID: servo ID
    Turn Counter Reset

 

4.4 Home Position Set

  1. ID: servo ID
    Home Position Set

 

4.5 Damping Mode

  1. ID: servo ID
  2. Power: damping output power (mW)
    Damping Mode

 

4.6 Communication Test

  1. ID: servo ID
    Communication Test

 

4.7 Async Commands

  1. Start async: fixed command, use directly.

  2. End async:

State: 0 -- execute immediately after async ends; 1 -- cancel execution after async ends.

Async Start
Async End

 

4.8 Data Monitoring

  1. ID: servo ID
    Data Monitoring

 

4.9 Stop Rotation (Three Modes: Release / Hold / Damping)

  1. ID: servo ID
  2. Power: output power (mW)
    Stop Rotation - Release
    Stop Rotation - Hold
    Stop Rotation - Damping