# While loops inside Gateway Events are very unreliable

**URL:** <https://forum.inductiveautomation.com/t/while-loops-inside-gateway-events-are-very-unreliable/105023>\
**Category:** Ignition\
**Tags:** ignition81, scripting, vision\
**Created:** [April 11, 2025, 9:19pm UTC](https://forum.inductiveautomation.com/t/while-loops-inside-gateway-events-are-very-unreliable/105023 "2025-04-11T21:19:43Z")\
**Posts on this page:** 1\
**Showing post:** 17

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [April 11, 2025, 11:00pm UTC](https://forum.inductiveautomation.com/t/while-loops-inside-gateway-events-are-very-unreliable/105023/17 "2025-04-11T23:00:37Z")

</div>

> [@Factory Wide Multi Barcode Scanner Setup - Discussion/Feedback](https://forum.inductiveautomation.com/t/factory-wide-multi-barcode-scanner-setup-discussion-feedback/74666/25):
>
> I was able to get this to work after some testing. I got stuck on my data coming from the scanner being in 3 or 4 chunks, requiring multiple reads to get all the data. That turned out to be a setting on my serial gateway, it was set to use inter-character time gap as the delimiter, I changed it to use 0x0d0a instead and now my class reads it all as 1 message. I unfortunately have no idea what the maximum message size from the serial-ethernet gateway is, the only thing I can find in the docs is …

The TCP listener class I made here for listening to barcode scanners might be of some use. I was offloading to a queue for another script to chew through, you'll just be writing to a tag. I think there is also a listener server class in the thread somewhere, I was anticipating barcode scanners that acted as clients as well.

Further up in the post it talks about the storing of the old instance and killing it on script environment update/reset.

---

_[View the full topic](https://forum.inductiveautomation.com/t/while-loops-inside-gateway-events-are-very-unreliable/105023)._
