{"id":18847796,"url":"https://github.com/interkosmos/fortran-modbus","last_synced_at":"2026-03-19T06:42:38.889Z","repository":{"id":236808453,"uuid":"790943874","full_name":"interkosmos/fortran-modbus","owner":"interkosmos","description":"Fortran 2018 interface bindings to libmodbus","archived":false,"fork":false,"pushed_at":"2024-11-18T22:23:10.000Z","size":26,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-30T13:57:09.445Z","etag":null,"topics":["automation","fortran","fortran-2018","fortran-package-manager","iiot","iot","libmodbus","modbus","modbus-rtu","modbus-tcp"],"latest_commit_sha":null,"homepage":"","language":"Fortran","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/interkosmos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-23T20:07:42.000Z","updated_at":"2024-11-18T22:23:14.000Z","dependencies_parsed_at":"2024-04-28T18:29:44.652Z","dependency_job_id":"305ea9e2-d5fb-458d-af57-c0f35b048abe","html_url":"https://github.com/interkosmos/fortran-modbus","commit_stats":null,"previous_names":["interkosmos/fortran-modbus"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/interkosmos%2Ffortran-modbus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/interkosmos%2Ffortran-modbus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/interkosmos%2Ffortran-modbus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/interkosmos%2Ffortran-modbus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/interkosmos","download_url":"https://codeload.github.com/interkosmos/fortran-modbus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239783793,"owners_count":19696444,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","fortran","fortran-2018","fortran-package-manager","iiot","iot","libmodbus","modbus","modbus-rtu","modbus-tcp"],"created_at":"2024-11-08T03:09:42.446Z","updated_at":"2026-01-26T12:13:08.727Z","avatar_url":"https://github.com/interkosmos.png","language":"Fortran","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fortran-modbus\n\nA collection of Fortran 2018 interface bindings to\n[libmodbus](https://libmodbus.org/), for Modbus RTU/TCP communication.\n\n## Build Instructions\n\nThe package _libmodbus_ has to be installed with development headers. On\nFreeBSD, run:\n\n```\n# pkg install comms/libmodbus\n```\n\nOn Linux, instead:\n\n```\n# apt-get install libmodbus5 libmodbus-dev\n```\n\nBuild and install the Fortran library using the provided Makefile:\n\n```\n$ make\n$ make install PREFIX=/opt\n```\n\nLink your programs against `/opt/lib/libfortran-modbus.a -lmodbus`. Optionally,\noverwrite the default compiler and the compiler flags:\n\n```\n$ make FC=ifx FFLAGS=\"-O3\"\n```\n\nOr, use the [Fortran Package Manager](https://github.com/fortran-lang/fpm):\n\n```\n$ fpm build --profile release\n```\n\nBuild and run the test program:\n\n```\n$ make test\n$ ./test_modbus\n```\n\n## Example\n\nThe following example program connects to a device via Modbus RTU and outputs\ntwo registers as a real number:\n\n```fortran\n! example.f90\nprogram main\n    use :: modbus\n    use :: modbus_rtu\n    implicit none (type, external)\n\n    integer, parameter :: ADDRESS = 50\n    integer, parameter :: SLAVE   = 10\n\n    integer                  :: stat\n    integer(kind=c_uint16_t) :: regs(2)\n    real                     :: f\n    type(c_ptr)              :: ctx\n\n    ctx  = c_null_ptr\n    stat = -1\n    regs = 0\n\n    mb_block: block\n        ! Create Modbux RTU context.\n        ctx = modbus_new_rtu('/dev/ttyUSB0', 19200, 'E', 8, 1)\n        if (.not. c_associated(ctx)) exit mb_block\n\n        ! Connect to device.\n        stat = modbus_connect(ctx)\n        if (stat == -1) exit mb_block\n\n        ! Set slave number.\n        stat = modbus_set_slave(ctx, SLAVE)\n        if (stat == -1) exit mb_block\n\n        ! Read registers.\n        stat = modbus_read_registers(ctx, ADDRESS, size(regs), regs)\n        if (stat == -1) exit mb_block\n\n        ! Convert to real.\n        f = modbus_get_float_abcd(regs)\n        print '(f12.8)', f\n    end block mb_block\n\n    call modbus_close(ctx)\n    call modbus_free(ctx)\n\n    if (stat == -1) print '(a)', 'Error: operation failed'\nend program main\n```\n\nIf the Fortran library is installed to `/opt/lib`, run:\n\n```\n$ gfortran -o example example.f90 /opt/lib/libfortran-modbus.a -lmodbus\n```\n\n## Fortran Package Manager\n\nYou can add *fortran-modbus* as an FPM dependency:\n\n```toml\n[dependencies]\nfortran-modbus = { git = \"https://github.com/interkosmos/fortran-modbus.git\" }\n```\n\n## Licence\n\nISC\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finterkosmos%2Ffortran-modbus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finterkosmos%2Ffortran-modbus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finterkosmos%2Ffortran-modbus/lists"}