Skip to content

Commit

Permalink
Added documentation for Sainsmart 16-channel control module, updated …
Browse files Browse the repository at this point in the history
…README and HISTORY
  • Loading branch information
ondrej1024 committed Apr 11, 2016
1 parent 94ebf2e commit 54edc0e
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 10 deletions.
4 changes: 4 additions & 0 deletions HISTORY
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ Version history
- Added new parameter for number of relays on Sainsmart card (4/8)
- Added detection for number of relays on HID API compatible relay card
- Added logging daemon messages to syslog

0.10: 11/04/2016
- Added support for SainSmart 16 Channel controller USB HID Programmable Control Relay Module
- Cleanup patches
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Currently the following relay cards are supported:
- [Sainsmart USB 4/8-channel relay card](http://www.sainsmart.com/sainsmart-4-channel-5v-usb-relay-board-module-controller-for-automation-robotics.html),
see [*Note 2*](https://github.com/ondrej1024/crelay#note-2-sainsmart-usb-48-channel-relay-card) below
- [HID API compatible relay cards (1/2/4/8 channel)](http://www.ebay.com/itm/For-Smart-Home-5V-USB-Relay-2-Channel-Programmable-Computer-Control-/190950124351)
- [Sainsmart USB 16-channel relay control module](http://www.sainsmart.com/arduino/sainsmart-16-channel-controller-usb-hid-programmable-control-relay-module.html)
- Generic GPIO controlled relays,
see [*Note 3*](https://github.com/ondrej1024/crelay#note-3-gpio-controlled-relays) below

Expand Down Expand Up @@ -62,13 +63,14 @@ The following picture shows a high level view on the modular software architectu

#### Command line interface
$ crelay
crelay, version 0.9
crelay, version 0.10

This utility provides a unified way of controlling different types of relay cards.
Currently supported relay cards:
- Conrad USB 4-channel relay card
- Sainsmart USB 4-channel relay card
- Sainsmart USB 4/8-channel relay card
- HID API compatible relay card
- Sainsmart USB-HID 16-channel relay card
- Generic GPIO relays
The card which is detected first will be used.

Expand Down Expand Up @@ -247,7 +249,8 @@ The support for the different relay cards in *crelay* has only been possible tha
* [Dominic Sacré](https://github.com/dsacre) who discovered the communication protocol of the Conrad USB card
* [Darryl Bond](https://github.com/darrylb123), who discovered the communication protocol of the HID API cards
* [Steve Crow](https://github.com/stav09), who discovered the communication protocol of the Sainsmart USB cards

* [Kevin Hilman](https://github.com/khilman), who implemented and tested the support for the Sainsmart 16-channel control module
* [Andrew Lunn](https://github.com/lunn), who contributed cleanup patches
<br>

### Notes
Expand Down
56 changes: 56 additions & 0 deletions relays/SainSmart-USB-16-channel/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
SainSmart 16 Channel controller USB HID Programmable Control Relay Module
=========================================================================

This is a plug in module which can be used with the Sainsmart 16 channel relay cards
to add a USB interface to these cards.

The module implements the "Human Interface Device" (HID) interface class. The HIDAPI
multi-platform library can be used to access this kind of device:
http://www.signal11.us/oss/hidapi/


Product page:

http://www.sainsmart.com/arduino/sainsmart-16-channel-controller-usb-hid-programmable-control-relay-module.html


Communication protocol description:

Read command
------------

Request (16 bytes):
RD LN 11 11 11 11 11 11 11 11 'H' 'I' 'D' 'C' CS CS
RD: read command (0xD2)
LN: message length (excluding checksum)
CS: checksum bytes (16 bits)

Response:
XX XX BM BM
BM: Relay state bitmap (16 bits)
XX: unknown meaning

Relay State Bitmap:
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 bits
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| 15| 0 | 14| 1 | 13| 2 | 12| 3 | 11| 4 | 10| 5 | 9 | 6 | 8 | 7 | relay number
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+

Write command
-------------

Request (16 bytes):
WR LN BM BM 00 00 00 00 00 00 'H' 'I' 'D' 'C' CS CS
WR: write command (0xC3)
LN: message length (excluding checksum)
BM: Relay state bitmap (16 bits)
CS: checksum bytes (16 bits)

Response:
None

Relay State Bitmap:
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 bits
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| 15| 14| 13| 12| 11| 10| 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | relay number
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
8 changes: 4 additions & 4 deletions src/crelay.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
* sudo make install
*
* Last modified:
* 19/08/2015
* 11/04/2016
*
* Copyright 2015, Ondrej Wisniewski
* Copyright 2016, Ondrej Wisniewski
*
* This file is part of crelay.
*
Expand Down Expand Up @@ -57,8 +57,8 @@
#include "config.h"
#include "relay_drv.h"

#define VERSION "0.9"
#define DATE "2015"
#define VERSION "0.10"
#define DATE "2016"

/* HTTP server defines */
#define SERVER "crelay/"VERSION
Expand Down
61 changes: 58 additions & 3 deletions src/relay_drv_sainsmart16.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,60 @@
* along with crelay. If not, see <http://www.gnu.org/licenses/>.
*
*****************************************************************************/

/******************************************************************************
* Communication protocol description
* ==================================
*
* Read command
* ------------
*
* Request (16 bytes)
*
* Send the following buffer using hid_write():
* RD LN 11 11 11 11 11 11 11 11 'H' 'I' 'D' 'C' CS CS
*
* RD: read command (0xD2)
* LN: message length (excluding checksum)
* CS: checksum bytes (16 bits)
*
* Response
*
* Receive the response using hid_read():
* XX XX BM BM
* BM: Relay state bitmap (16 bits)
* XX: unknown meaning
*
* Relay State Bitmap:
* 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 bits
* +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
* | 15| 0 | 14| 1 | 13| 2 | 12| 3 | 11| 4 | 10| 5 | 9 | 6 | 8 | 7 | relay number
* +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
*
* Write command
* -------------
*
* Request (16 bytes)
*
* Send the following buffer using hid_write():
* WR LN BM BM 00 00 00 00 00 00 'H' 'I' 'D' 'C' CS CS
*
* WR: write command (0xC3)
* LN: message length (excluding checksum)
* BM: Relay state bitmap (16 bits)
* CS: checksum bytes (16 bits)
*
* Response:
* None
*
* Relay State Bitmap:
* 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 bits
* +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
* | 15| 14| 13| 12| 11| 10| 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | relay number
* +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
*****************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -267,9 +321,10 @@ int set_relay_sainsmart_16chan(char* portname, uint8 relay, relay_state_t relay_
return -2;
}

printf("Sain16 USB: portname=%s, relay=%d, state=%s\n",
portname, relay, relay_state == ON? "ON" : "OFF");

/*
printf("DBG: Sain16 USB: portname=%s, relay=%d, state=%s\n",
portname, relay, relay_state == ON? "ON" : "OFF");
*/
/* Read relay states */
if (get_mask(hid_dev, &bitmap) < 0)
{
Expand Down

0 comments on commit 54edc0e

Please sign in to comment.