Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/spider-gazelle/crystal-bacnet
BACnet Support for Crystal Lang
https://github.com/spider-gazelle/crystal-bacnet
Last synced: 3 months ago
JSON representation
BACnet Support for Crystal Lang
- Host: GitHub
- URL: https://github.com/spider-gazelle/crystal-bacnet
- Owner: spider-gazelle
- License: mit
- Created: 2020-05-28T02:06:32.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-07-16T13:12:55.000Z (4 months ago)
- Last Synced: 2024-07-16T16:02:49.274Z (4 months ago)
- Language: Crystal
- Size: 147 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-crystal - crystal-bacnet - BACnet protocol implementation with BACnet/IP client (Network Protocols)
README
# BACnet Support for Crystal Lang
[![CI](https://github.com/spider-gazelle/crystal-bacnet/actions/workflows/ci.yml/badge.svg)](https://github.com/spider-gazelle/crystal-bacnet/actions/workflows/ci.yml)
it supports
* the IPv4 data link layer (BACnet/IP)
* the websocket data link layer (BACnet/SC)## Installation
Add the dependency to your `shard.yml`:
```yaml
dependencies:
bacnet:
github: spider-gazelle/crystal-bacnet
```## Usage
```crystal
require "bacnet"
require "socket"# ======================
# Create transport layer
# ======================
server = UDPSocket.new
server.bind "0.0.0.0", 0xBAC0# ======================
# Hook up the client to the transport
# ======================
client = BACnet::Client::IPv4.newclient.on_transmit do |message, address|
if address.address == Socket::IPAddress::BROADCAST
# Broadcast this message, might need to be a unicast to a BBMD
else
server.send message, to: address
end
endspawn do
# Feed data to the client
loop do
break if server.closed?
bytes, client_addr = server.receivemessage = IO::Memory.new(bytes).read_bytes(BACnet::Message::IPv4)
client.received message, client_addr
end
end# ======================
# Collect device information
# ======================
registry = BACnet::Client::DeviceRegistry.new(client)
registry.on_new_device do |device|
puts "FOUND NEW DEVICE: #{device.vendor_name} #{device.name} #{device.model_name}"
end# broadcast a who_is out onto the network
client.who_is```