aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElectric-Blue <Electric-Blue@users.noreply.github.com>2016-01-27 01:13:16 +0300
committerElectric-Blue <Electric-Blue@users.noreply.github.com>2016-01-27 01:13:16 +0300
commit292c9e6e6e0351bfdb05f1fa74c163dd530ad27e (patch)
tree8b07fe7f5afff4917a76800e98179c2c7cf390dd
parent0c4a1cc1c2083a871562364de5df4f9d88ec321e (diff)
downloadNimBluez-292c9e6e6e0351bfdb05f1fa74c163dd530ad27e.tar.gz
NimBluez-292c9e6e6e0351bfdb05f1fa74c163dd530ad27e.zip
Update README.md
-rw-r--r--README.md96
1 files changed, 53 insertions, 43 deletions
diff --git a/README.md b/README.md
index f22609c..611a80b 100644
--- a/README.md
+++ b/README.md
@@ -2,56 +2,66 @@
Modules for access to system [Bluetooth](https://www.bluetooth.com/) resources for the [Nim](http://nim-lang.org/) programming language.
-Use [nimbluez.bluetooth](https://github.com/Electric-Blue/NimBluez/nimbluez/bluetooth.nim) module for cross-platform discovery and managing Bluetooth devices and services.
+Use `nimbluez/bluetooth` module for cross-platform discovery and managing Bluetooth devices and services.
-For cross-platform low-level sockets interface implementation for Bluetooth use
-[nimbluez.bluetoothnativesockets](https://github.com/Electric-Blue/NimBluez/nimbluez/bluetoothnativesockets.nim).
+For cross-platform low-level sockets interface implementation use `nimbluez/bluetoothnativesockets`.
-You can find wrappers for [BlueZ](http://www.bluez.org/) in [nimbluez/bluez](https://github.com/Electric-Blue/NimBluez/nimbluez/bluez/) folder.
-For [Microsoft Bluetooth](https://msdn.microsoft.com/en-us/library/windows/desktop/aa362761%28v=vs.85%29.aspx) protocol stack wrappers look at [nimbluez/msbt](https://github.com/Electric-Blue/NimBluez/nimbluez/msbt/).
+You can find wrappers for [BlueZ](http://www.bluez.org/) in `nimbluez/bluez` folder.
+For [Microsoft Bluetooth](https://msdn.microsoft.com/en-us/library/windows/desktop/aa362761%28v=vs.85%29.aspx) protocol stack wrappers look at `nimbluez/msbt`.
## Installation
To install using [Nimble](https://github.com/nim-lang/nimble) run the following:
```
$ nimble install nimbluez
```
-
+(Not yet published.)
## Examples
-.. code-block:: nim
- # Simple discovery example.
- import nimbluez.bluetooth
-
- echo "All visible remote devices:"
- for remoteDevice in getRemoteDevices():
- echo remoteDevice.address, " - ", remoteDevice.name
-
-.. code-block:: nim
- # Simple server example.
- # Attention! This code
- import nimbluez/bluetoothnativesockets
-
- var serverSocket = newBluetoothNativeSocket(SOCK_STREAM, BTPROTO_RFCOMM)
- discard serverSocket.bindAddr(RfcommPort(0))
- discard serverSocket.listen()
- var
- clientSocket: SocketHandle
- clientAddress: string
- clientSocket = serverSocket.acceptRfcommAddr(clientAddress)
- var
- message: string
- message = clientSocket.recv()
- echo message
- clientSocket.close()
- serverSocket.close()
-
-.. code-block:: nim
- # Simple client example.
- import nimbluez/bluetoothnativesockets
-
- var clientSocket = newBluetoothNativeSocket(SOCK_STREAM, BTPROTO_RFCOMM)
- discard clientSocket.connect(RfcommPort(1), "00:02:72:0F:5C:87")
- discard clientSocket.send("Hi there!")
- clientSocket.close()
-
-For more examples look at [examples]() folder.
+```nim
+# Simple discovery example.
+import nimbluez/bluetooth
+
+echo "All visible remote devices:"
+for remoteDevice in getRemoteDevices():
+ echo remoteDevice.address, " - ", remoteDevice.name
+```
+
+```nim
+# Simple server example.
+# Attention! This code does not contain error handling.
+import nimbluez/bluetoothnativesockets
+
+var serverSocket = newBluetoothNativeSocket(SOCK_STREAM, BTPROTO_RFCOMM)
+var name = getRfcommAddr(RfcommPort(1))
+discard bindAddr(serverSocket,
+ cast[ptr SockAddr](addr(name)),
+ sizeof(name).SockLen)
+discard serverSocket.listen()
+var
+ clientName = getRfcommAddr()
+ clientNameLen = sizeof(clientName).SockLen
+var clientSocket = accept(serverSocket,
+ cast[ptr SockAddr](addr(clientName)),
+ addr(clientNameLen))
+var message: string = ""
+message.setLen(1000)
+let recvLen = clientSocket.recv(cstring(message), cint(message.len), cint(0))
+message.setLen(recvLen)
+echo message
+clientSocket.close()
+serverSocket.close()
+```
+
+```nim
+# Simple client example.
+# Attention! This code does not contain error handling.
+import nimbluez/bluetoothnativesockets
+
+var socket = newBluetoothNativeSocket(SOCK_STREAM, BTPROTO_RFCOMM)
+var name = getRfcommAddr(RfcommPort(1), "00:02:72:0F:5C:87")
+discard connect(socket, cast[ptr SockAddr](addr(name)), sizeof(name).SockLen)
+var message = "Hi there!"
+discard send(socket, cstring(message), cint(message.len), cint(0))
+socket.close()
+```
+For more examples look at `examples` folder.