You mentioned you were using an S7300 AI card, so I'm assuming you are using an S7300 CPU as well.
The 300's have a concept called the "Process Image", where it at the beginning of the PLC scan, it grabs a certain amount of the IO table, and buffers it into memory. This is called the Process Image. The amount of memory it grabs is configurable, but the default is often 256 bytes. Analog values are, by default, placed outside the Process Image, but could be moved inside it if you want to. One of the advantages of this buffering is that the Process Image will not change during the scan of the PLC. This is called a synchronous scan, and is what users expect from pretty much all PLCs (except the Logix family, which is asynchronous).
When the PLC started the scan, it probably copied IW0-IW254 into the Process Image (PI) table. When you use the command IW298, it looks at the buffered PI, saw that there was no value stored there, and returned 0. When you use the command PIW298 (or, in portal, IW298
), it goes directly to the communications interface and grabs the most recent value from the IO card. This is called a peripheral read.
I'm not 100% sure why these PLCs only buffer part of the IO data. My guess is that, historically, copying the IO memory took a lot of time, and the PLC should only copy exactly as much as needed to avoid wasting time. In the newer Siemens PLCs (S71200/1500), the entire IO table is buffered in the process image, and so this isn't an issue. You can still use the
to command a periphery read/write, to intentionally grab the most recent value instead of the buffered value.