Perspective client-side serial port access

We’re looking for the best way to have our Perspective session interact with the serial port on the client machine. I haven’t yet found any methods built into Perspective or Ignition scripting anywhere, and we’re currently thinking the simplest method is to use the WebDev module to serve some custom scripting based on the Web Serial API.

I’m trying to find any WebDev examples showing other types of device interactions and not succeeding. There was this forum post that was talking about a barcode scanner, but the links are all dead now. I’m not finding any other similar examples here or on Ignition Exchange.

Keeping in mind that this would also only be used underneath an authenticated Perspective session, I’m trying to make sure we understand any limitations of interacting between the WebDev scripts and the greater Perspective session. I found this forum post talking about passing the session object as parameter to WebDev and don’t fully understand it yet. We may just have to experiment with that concept a bit, but (again) it would be awesome if anyone had any examples they were willing to share.

Are we heading down the wrong path? Are there examples showing any parts of this setup that we can go read?

Honestly, an entire module with a Perspective component might be easier than the webdev route, mostly because there’s no way to ‘embed’ Webdev inside the page (outside of an iframe) - and I have to assume that browsers are very cautious about protocols like Web Serial inside of iframes.

I don’t suppose there’s any chance IA was considering expanding the serial modules to include Perspective clients? :wink:

We’re still considering our options. We might be able to avoid iframe issues since our serial functionality is only a sometimes thing and can take over the entire browser when running. We might make the WebDev functionality serve full pages and provide a way to hop back into Perspective when done.

1 Like

Nothing I’m currently aware of - Web Serial in particular is still a pretty ‘bleeding-edge’ API (no support in Firefox or Safari, for instance), so we’d definitely hesitate to include it first party.

What you described for jumping ‘out of’ Perspective into your Webdev definitely seems more doable - authentication is still a sticking point there if I remember correctly, but that may have been fixed since I last messed around with it.

Do the scripts inside of WebDev have access to things like system.perspective.getSessionInfo? We were thinking we would pass in a session ID as a parameter, and have WebDev validate that that session is legitimate and the WebDev requests are coming from the same IP.

Is there an easier way to do that?

That would definitely work - getSessionInfo() is available everywhere on the gateway. In a perfect world there would be some other ways to get the same information, but each module on the gateway is in its own segment classloader, so you can’t access Perspective’s internals from your Webdev scripts, only what it chooses to expose via scripting functions.