IMD SolutionComputing LibraryShop main store

How-to

Write to a PI server from Visual Basic without an OPC server

Edge computing and IIoT Published 6 min read By IMD Solution engineering team

Short answer

Skip the OPC DA layer. A Visual Basic export is the data producer, so it can write directly to the PI Data Archive with the AF SDK, or through PI Web API when the host cannot take a client install. An OPC server only adds a mapping layer, because it accepts data from sources that publish OPC items, and a VB export does not.

On this page
  1. The four paths into PI from Visual Basic
  2. Confirm licensing before you write code
  3. Two checks decide AF SDK on an older Visual Basic
  4. Build the direct write path
  5. Sizing the write method for 12 tags at 1 value per second
  6. Verify each layer separately
  7. The decision
  8. Questions asked

Write straight to the PI Data Archive from your Visual Basic program with the PI AF SDK, or through PI Web API when the host cannot take a client install. Your VB export is the data producer, so an OPC DA server between it and PI buys you nothing: an OPC server accepts data from sources that publish OPC items, and a Visual Basic export does not. Inserting one means adding DCOM configuration, an interface node and a second tag-mapping layer, while the original problem, getting VB values into PI, still needs solving. The path you pick is decided by four inputs: which PI client technology you are licensed for, the .NET Framework and bitness match between the AF SDK assemblies and your project, the write rate, and whether data arrives as batches or a stream.

The four paths into PI from Visual Basic #

Approach Status Fit for a VB export
PI AF SDK Preferred .NET library Typed objects, bulk writes, natural fit for VB
PI Web API Supported REST interface No client install; small periodic batches over HTTP
PI OLEDB Supported SQL-style access Workable for relational-style inserts, less natural for streams
PI SDK, PI-API Obsolete Legacy installs only; avoid for new work
OPC DA server in between Extra layer Only when the source already speaks OPC

Pick AF SDK when the program runs on a Windows host that can carry the PI client install and the license. Pick PI Web API when the host cannot take that install, or when values arrive as small periodic batches that map cleanly onto HTTP calls. Keep an OPC layer only when the data generator already ships an OPC interface. The same choice shapes the historian side of a larger collection architecture; the article on whether SCADA needs a historian between it and an OPC UA server article:does-scada-need-a-historian-between-it-and-an-opc-ua-server covers the corresponding question at the SCADA layer.

Confirm licensing before you write code #

Non-OSIsoft software that talks to the PI Data Archive usually needs a PI System Access license. A program that compiles and connects can still be refused or constrained at the write, so settle three items in writing with your PI support contact before development:

  1. Which client technology your license covers: AF SDK, Web API or OLEDB.
  2. The identity the VB program runs under, and the mapping or trust entry for it on the Data Archive.
  3. Write permission for that identity on the target points, and the expected value rate, so the write method is sized correctly.

Server-side permissions are documented as standard access levels, read, write and admin, applied per point or per database; the vendor's PI access levels documentation page https://docs.aveva.com/bundle/pi-server-s-da-admin/page/1020312.html describes those levels. Grant write only on the points this program owns.

Two checks decide AF SDK on an older Visual Basic #

The AF SDK is a .NET assembly, so two project settings decide whether it loads:

  1. Framework target. Compare the .NET Framework version required by the AF SDK release you install, from that release's notes, against the maximum target your VB project supports. The free 2010-era Express editions cap low; if your edition cannot reach the required framework, either build the writer in a newer Visual Studio and call it from the export, or switch to PI Web API, which needs only HTTP calls from the VB side.
  2. Platform bitness. Set the project platform target to the same bitness, x86 or x64, as the AF SDK assemblies you reference. A mismatch produces a load failure at runtime, not a compile error, so the failure appears the first time the writer runs.

If either check fails and you cannot change the project, PI Web API is the fallback: the same license question applies, but the host carries no PI client install and no bitness constraint.

Build the direct write path #

  1. Create the PI points on the Data Archive with names that map one-to-one to the generator's variables. Set each point type, float, integer, digital or string, to match the exported value, and set the point source to a value reserved for this program so you can find its points later.
  2. Install the PI client library on the host, add the reference in the VB project, and set the platform target to the library's bitness.
  3. Connect to the Data Archive by name, and resolve each point once at startup. Cache the point objects; resolving per write adds a lookup on every value.
  4. Send the source timestamp with every value. Relying on host time puts buffered or delayed exports at the wrong place on the trend and breaks the archive's view of the process.
  5. For streaming data, batch values per point and send one bulk call per short cycle. For periodic exports, write once per export cycle.
  6. Catch connection exceptions, log them with the point name and timestamp, and retry from a local queue. The VB program has no store-and-forward unless you add it, so an archive outage otherwise drops data silently.

The same queue-then-write pattern is what fails when sources outrun the database; the article on why high frequency data logging fails at the database write rate article:why-high-frequency-data-logging-fails-at-the-database-write-rate shows the write-rate arithmetic from the historian side.

Sizing the write method for 12 tags at 1 value per second #

Inputs. Twelve tags, exported as a continuous stream at 1 value per tag per second, on an AF SDK writer with a batching cycle of 5 seconds. These are a typical streaming-export case; substitute your own tag count and rate, and the arithmetic below moves with them.

Rule. Aggregate values per point over the batching cycle and send one bulk call per cycle instead of one call per value. Batch when the aggregate rate would push single-value calls past roughly 10 calls per second on one connection, which is where per-call overhead starts to dominate the write itself.

Arithmetic. Aggregate rate: 12 tags multiplied by 1 value per second equals 12 values per second, already above the 10-calls-per-second threshold, so single-value writes are out. Bulk calls: a 5 second cycle collects 12 values per second multiplied by 5 seconds equals 60 values per cycle, sent as 1 call per 5 seconds, which is 0.2 write calls per second.

Result. Batching cuts the call rate from 12 calls per second to 0.2 calls per second, a factor of 60, and moves the same 60 values per cycle into the archive.

Decision. At 12 values per second and above, batch and bulk-write; below about 10 values per second in aggregate, single-value writes on each export cycle are simple and adequate.

Verify each layer separately #

Run the writer against one test point and check one layer at a time. Compare the last value and timestamp in the source export with the archive value for the same timestamp, then open the point in a PI client tool and confirm the value shows good status, not substituted or questionable. Pull a trend across the write period and look for gaps equal to your export interval, which reveal dropped cycles. Finally, stop the archive connection briefly, restart it, and confirm the queued values arrive with their original timestamps and in order. This is the same discipline the historian-side article on connecting on-premise OPC UA and SQL servers to a cloud PI system article:connect-on-premise-opc-ua-and-sql-servers-to-a-cloud-pi-system applies when a new collection path goes live: one known tag, one known value, one known timestamp.

The decision #

You do not need Matrikon OPC DA or any OPC server for this. License permitting, write with the AF SDK from Visual Basic: match the framework target and bitness, resolve points once, stamp with the source time, and bulk-write at 12 values per second or more. When the host cannot take the client install or the framework check fails, write through PI Web API instead. Reach for an OPC layer only when the data generator already exposes OPC items of its own.

Questions asked

Why does an OPC DA server not help when Visual Basic is the data source?

An OPC DA server serves device data to OPC clients; it does not accept a Visual Basic export unless a second component publishes that data into it. You would add DCOM configuration, an interface node and an OPC-item-to-tag mapping without removing the original problem, which is getting values from the VB program into the archive.

My VB program connects to PI but the trend stays flat. What differs between a connection and a write?

A successful connection only proves the identity can reach the server. Check separately that the identity has write permission on the point, that the point type matches the value you send, and that the timestamp you supply falls inside the display range. A write that returns no exception but lands outside the trend window looks identical to no write at all.

The AF SDK assembly fails to load in my Visual Basic project. What is the usual cause?

Almost always a framework or bitness mismatch. Compare the .NET Framework version in the AF SDK release notes for the installed release against your project's target framework, and set the project platform target to the same bitness as the installed assemblies. A mismatch fails at runtime, not at compile time, so rebuild and re-run the test-point write after fixing it.

Can I use the PI SDK or the PI API for a new VB writer?

No. Both are obsolete client technologies carried only by legacy installs. For new work use the AF SDK on a host that can take the PI client install, or PI Web API when it cannot. Building a new writer on an obsolete library adds migration work the day that library is retired from your PI system.

Do I need a special license to write to PI from my own program?

Third-party software that reads or writes the PI Data Archive typically needs a PI System Access license on top of the base server. Confirm with your PI vendor support contact which client technologies your license covers before you write code, because a program that compiles and connects can still be refused at the write when the license does not cover it.

Keep reading

  • Explainer

    Connect on-premise OPC UA and SQL servers to a cloud PI System

    Yes. Install the AVEVA adapters on-premise, on a small host next to the OPC UA and SQL servers, and point egress at PI Web API in the cloud; the PI Data Archive port is not a supported egress destination. Only the adapter-to-Web API direction needs an outbound route.

    Edge computing and IIoT

  • Explainer

    Why a PI value timestamp is not a receipt time

    No, an AFDataPipe event carries one timestamp — the value's event time, assigned by whatever wrote it — and the PI Data Archive exposes no per-value server receipt time. A sync over a one-way diode therefore restarts from the earlier of the two readers' last sent timestamps minus an overlap margin, journals every event locally before sending, and reconciles archives on a schedule. Treat 0% data loss as a requirement you validate, not something AFDataPipe guarantees.

    Edge computing and IIoT

  • Troubleshooting

    Why PI AF SDK writes stall after a PI Server reboot

    After a PI Server restart, AF SDK writes can return no errors while nothing lands in the archive, because PiServer.ConnectionInfo.IsConnected keeps reporting the old connection state and snapshot errors go unchecked. Gate recovery on operation-level errors instead, and preconfigure PI Buffer Subsystem so BufferIfPossible actually queues events through the outage window.

    Edge computing and IIoT

What the Historian SDK does with multiple event writes