> For the complete documentation index, see [llms.txt](https://huang-jason.gitbook.io/automation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://huang-jason.gitbook.io/automation/mcio-1-2.md).

# MCIO 1-5

## Motion Control & IO

### Deterministic

No matter how fast is the bus, two parallel devices receive the same risining edge at identical time.

### 0. Remote login

```
$ mstsc
```

### 1. Networking

141.52.97.224

administrator

**1. 1. Create project**

`File -> new -> project -> TwinCat XAE prject(XML format) -> input file name & ok`

`Solution Explorer -> double click "system"-> choose target -> search(Ethernet) -> broadcast search OR enter ip`

set `address info` to `IP Address`

Add route & login

**1. 2. PLC project**

`Solution Explorer -> TwinCat -> SPS -> (right click) add new item -> standard plc project -> enter name: code_X-> OK`

`Solution Explorer -> TwinCat -> SPS -> code_X -> POUs -> MAIN (PRG)`

```
---------------------------------
PROGRAM MAIN
VAR
    beat : DINT;
END_VAR
---------------------------------
beat := beat + 1;
---------------------------------
```

`input_code -> (Header) TwinCAT -> active configuration -> login -> start`

```
start = F5
stop = shift F5
```

## 2. TWINCAT IO

#### create IO

`Solution Explorer -> TwinCat -> I/O -> device -> add new element -> select EtherCAT -> EtherCAT master -> OK`

#### Assign hardware

* If the device are connected to CX5140 directly, then they are PCI.
* If the device are connected to CX5140 by LAN, then they are LAN.

`Solution Explorer -> TwinCat -> SYSTEM -> select target -> click CX35CD`

`Click TwinCat/IO/Devices/Device 1(EtherCAT) -> adapter -> click SEARCH -> PCI!!!-> click BLUE CONFIG MODE`

`Right click Device 1(EtherCAT) -> scan`

Then, you will find device

#### Code

```
---------------------------------
PROGRAM MAIN
VAR
    heartbeat : BYTE;

    one   AT %Q* : BOOL;
    two   AT %Q* : BOOL;
    three AT %Q* : BOOL;
    four  AT %Q* : BOOL;

    prox  AT %I* : BOOL;

END_VAR
---------------------------------
heartbeat := heartbeat + 1;

IF prox = TRUE THEN
    one   := heartbeat MOD 2 = 0;
    two   := heartbeat MOD 4 = 0;
    three := heartbeat MOD 8 = 0;
    four  := heartbeat MOD 16 = 0;
ELSE
    one   := FALSE;
    two   := FALSE;
    three := FALSE;
    four  := FALSE;    
END_IF
---------------------------------
```

build solution!!

#### Parts

EL2008 output

<https://www.beckhoff.com/english.asp?ethercat/el2008.htm>

EL1819 digital input

<https://www.beckhoff.com/english.asp?ethercat/el1819.htm>

#### Bind IO to variable

`click channel N -> right-click output -> change link -> select variable`

### Hardware changes - Rescan

`Right click Device 1(EtherCAT) -> scan -> copy before / after -> activate configuration`
