crystal-bacnet v0.11.0
BACnet Support for Crystal Lang
it supports
- the IPv4 data link layer (BACnet/IP)
- the websocket data link layer (BACnet/SC)
Installation
Add the dependency to your shard.yml
:
dependencies:
bacnet:
github: spider-gazelle/crystal-bacnet
Usage
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.new
client.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
end
spawn do
# Feed data to the client
loop do
break if server.closed?
bytes, client_addr = server.receive
message = 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
Repository
crystal-bacnet
Owner
Statistic
- 0
- 0
- 0
- 1
- 2
- 2 months ago
- May 28, 2020
License
MIT License
Links
Synced at
Wed, 20 Nov 2024 20:00:52 GMT
Languages