# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## Re: Rotary table WEISS Labview

That is the Python code. It works for me. I have tried 3 libraries of Modbus in Labview including the NI Modbus library. Tried writing to single registers, multiple registers, coils, etc. Device number, time out, address, etc.
Always comes with an error when Labview executes the block to read.

Message 11 of 23
(305 Views)

## Re: Rotary table WEISS Labview

So please post the NI Modbus free library version and describe which error and where, so we can check it.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
Message 12 of 23
(295 Views)

## Re: Rotary table WEISS Labview

@henk1000 wrote:

That is the Python code. It works for me. I have tried 3 libraries of Modbus in Labview including the NI Modbus library. Tried writing to single registers, multiple registers, coils, etc. Device number, time out, address, etc.
Always comes with an error when Labview executes the block to read.

Seems pretty simple enough, please attach your LV code to see what could be the problem.

``````from pymodbus.client import ModbusTcpClient

"""A dummy docstring."""
position = hex_to_dec(v[0], v[1], 10000)
speed = hex_to_dec(v[4], v[5], 10000)
torque = hex_to_dec(v[8], v[9], 1000)
motor_state = v[12]
print(f"position: {position}")
print(f"speed: {speed}")
print(f"torque: {torque}")
print(f"motor_state: {motor_state}")

def hex_to_dec(reg1, reg2, factor):
"""A dummy docstring."""
a = str(hex(reg1))
a = a[2:]
b = hex(reg2)
b = b[2:]
c = "0x" + b + a
c = int(c, 16) / factor  # normaly 10000
return c

def writeModbus(client, a, b):
"""A dummy docstring."""
try:
write_to_motor = client.write_registers(a, b)
assert not write_to_motor.isError()
except ConnectionError as errorcom:
raise SystemExit from errorcom

def modBus():
"""A dummy docstring."""
try:
client = ModbusTcpClient('192.168.1.200', port=502)
print("Modbus connected")
except ConnectionError as errorcom:
print("Can not connect to PLC!")
raise SystemExit from errorcom
return client

connect = modBus()
writeModbus(connect, 0, 1)   # Write on register 0, value 1

connect.close()
``````

Santhosh
Soliton Technologies

Finding it hard to source NI hardware? Try NI Trading Post
Message 13 of 23
(285 Views)

## Re: Rotary table WEISS Labview

@henk1000 wrote:

That is the Python code. It works for me. I have tried 3 libraries of Modbus in Labview including the NI Modbus library. Tried writing to single registers, multiple registers, coils, etc. Device number, time out, address, etc.
Always comes with an error when Labview executes the block to read.

Well if you are having so much trouble with the LabVIEW modbus libs and the Python modbus lib works, just call the python code in LabVIEW with a python node, see here in LabVIEW for examples:

Examples for using the Python Node are available in the LabVIEW Example Finder (found in Help >> Find Examples...) under Communicating with External Applications >> Using External Code >> Integrating Python Code.

Or if you must make it work in pure LabVIEW, post the error that you got.

______________________________________________________________
Have a pleasant day and be sure to learn Python for success and prosperity.
Message 14 of 23
(284 Views)

## Re: Rotary table WEISS Labview

Ask them for the MODBUS protocol.

Message 15 of 23
(273 Views)

## Re: Rotary table WEISS Labview

That's what I have been doing, but would nice having only the Labview application.

Message 16 of 23
(243 Views)

Message 17 of 23
(240 Views)

## Re: Rotary table WEISS Labview

@henk1000 wrote:

Thanks, that helps. Error 56 is a timeout error:

https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z0000019Lz2SAE&l=en-US

______________________________________________________________
Have a pleasant day and be sure to learn Python for success and prosperity.
Message 18 of 23
(226 Views)

## Re: Rotary table WEISS Labview

I don't have that modbus library, can you set the timeout?

______________________________________________________________
Have a pleasant day and be sure to learn Python for success and prosperity.
Message 19 of 23
(225 Views)

## Re: Rotary table WEISS Labview

What happens if you try this ?

Message 20 of 23
(216 Views)