LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

stop bit for 485 Modbus with Modbus library

Good Morning,

 

I am trying to establish communications with one of our VFD on the factory floor, and ran into an issue with communication.  The VFD requires either 1 or 2 stop bits in order to communicate.  Unfortunately within Labiew's Modbus library there is no option to specify the number of stop bits.  On top of that, the Modbus library uses 0 stop bits, causing a communication error!!!

 

Is there some way to work around this in Labview.  By that I mean I would like to specify the umber of stop bits.  I found ways to disable communication errors on some older VFD's, but that is not possible with this version.

 

Thank You in advance,

Mike

0 Kudos
Message 1 of 10
(4,899 Views)

If I've learned anything about the ModBus protocol is that it's not as universal as a protocol should be.  Everyone wants their own little something in there.  Little Endian, Big Endian, stop bit, etc.  Our solution was to just make our own custom LabVIEW code to handle this giving us a range of options to match the non-universal ModBus protocol.  You may want to consider doing the same.  Although, I understand, time...

0 Kudos
Message 2 of 10
(4,894 Views)

Which Modbus library from LabVIEW are you using?

 

There have been a couple variations over the year from ones that were the release of an R&D project, to ones that were rewritten to be based more on object oriented classes.  I think there is another variation beyond that.  Also, the DSC module has means of setting up a library of variables that can be linked to modbus devices and basically does all the modbus communications behind the scenes.

 

I know the older modbus libraries had a subVI to initialize the connection that hard coded the stop bytes.  I never used the library's initialization subVI, just a regular VISA configure and set all that myself.

 

Know what flavor of modbus functions you are using from NI could tell us more about the ways to work around the problem you are having.

 

Attach some code!

0 Kudos
Message 3 of 10
(4,880 Views)

Take a look at this code.

 

It shows the general idea on how to configure the port to work with a single stop bit instead of 2.

 

 

modbus stop bits.png

Message 4 of 10
(4,878 Views)

Mike,

 

After digging into things a bit more, we can remove that code entirely.  The API uses its own version of the configure serial port VI that's a subVI to configure the port to match the type of connection you're using.  Based on the parity you define when setting up the Modbus Master, it will determine how many stop bits are required and configure the port appropriately.  If you choose parity, it will set 1 stop bit (as you're doing).  If you choose no parity, it will use 2 stop bits.  At no time will it set 0 stop bits.

0 Kudos
Message 5 of 10
(4,849 Views)

I wouldn't even think it would be possible to have zero stop bits.  When I look at a serial port in Windows device manager, the only options I see are 1, 1.5, and 2 bits.

 

The code BoKnows posted is one of the newer API's; one I'm not as familiar with.  With the newer API's, you have to use the initialization subVI.  Whether the separate VISA configure works with it or not, I don't know, but I guess it probably would.

 

I disagree with the statement that the  separate serial configure can be removed entirely.  Probably 99% of the time it can.  But it is wrong for the Initialization subVI to assume the number of stop bits based on parity.  It might just guess wrong.  I know the older modbus library (http://www.ni.com/example/29756/en/) assumed the number of stop bits.  As DailyDose said, not all modbus devices follow the standards exactly as they should.  It is very possible that the original poster's problems are based on a device that is not adhering to a standard.

0 Kudos
Message 6 of 10
(4,842 Views)

@RavensFan wrote:

 I disagree with the statement that the  separate serial configure can be removed entirely.  Probably 99% of the time it can.  But it is wrong for the Initialization subVI to assume the number of stop bits based on parity.  It might just guess wrong. As DailyDose said, not all modbus devices follow the standards exactly as they should.  It is very possible that the original poster's problems are based on a device that is not adhering to a standard.


If we're being entirely fair here, something that isn't adhering to the Modbus standard isn't communicating by Modbus.  The API isn't "guessing" how many stop bits to use.  It's using the number of stop bits the standard prescribes. 

 

If we're communicating by Modbus, you can delete that config as it's handled in the initialization.  If you leave the Modbus standard, then it may be wort taking a look at how to modify the Modbus API to communicate with the device with a similar communication protocol.

 

By definition, all Modbus devices follow the standards.  The moment they deviate, they're no longer Modbus. 

0 Kudos
Message 7 of 10
(4,803 Views)

There are many devices that use Modbus and do not care about stop bits at all.  Those would be modbus devices that are using TCP/IP.

 

The main part of modbus is the protocol for how the packet of data for commands and responses are structured.  The number of stop bits, parity bits, baud rate are all details that relate to a lower level of the communication protocol that has nothing to do with the packet structure, which is the primary purpose of the modbus standard.

 

While it would be nice if every modbus device that used serial ports used exactly the stop bit definition the modbus spec calls out , the fact is that in the real world, there are still many devices that used the modbus protcol definition of communication packets that the 99% of the code in the NI modbus libraries will work with just fine, and the code needs to be adjusted to account for this deviation from the modbus spec that is pretty much a insignficant and I'd argue that the number of stop bits should never have been defined by the protocol anyway.  But it was decades ago that the spec was written and somebody must have felt adding that aspect was important at that time.

 

Saying a modbus device is no longer modbus because it used the wrong number of stop bits is ridiculous.  It is still follows the Modbus standard, but with an exception to it.

0 Kudos
Message 8 of 10
(4,787 Views)

There are many devices that use Modbus and do not care about stop bits at all.  Those would be modbus devices that are using TCP/IP.

True.  But, they have nothing to do with this conversation.  We've been talking about Modbus over serial.  Anything I've said has been within this context.  As we'd use a different instance of the polymorphic VI for TCP, the decision to leave that piece of code in or not wouldn't make sense in the context of Modbus over TCP/IP.

 

The main part of modbus is the protocol for how the packet of data for commands and responses are structured.  The number of stop bits, parity bits, baud rate are all details that relate to a lower level of the communication protocol that has nothing to do with the packet structure, which is the primary purpose of the modbus standard.

I'd agree with this.   

 

While it would be nice if every modbus device that used serial ports used exactly the stop bit definition the modbus spec calls out , the fact is that in the real world, there are still many devices that used the modbus protcol definition of communication packets that the 99% of the code in the NI modbus libraries will work with just fine, and the code needs to be adjusted to account for this deviation from the modbus spec that is pretty much a insignficant and I'd argue that the number of stop bits should never have been defined by the protocol anyway.  But it was decades ago that the spec was written and somebody must have felt adding that aspect was important at that time.

Here's where we start to disagree.  Yes, devices in the real world don't adhere to the standard.  Let's look at the DS0.  It's the basic communication block used by both T1 and E1 standards.  Do both methods work?  Absolutely.  Is it safe to say T1 is E1 compliant because the primary purpose of the DS0 is to structure the packet of data and the signaling details are too low level to really impact that compliance?  Not at all.  That's where we are in this discussion.  The code I posted prior is Rube Goldberg code.  From a logical standpoint, it's no different than:

multiply.png

The code I added, and later suggested we delete after digging deeper into the Modbus API, is identical to code already run in a subVI taking place when the Serial Master is created.  If you configure the port and follow that by configuring the port, you're doing the logical equivalent of taking an answer an multiplying it by one.  In the times you're working with a device that doesn't comply to the standard, you can build an API to work with that device.  If the difference is something as small as the stop bits, it'd make sense to include the port configuration in the API.  But, it absolutely does NOT make sense to include it in every application just as it doesn't make sense to include the multiply by one in every application because some day you may want to double that value instead.

 

Saying a modbus device is no longer modbus because it used the wrong number of stop bits is ridiculous.  It is still follows the Modbus standard, but with an exception to it.

The entire point of standards is so we can avoid conversations like these.  Adhering to the standard makes it easy to communicate between two devices and doesn't require strange additions to code to make things work.  Saying a modbus device is no longer a modbus device is ridiculous.  However, it's no more ridiculous than saying something that mostly adheres to the standard is compliant.  The value in saying something is a Modbus device is that you're telling the user they can use the same rules everyone else uses without having to worry about complications.  When you take that away, it's pointless to call it a Modbus device.  You've not met the standard and you've created the exact complications standards are meant to avoid.

 

I'm sure we could have a rather long conversation back and forth and both learn bits and pieces from the other.  But, we're getting pretty far away from Mike originally was asking.  If you'd like to continue the conversation, you're more than welcome to send me a message.  But, I won't be checking the thread going forward.

0 Kudos
Message 9 of 10
(4,772 Views)

In the real world, I only care about using the tools to make sure the devices I'm working with actually work.

 

You have a long paragraph there about DS0 T1 E1.   You completely lost me there.  I have no clue what you are talking about.

0 Kudos
Message 10 of 10
(4,761 Views)