Troubleshooting
Weintek Free Protocol INPORT receive length and macro debug
Short answer
In EasyBuilder Pro Free Protocol Ethernet macros, INPORT takes the maximum receive buffer length in its third argument and writes the received byte count into its fourth argument. Passing zero as the third argument caps every read at zero bytes, so guard conditions on that variable never see incoming data and unguarded SetData calls overwrite HMI registers with empty buffers. Set the third argument to the buffer size, check the fourth argument before calling SetData, and verify runtime values with TRACE in EasyDiagnoser.

On this page
When an EasyBuilder Pro Free Protocol Ethernet macro calls INPORT with zero in the third argument, the HMI caps every read at zero bytes and ignores incoming TCP packets. The third argument defines the maximum byte count to read, while the fourth argument returns the actual number of bytes received. Fix the macro by passing the buffer size in the third argument, checking the fourth argument before calling SetData, and confirming live values with TRACE in EasyDiagnoser.
Why INPORT returns zero and overwrites LW registers #
Two separate faults occur when the third and fourth arguments of INPORT are swapped. First, initializing the third argument to 0 and treating it as the returned byte count tells the HMI to read at most zero bytes from "Free Protocol Server (Ethernet)". Even when an external TCP client transmits a valid message, the read length stays 0 and any condition testing that variable never executes.
Second, passing a constant such as 1 in the fourth argument as if it were a wait time breaks the receive guard. Because INPORT overwrites that fourth variable with the number of bytes actually read, any periodic macro that calls SetData without checking the fourth argument copies an empty buffer into "Local HMI" LW registers on idle scans, erasing the last valid payload.
Software build differences can also affect Free Protocol handling. The EasyBuilder Pro V6.09.01.671 release notes specifically record a Free Protocol update under item 12 alongside protocol driver changes, so confirm the installed build before assuming a hardware or network fault. When a project combines Free Protocol with standard PLC drivers, also check how many protocol drivers one HMI project can run to keep communication loads within panel limits.
Corrected Free Protocol INPORT macro structure #
The example below uses the documented EasyBuilder Pro macro identifiers macro_command main(), end macro_command, INPORT, SetData, TRACE, FILL, "Free Protocol Server (Ethernet)", "Local HMI", and LW. The local variables Response, RLength, and CRecvd are illustrative names declared with explicit types and initial values.
macro_command main()
char Response[20] = ""
short RLength = 20
short CRecvd = 0
INPORT(Response[0], "Free Protocol Server (Ethernet)", RLength, CRecvd)
if CRecvd >= 4 then
TRACE("CRecvd = %d", CRecvd)
SetData(Response[0], "Local HMI", LW, 0, 20)
end if
end macro_command
In this structure, RLength stays fixed at the buffer capacity so INPORT can read incoming bytes up to that limit, while CRecvd receives the actual byte count returned by the Ethernet port. SetData executes only when CRecvd reaches the minimum payload length. If incoming messages vary in length and trailing characters must be cleared, uncomment or add FILL(Response[0], 0, RLength) before INPORT. Similar strict argument-order behavior applies to Weintek macro recipe lookup functions.
Sizing the INPORT buffer and guard for a 20-byte TCP frame #
Inputs for this case come from a typical Free Protocol Ethernet receive macro configuration:
- Illustrative receive array capacity: 20 bytes (
char Response[20]). - Illustrative minimum valid payload threshold: 4 bytes.
- Illustrative timed macro execution interval: 5 seconds.
- Illustrative test traffic: a 12-byte TCP frame on an active scan, followed by 0 bytes on the next idle scan.
The rule is direct: set the third INPORT argument equal to the buffer capacity in bytes, capture the actual read count in the fourth argument, and allow SetData to write LW registers only when the fourth argument is at least the minimum valid payload length.
For the active scan, RLength is 20 bytes and the external client sends 12 bytes, so INPORT writes 12 into CRecvd. Testing the guard gives 12 >= 4, which is true, so SetData copies the 20-byte buffer into LW 0. On the next 5-second scan with no incoming TCP traffic, INPORT writes 0 into CRecvd. Testing the guard gives 0 >= 4, which is false, so the macro skips SetData.
The result is that the 12-byte payload latches cleanly into LW 0 and stays visible across subsequent 5-second idle cycles instead of disappearing. The decision is fixed by that threshold: keep the third argument at 20 bytes and block SetData whenever CRecvd is below 4 bytes. If the external device sends frames longer than the current buffer capacity, raise both the array declaration and RLength to match the longest expected packet before deployment.
Debugging macro execution with TRACE and EasyDiagnoser #
Verify the corrected macro in EasyDiagnoser using TRACE output rather than guessing from HMI screen tags. Place one TRACE statement immediately after INPORT to log CRecvd on every cycle, and keep a second TRACE inside the if block to confirm when SetData runs.
Prove the fix with two bench tests:
- Run the timed macro with no TCP client transmitting and confirm EasyDiagnoser prints
CRecvd = 0without triggering theSetDatatrace line, while existingLW0 values remain unchanged. - Transmit a 4-byte or longer TCP payload from the client and confirm EasyDiagnoser prints the exact received byte count and
LW0 updates with the new data.
Step-by-step verification and project download checklist #
- Verify the device string in
INPORTmatches"Free Protocol Server (Ethernet)"in the EasyBuilder Pro system parameters. - Set the third
INPORTargument to the buffer array length and initialize the fourth argument to0before each read. - Gate
SetDataon the fourth argument so idle scans never overwriteLWregisters with empty arrays. - Call
FILLbeforeINPORTwhen variable-length messages must clear leftover trailing bytes from earlier frames. - Download the updated project to an MT8071iP over
Ethernet > IP tabusing theF7shortcut documented in the MT6071iP and MT8071iP Series Installation and Startup Guide, and verify stable 24±20% Volts DC panel power if Ethernet links drop during testing. - Check the EasyBuilder Pro build against the EasyBuilder Pro V6.09.01.671 release notes if Free Protocol behavior differs between simulation and the physical HMI.
Questions asked
Does INPORT wait for data when no TCP packet is in the Ethernet buffer?
No. The fourth argument in INPORT is an output variable that returns how many bytes were read, not a timeout delay. If no TCP data is waiting when the macro runs, INPORT returns immediately with zero in the fourth argument. Control how often the HMI checks for incoming Ethernet frames by adjusting the macro's timed execution interval or triggering the macro from a bit change.
Why do old characters remain at the end of LW registers after a shorter TCP message arrives?
When a shorter message arrives, INPORT only writes the newly received characters into the start of the buffer array. If you copy the full array to LW registers without clearing it first, trailing bytes from a longer previous message stay behind in memory. Call FILL with zero across the buffer array before INPORT whenever incoming TCP frame lengths vary.
Can you step through a Weintek EasyBuilder Pro macro line by line like a PLC debugger?
EasyBuilder Pro does not provide a breakpoint-based step debugger for HMI macros. Instead, insert TRACE calls at key points in the macro and watch the printed variable values in EasyDiagnoser during online simulation or while connected to the panel over Ethernet. Printing both the returned byte count and the branch taken isolates argument and guard errors quickly.


