Skip to content

nkottary/Modbus.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Modbus.jl

A julia interface to the libmodbus C library.

Installation

To get the master version:

Pkg.clone("https://github.com/nkottary/Modbus.jl")

Basic Usage

# 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)

Tests

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.

ModbusPal setup

alt tag

Julia output

alt tag

About

Julia wrappers for libmodbus C library.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages