LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

modbus communicate over USB

Hi,

 

I am trying to communicate to an APC UPS over USB using modbus. This manual discusses how the protocol works with the UPS. 

 

Does anyone know how to setup a vi to send a given message (register 130 in the above manual) and receive the response all over USB using modbus? It looks like a particular driver needs to be downloaded as well to allow for interrupt transfers.

 

Thanks

0 Kudos
Message 1 of 7
(3,493 Views)

Hi MNR001,

 

I'm not entirely sure if you can use just USB. My suspicion is that you would have to get a USB to serial adapter. On top of this, there are a few libraries that one could be using for programming Modbus in LabVIEW, the Modbus Library for LabVIEW which is a free download from the NI Website (found here: http://www.ni.com/example/29756/en/) but is note supported by the Applications Engineering Team, or the Modbus API that comes with the LabVIEW DSC Module or LabVIEW RT Module. If you have access to either the LabVIEW DSC Module or the LabVIEW RT Module, look into the API. If you don't, it may be worth checking out the Modbus library.


Thanks,

 

Peter George

Applications Engineer

National Instruments

0 Kudos
Message 2 of 7
(3,413 Views)

Hello,

 

Did you ever get this working? I have a similar issue were I need to query the APC UPS for information using modbus. I have it connected using serial RJ45 and RS232. Just wondering if you were able to get something going. 

 

I have downloaded the NI modbus driver and starting to play with it.

 

Thanks,

Luis

 

Certified TestStand Developer

0 Kudos
Message 3 of 7
(2,381 Views)

Luis,

 

That's a fairly old thread with no followup activity (till now, of course).  May I ask, what model APC device is this, and what OS is the host device running?

 

I only ask because if it's 1) a modern USB-interfaced UPS, and 2) a Windows OS, then I'd suggest you *not* pursue modbus.  If those are your circumstances, consider relying on Windows built-in UPS support, and use some existing LabVIEW code written by Phillip Brooks (or the variation I did on it) which calls WinAPI and/or .NET methods to get UPS status - battery level, AC status, runtime remaining etc.  My addition allows you to simply add UPS state changes into LabVIEW event handling.

 

I've posted it here in case this is of interest to you.

 

Best of luck!

 

Dave

David Boyd
Sr. Test Engineer
Abbott Labs
(lapsed) Certified LabVIEW Developer
0 Kudos
Message 4 of 7
(2,364 Views)

Hi Dave,

 

Thank you for your reply. I have been searching on a LabVIEW program with APC UPS support. I did stumble up on another thread and your code. Even though your program does work for APC UPS's, it is not what I'm looking for. 

 

This thread was a bit closer to what I'm looking for. Although, I am not using USB comms. I am using serial instead.

 

To answer your questions: 1) I'm using serial RJ45 or RS232. 2) I am using a Windows OS. 

 

APC advertises that using modbus protocol one can develop 3rd party applications that can access a lot of the smart features on the UPS. I already designed a RJ45 cable following their AN-181. I was just checking to see if there was some code out there or anyone else having a similar problem.

 

Thanks,

Luis

0 Kudos
Message 5 of 7
(2,361 Views)

Luis,

So, you've explicitly enabled Modbus interfacing on the UPS, and you have a serial interface from the PC to the UPS.  And of course, you don't have Windows battery class support for said UPS since it's not connected/enumerated in USB.  OK, got it.

 

If all you really wanted was status like what the WinAPI stuff offers, I would say you're doing it the hard way.  But, I'll assume you have your reasons - the ModBus doc from Schneider really looks like you can get far more control and status, and frankly I hadn't seen this before.  At this point, conceptually, I think you're considering the APC as an instrument, meaning you're writing an instrument driver, with the obvious interface being VISA serial. (In fact, I'm tempted to start creating such a driver for my own use - I need to check if our APCs implement/support this!)

 

There are several Modbus interfacing libraries developed over the years in LabVIEW, and from the bits I've seen they vary considerably in both code quality and complexity - some even offer both master AND slave role support, and of course there's ASCII vs RTU vs TCP (some libraries support all three protocols.)

 

I've got my own modest Modbus library too, which I've used as a building block for other instruments, and it supports both serial/RTU and TCP transparently (it tests VISA at runtime for serial vs. TCP and implements either).

 

Again if you want it... I've attached an archive.  Notice that there are paths for both user.lib (which is where I locate the Modbus support) and instr.lib (which is where I keep subfolders for a few instruments which make reference to the Modbus support).  My Modbus stuff and the instrument drivers are namespaced in their own project libraries.  You may wish to look at one of the Acuvim instrument drivers as a model - the block diagrams should give you an idea of how straightforward it is to read a block of holding registers given a base address and a register count, and cast the resultant array of words into the data structure it represents in the UPS. (The Schneider doc looks like some responses should be cast into fixed-point values.)

 

You should check the Schneider doc for their serial setup - looks like they violate some minor Modbus stipulations on character parity and formatting.  You may need to look at my serial init routines and see where my stuff attempts to coerce the port to standard (and be more forgiving).

 

Good luck, again.  Would love to hear how this works out for you.

 

Dave

David Boyd
Sr. Test Engineer
Abbott Labs
(lapsed) Certified LabVIEW Developer
0 Kudos
Message 6 of 7
(2,342 Views)

Thanks David,

 

Looks like I got you wrapped up into this as well. Yes, I'm looking into getting more info and possibly control the UPS via modbus. I had success in doing this already using simple TCP/IP with the help of the Network Management Card (NMC). With this card you have the power to query and control this UPS just like any LXI instrument with your own application. Note that APC does not advertise this right now. UPS control like an instrument using TCP/IP protocol and LabVIEW... omg!

 

However, APC claims that this can be done on some cheaper models using modbus. That's where I'm at right now. It looks like some of the older SMT models we have here DO NOT support modbus which means I'm stuck. I'm trying to see which models do support it so that we could buy the right stuff next time around.

 

Also, it seems that this is very new to APC as well. Their tech support is next to useless on this topic.

 

And you are correct, it looks like APC violates some of the modbus protocols which is interesting. Thank you again for your interest and help on this.

 

Luis Garcia

Certified TestStand Developer

0 Kudos
Message 7 of 7
(2,326 Views)