← Back to Robot Communication series
🤖
Basics
Intro · Prereq: none

01. Setting Up the Practice Environment

This track reproduces HIWIN industrial-robot communication on a single PC, with no real robot. Lesson 1 installs Python·pymodbus·pyserial, explains the _shared/ library that holds the large simulators, and confirms "ready" with a self-check script. Get this right once and the next 8 lessons run smoothly.

robot commHIWINpymodbuspyserialsimulatorsetup
Duration
~30 min – 1 hour
Level
📊 Beginner
Prerequisite
🎯 None
OUTCOME
Install Python·pymodbus·pyserial, understand the _shared/ bootstrap, and confirm the practice ports (1502/1503/6000) and a passing self-check.

What you'll learn

  • 1Install Python · pymodbus · pyserial and verify versions
  • 2Understand how each lesson's main.py loads the _shared/ modules via a bootstrap
  • 3Explain the practice ports (robot 1502 / gripper 1503 / vision 6000) and why 502 is avoided
  • 4Run the environment self-check and confirm "pass"

Introduction

This is a **practice-first, 9-lesson** course based on the HIWIN robot communication manual. With no real robot·PLC·gripper·vision, you can follow the whole thing on **one PC** — the large simulators are provided as PC programs. The audience is automation engineers (with basic programming, new to industrial comms·Modbus).

Key concepts

1) What the simulators replace

Real deviceThis track's stand-in
Robot (Modbus slave)_shared/robot_server_sim.py
XEG electric gripper_shared/gripper_sim.py
Upstream PLC/master_shared/modbus_master.py
Vision/upstream (TCP)_shared/tcp_echo_server.py
RS-232 cablecom0com virtual COM ports (lesson 4)

2) The _shared/ library & bootstrap

Rather than copying the large simulators per lesson, they live once in lecture/_shared/. Simulators run standalone in a separate terminal (you connect over TCP), while helpers like word_tools·modbus_master are imported. Each lesson file sits deep in the tree, so it walks up looking for _shared/.

python
import os, sys
_d = os.path.dirname(os.path.abspath(__file__))
while _d != os.path.dirname(_d) and not os.path.isdir(os.path.join(_d, "_shared")):
    _d = os.path.dirname(_d)
sys.path.insert(0, os.path.join(_d, "_shared"))

3) Practice ports and avoiding 502

RoleSimulatorPractice portReal
Robotrobot_server_sim.py1502502
Grippergripper_sim.py1503502
Visiontcp_echo_server.py6000any
ℹ️

On Windows, ports below 1024 (like 502) may need admin rights, so practice uses 1502/1503.

Core example

Self-check: verify Python version·dependencies·shared-module import and conversion values at once.

python
from word_tools import split_word, combine_word, ieee754_encode
a = split_word(90000)                 # -> (24464, 1)
assert combine_word(*a) == 90000
assert ieee754_encode(10.5) == 1093140480
print("environment check passed ✅")
bash
# install deps (once)
cd lecture/_shared
python -m pip install -r requirements.txt
set PYTHONUTF8=1            # PowerShell: $env:PYTHONUTF8=1 (avoid mojibake)

cd ../01_intro/01_setup
python src/setup_check/main.py   # last line "passed ✅" means you're ready

Common mistakes

Q. ModuleNotFoundError: No module named 'pymodbus'

A. Dependencies aren't installed, or installed on a different Python. Install on the current Python: python -m pip install -r ../../_shared/requirements.txt.

Q. Korean text shows as ???? or garbled.

A. Windows console default encoding (cp949). Run set PYTHONUTF8=1 (PowerShell: $env:PYTHONUTF8=1) first.

Q. ModuleNotFoundError on from word_tools import ...

A. The _shared/ bootstrap is missing, or the file was moved out of place. Confirm the bootstrap is at the very top of main.py.

Summary

  • You're ready to simulate robot·gripper·vision·master on a PC alone
  • Shared code lives in _shared/; each lesson loads it via the bootstrap
  • Practice ports: 1502 (robot) / 1503 (gripper) / 6000 (vision)
  • Protect console Korean with PYTHONUTF8=1

Exercises

  1. Run setup_check/main.py and confirm "passed ✅" with exit code 0
  2. Explain why split_word(90000) is (24464, 1) using base 65536
  3. Verify the ieee754_encode(10.5) and combine_word round-trips by hand
Example code / lecture materials

All lecture materials and example code (with simulators, homework, and answers) are openly available on GitHub.

View on GitHub ↗