EST. 2026 — Notes from real server work SYSADMIN · SECURITY · AI · DIRECTADMIN Issue 01
THE SYSADMIN ALMANAC
Home / Hardware / I Planned to Move Valve Wires That Were Never on the DQ Card
Hardware

I Planned to Move Valve Wires That Were Never on the DQ Card

by Ton-Or ·4 Dec 2026·11 min read
I Planned to Move Valve Wires That Were Never on the DQ Card

An address in a tag table only tells me where a bit sits in the process image. It does not tell me whether the endpoint is an individual copper wire or an entire device on fieldbus. Moving those two things involves very different work.

1-minute summary

Symptom / problem
A valve move was designed from the tag table, but the valves sit on a fieldbus terminal, not on card wiring.
Who should read
Anyone about to relocate I/O in an existing Siemens PLC project.
Fix in short
Dump the hardware configuration with Openness before designing, to see whether each address is a single wire or a device on a fieldbus.
Jump to steps

I took on a job to move workpiece detection sensors and pneumatic cylinder valves from a central PLC to the PLC at each station. I finished the design, wrote the program, tested it on a simulator, and delivered the files. On the last day, the client asked for actual wiring diagrams before and after the move. I wrote a script to extract the hardware configuration from the project to build the diagrams, and found that the output addresses for all 4 valves were not channels on a DQ card, as I had believed all along. They belonged to a valve terminal connected over PROFINET. There had never been individual wires to move. This article explains where I went wrong, what the dump script looks like, and how to find the terminals on the input side, where there really are wires.

The diagrams and terminal numbers in this article are examples

The addresses, terminal numbers, valve positions, and IP addresses in this article have been replaced with example values, and the terminal formula applies only to module models whose manuals specify this terminal layout. Moving wires and outputs on an actual machine requires the electrical and control engineers responsible for that machine to review the drawings, inspect the site, and approve the work before it starts. Diagrams generated from project files cannot replace tracing the actual wiring.

Designing from the tag table alone

At the start of the job, I opened the central PLC's tag table and saw two groups that needed moving. The workpiece detection sensors were at %I addresses on a DI card, while the pneumatic cylinder's Up and Down valves were in a certain %Q range. I immediately assumed that both groups used 24 V wires connected to cards: sensors into the DI card, valves out of the DQ card. Moving them would mean disconnecting wires from the central PLC's cards and connecting them to the station PLC's cards.

What I believed during the designtag table%I and %Q->My assumption24 V wires to cards->Write programDrive station DQ->DeliverBefore checking hardware

The program I delivered therefore drove the station's DQ outputs, which would be correct if the endpoints were solenoids with their own wires. No step in compilation or simulator testing would tell me this assumption was wrong, because the simulator knows nothing about wires. It only knows bits.

My mistaken assumption was that an address could tell me the hardware type: %Q must mean an output card. That is not true. The PLC's process image is a shared area where everything reserves its own range. Rack cards, PROFINET devices, inverters, and valve terminals all get addresses that look exactly the same.

Dumping project hardware with Openness

The information about which address range belongs to what is in the project's hardware configuration, which I could inspect visually in TIA Portal. But with several PLCs and dozens of devices in a project, clicking through them one at a time makes it easy to miss things. I wrote a script to walk the entire tree through V15.1 Openness from Windows PowerShell 5.1 and print it as text, one device per line.

# Windows PowerShell 5.1 บนเครื่องที่เปิด TIA Portal V15.1 กับสำเนาโครงการอยู่ (อ่านอย่างเดียว)
$dll = 'C:\Program Files\Siemens\Automation\Portal V15_1\PublicAPI\V15.1\Siemens.Engineering.dll'
[Reflection.Assembly]::LoadFrom($dll) | Out-Null
$tia = [Siemens.Engineering.TiaPortal]::GetProcesses()[0].Attach()
$prj = $tia.Projects[0]
$log = 'C:\Projects\hw_dump\Work_A.txt'
New-Item -ItemType Directory -Force -Path (Split-Path $log) | Out-Null
Set-Content $log "PROJECT $($prj.Name)" -Encoding UTF8

function Item($it, $indent) {
    $pos = ''; try { $pos = $it.PositionNumber } catch {}
    $adr = @()
    try { foreach ($a in $it.Addresses) { $adr += "$($a.IoType) $($a.StartAddress) len $($a.Length)bit" } } catch {}
    $net = @()
    try {
        $type = [Siemens.Engineering.HW.Features.NetworkInterface]
        $ni = $it.GetType().GetMethod('GetService').MakeGenericMethod($type).Invoke($it, $null)
        if ($ni) {
            foreach ($n in $ni.Nodes) {
                $net += "$($n.Name)=$($n.GetAttribute('Address'))"
                try { $net += "pnname=$($n.GetAttribute('PnDeviceName'))" } catch {}
            }
        }
    } catch {}
    $line = '{0}[{1}] {2} | {3} | {4} | {5}' -f $indent, $pos, $it.Name, $it.TypeIdentifier, ($adr -join '; '), ($net -join ' ')
    Add-Content $log $line -Encoding UTF8
    foreach ($child in $it.DeviceItems) { Item $child ($indent + '  ') }
}
function Dev($d, $where) {
    Add-Content $log "DEVICE $where $($d.Name) | $($d.TypeIdentifier)" -Encoding UTF8
    foreach ($i in $d.DeviceItems) { Item $i '  ' }
}
function Grp($g, $where) {
    foreach ($d in $g.Devices) { Dev $d $where }
    foreach ($s in $g.Groups) { Grp $s "$where/$($s.Name)" }
}

foreach ($d in $prj.Devices) { Dev $d 'main' }
foreach ($g in $prj.DeviceGroups) { Grp $g "group:$($g.Name)" }
try { Grp $prj.UngroupedDevicesGroup 'ungrouped' } catch { Add-Content $log "no ungrouped: $($_.Exception.Message)" }
foreach ($s in $prj.Subnets) {
    Add-Content $log "SUBNET $($s.Name) | nodes: $(($s.Nodes | ForEach-Object { $_.Name }) -join ',')" -Encoding UTF8
}

There are three things to know before using this script.

  1. It must traverse all three locations: the project's Devices, DeviceGroups recursively through every level, and UngroupedDevicesGroup. The last one matters most because many fieldbus devices imported from GSD files end up there. Traversing only Devices will miss them entirely.
  2. Every property access needs a try/catch because different item types have different properties. Some have no slot number, some have no address, and some have no network interface. Without the wrapper, the script stops at the first item missing a property.
  3. PowerShell cannot call .NET generic methods directly, so requesting the NetworkInterface service requires going through MakeGenericMethod.

The address Length comes out in bits. A 32-channel card returns 32; a device reserving 5 bytes returns 40. I have to divide by eight when comparing it with byte ranges in the tag table. This script only reads and does not change anything in the project, but I still ran it against a copy rather than the original file.

What the dump revealed: the valves were on a valve terminal

The result was a text file with one item per line. The extract below includes only the relevant lines. I have replaced all device names, model codes, and IP addresses with generic values.

PROJECT Work_A
DEVICE main Main_PLC | <รหัสรุ่น CPU>
  [1] PLC_1 | <รหัสรุ่น CPU> |  | X1=192.168.0.1 pnname=main-plc
  [2] DI_32_1 | <รหัสรุ่นการ์ด DI 32 ช่อง> | Input 8 len 32bit |
  [4] DQ_32_1 | <รหัสรุ่นการ์ด DQ 32 ช่อง> | Output 12 len 32bit |
DEVICE ungrouped ValveTerminal_1 | <GSD id ของ valve terminal>
  [0] ValveTerminal_1 | <GSD id> |  | X1=192.168.0.20 pnname=valve-terminal-1
  [1] Valves | <GSD id ของโมดูลวาล์ว> | Output 120 len 32bit |
SUBNET PN/IE_1 | nodes: X1,X1

The line that changed the entire job was the second-to-last one. The outputs starting at QB120, with a length of 32 bits, span QB120 through QB123, a total of 4 bytes. They did not belong to a card in the rack. They belonged to a device in the ungrouped group, connected over PROFINET, and that device was a valve terminal: a pneumatic manifold with a row of valves that receives commands for the whole assembly over fieldbus. The 4 pneumatic cylinder valves I intended to move were at positions 2, 3, 5, and 7 on this manifold.

4 valvesAssumed to have wires to a card
4 bytesValve terminal output range
0 wiresIndividual valve wires available to move
6 pointsSensors with actual wires on the DI card

Physically, this meant that the connection from the PLC to the valves consisted of a single network cable and pneumatic tubing. No individual copper wires ran back to the cabinet from each valve. Moving valve wires to the station's card therefore made no sense, because there were no wires to disconnect in the first place.

The effect on the delivered work: option A and option B

The program I delivered drove the station's DQ outputs. It was not inherently wrong, but it depended on hardware that did not yet exist. I stated this openly in the report, with two options for the site team to decide between.

Option A

Install separate solenoid valves at each station

Add new valves at the stations, run wires from each station PLC's DQ card to each valve, and install new pneumatic tubing. This matches the program files already delivered and requires no new program, but adds hardware and pneumatic work that must be assessed separately.

Option B

Keep the valves on the manifold and move only the sensors

The valves stay where they are, and the central PLC continues to command the valve terminal over fieldbus as before. Move only the 6 sensor connections to the station cards. This adds no pneumatic work, but requires a different program. The delivered files cannot be used directly.

I did not choose for them, because the deciding factors were on site, such as why they wanted the move in the first place, the available installation space, and the budget for pneumatic work. What I could do was clearly explain which option the delivered files supported and what extra work the other option would require.

Why I stated it plainly in the report

If I had not been asked for a wiring diagram, this would have surfaced when a technician opened the cabinet and could not find the valve wires, which is the most expensive point to discover it. Recording where the original assumption was wrong, how I discovered it, and which files it affected let the recipient make a decision before ordering parts and stopping the machine.

The inputs had real wires: finding terminals with the module formula

For the sensors, the dump confirmed a 32-channel DI card in slot 2, starting at IB8. These were real wires that could be moved. The next question when drawing the wiring diagram was which terminal on the card's front connector each sensor used. The tag table only gave an address such as I9.3, not a terminal number.

The 32-channel digital module with a 40-pin front connector has its terminals arranged in four groups of 10, according to the module manual. Channels 0 through 7 are on terminals 1 through 8, channels 8 through 15 on terminals 11 through 18, channels 16 through 23 on terminals 21 through 28, and channels 24 through 31 on terminals 31 through 38. As a formula, the terminal number equals the byte index within the module multiplied by 10, plus the bit number, plus 1.

def terminal(addr, module_start_byte):
    """'I9.3' บนโมดูลที่เริ่ม IB8 -> ขั้ว 14 (โมดูล 32 ช่อง คอนเนกเตอร์หน้า 40 ขา)"""
    byte, bit = (int(x) for x in addr.lstrip('%IQ').split('.'))
    index = byte - module_start_byte            # ลำดับไบต์ในโมดูล 0..3
    if not (0 <= index <= 3 and 0 <= bit <= 7):
        raise ValueError(f'{addr} ไม่อยู่ในโมดูลที่เริ่ม byte {module_start_byte}')
    return index * 10 + bit + 1

for a in ('I8.0', 'I8.4', 'I9.2', 'I9.3', 'I10.5', 'I11.0'):
    print(a, '-> ขั้ว', terminal(a, 8))
# I8.0 -> 1, I8.4 -> 5, I9.2 -> 13, I9.3 -> 14, I10.5 -> 26, I11.0 -> 31
address Byte index Bit Calculation Terminal
I8.4 0 4 0 x 10 + 4 + 1 5
I9.3 1 3 1 x 10 + 3 + 1 14
I10.5 2 5 2 x 10 + 5 + 1 26
I11.0 3 0 3 x 10 + 0 + 1 31

The 6 sensor connections in this job were therefore on terminals 1, 5, 13, 14, 26, and 31 of the DI card in slot 2. The module_start_byte value must come from the dump, not a guess based on the address, because a module does not necessarily start at byte 0. This formula must also be checked against the manual for the actual module model every time. Different module types have different terminal layouts.

32-channel DI, 40-pin connectorTerminal = byte index x 10 + bit + 1IB812345678910IB911121314151617181920IB1021222324252627282930IB1131323334353637383940valve terminal on PROFINET8 valve positions on one manifold12345678QB120-QB123 = 32 bitAll controlled over fieldbusNo individual wires6 sensor wires can be movedTerminals 1 5 13 14 26 314 valves, no wires to moveA New station valves B Keep on manifold
On the left are the DI card terminals, one byte per row. The red cells are the 6 sensor connections with actual wires that can be moved. The solid cells are terminals that are not signal channels. On the right is the valve terminal, which receives all 4 bytes of commands over PROFINET. The 4 valves intended for the move have no individual wires.

Drawing wiring diagrams from the dump and checking them visually before delivery

With the dump and terminal formula available, I wrote another Python script to read the dump file and generate SVG diagrams: a 40-pin connector face with the terminals to move highlighted, the row of valves on the manifold, and a wire-by-wire migration table, all embedded in an HTML report. The advantage of generating from the dump is that a typing error cannot make the diagram disagree with the project. If the project changes, I regenerate it.

After every generation, I rendered it to an image using headless Chrome and opened it for a visual check first. I do not deliver something I have not seen.

$chrome = 'C:\Program Files\Google\Chrome\Application\chrome.exe'
& $chrome --headless --disable-gpu --window-size=1600,1100 `
    --screenshot='C:\Projects\report\wiring.png' 'file:///C:/Projects/report/wiring.html'

This visual check caught one bug that no tool reported. Half the image was missing: the upper half looked normal, and the lower half was blank. There were no errors anywhere. The cause was that my generator wrote some SVG attributes without quotation marks, followed by />.

# ผิด: ค่า attribute ไม่มีเครื่องหมายคำพูด ตัว / ถูกกินเข้าไปเป็นส่วนของค่า
bad = f'<rect x={x} y={y} width={w} height={h}/>'

# ถูก: ใส่เครื่องหมายคำพูดทุกค่า
good = f'<rect x="{x}" y="{y}" width="{w}" height="{h}"/>'

In the incorrect version, the HTML parser read the height value as a number followed by a slash, so the tag was not closed. Everything written after it became a child of that rect, which was not drawn. As a result, the image disappeared from that point onward without a warning. If I had sent the file without rendering it first, the recipient would have received a diagram with only its upper half. I wrote separately about making SVG drawings that technicians can actually use in the article on true-scale SVG panel drawings. The report submitted for review on this job ran to several landscape A4 pages.

What the project file cannot tell me

The dump helps a lot, but it has limits. The project file only knows what someone configured in the engineering software. It does not know what is actually inside the cabinet. I included this list in the report so nobody would read the diagram and assume it was complete.

Five things to check on site

First, the power supply and common terminals for each channel group. Second, the actual wire colors and numbers. Third, the terminal blocks between the card and the devices. Fourth, cable routes and lengths. Fifth, whether the spare I/O channels at the destination are actually free. None of these five things is in the project file. A diagram generated from the dump can only show which signal should be on which terminal according to the configuration.

Question tag table hardware dump On-site check required
What address is this bit at? Yes Yes -
Does this address belong to a card or a fieldbus device? No Yes -
Which slot is it in, and what is its model code? No Yes -
Which terminal number is it on? No Yes, with the module manual Confirm
Wire colors, intermediate terminals, cable routes No No Must check
Are the spare channels actually free? No No Must check

I had designed the entire I/O migration from a table that could answer only the first row's question, then assumed the answer to the second row myself. The correct order is to run a hardware dump before designing, every time. It immediately tells me whether the things to be moved are wires or devices on fieldbus. If I had done this on the first day, the choice between A and B would have come up before I wrote the program, not after I delivered the files.

I consider this a mistake in the order of the work, not a tool failure. The information was in the project all along; I just had not looked at it. If you are about to move I/O between PLCs, try running a dump first, especially on the often-overlooked ungrouped group. If the terminal formula does not match the module model you use, I will come back and update it later.

Hit something like this? Stuck somewhere?

Come trade notes on the LinuxThai board

→ Continue on the board

Comments 0

No comments yet — be the first