Jump to content
MartinMcD

Using VISA in an executable running as a service

Recommended Posts

I've created a Windows service from an executable that writes a nonsense value to a network shared variable.  What I want to do is read a number from a serial device and write that value instead.  It doesn't seem to work and this link suggests it is not going to:

http://digital.ni.com/public.nsf/allkb/38128C80B42DBB8486256F3A006DECFF

 

Does anyone know of a workaround for this, ie accessing a port using VISA from within a service? I assume the answer is 'no' but it'd be so useful for my project that its worth checking. Its a continuously running thing and it needs to work when nobody is logged on - hence the service.

 

Thanks,

 

Martin

Share this post


Link to post
Share on other sites

I should have said, otherwise I think I will have to convert the PC to run as a real-time device, which is just a bit of a hassle time-wise.

Share this post


Link to post
Share on other sites

We've converted most of our applications into services on regular Windows (95/Vista/7/8) targets using srvany, and they work without any modifications. Are you sure the app works properly in the first place, before being converted into a service? Does it rely on access to configurations e.g that it might not have access to when it starts up as a service? If that configuration file is expected to be  in a system folder the servic emight not refer to the same folder...)

 

The link you posted talks about VISA server, not the VISA-RunTime...and it's the RunTime that's needed for the service to access a local serial port.

Edited by Mads

Share this post


Link to post
Share on other sites

Likewise we run our LV applications as services using FireDaemon and have not had any trouble reading from serial ports using VISA under Windows Server 2003, 2008, or 2008R2. (At least not any trouble that can be blamed on running as a service...we did have an issue where the Microsoft Mouse Driver identified our GPS device as a serial mouse!)

 

-Rob

Share this post


Link to post
Share on other sites

Ahh great, thank you for the responses.  I realised my error and it's working perfectly now - thanks for the encouragement!

 

 

(Out of interest, the problem vi was based on my method for processing the raw data coming from the serial port. It reads a value from a text file on a network drive. I forgot about this - the service isn't allowed to access the drive so it was just returning zero.)

Edited by MartinMcD

Share this post


Link to post
Share on other sites

Also, is there a mechanism for sending an event to the service so it can stop gracefully?

I'm having problems caused by not closing the VISA session for my serial ports when calling 'net stop', if an event could be passed I could close the port properly.

Share this post


Link to post
Share on other sites
Also, is there a mechanism for sending an event to the service so it can stop gracefully?

I'm having problems caused by not closing the VISA session for my serial ports when calling 'net stop', if an event could be passed I could close the port properly.

 

There's a setting in the labview options under environment that should sort that out (it puts cleanupVisa=True in the ini file).

 

Automatically close VISA sessions—Automatically closes VISA sessions left open by the application when the top-level VI becomes idle. This checkbox does not contain a checkmark by default.

Share this post


Link to post
Share on other sites

We've never experiences any VISA problems from shut-downs...but if the software required actions to be done prior to quitting, I do not think the application instance close event would do the trick, it does not seem to fire when the service is quit from the services panel.

 

Does anyone have a way to filter/intercept such an event and run shutdown code?

 

 

PS. Uou should also have RunAsService=True in the executables ini-file so that the service ignores any user logoffs (see http://www.ni.com/white-paper/3185/en).

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.