A julia interface to the libmodbus C library.
To get the master version:
Pkg.clone("https://github.com/nkottary/Modbus.jl")
# Create a modbus context with the necessary data.
ctx = modbus_new_tcp("192.168.0.109", 502)
# Optional attributes to set
# Set the slave unit ID, default is 255.
modbus_set_slave(ctx, 1)
# Set the response timeout to 0.75 seconds, default is 0.5 seconds
modbus_set_response_timeout(ctx, 0, 750000)
# ~~~ End of optional attributes
# Start the connection.
modbus_connect(ctx)
# Read 10 registers from address 2999
dest = modbus_read_registers(ctx, 2999, 10)
# Show the data recieved
@show dest
# Close the connection
modbus_close(ctx)
# Free memory allocated to context
modbus_free(ctx)
I have used the java program ModbusPal to simulate a slave on localhost. The first 2 registers (size 16 bit each) of the slave device are bound to a 32 bit float sine wave generated by the automation.