1

Good day,

This is going to be long. I'm trying to communicate with the "SainSmart iMatic with RJ45" board, which is used together with the "SainSmart 16-Channel 12V Relay Module".

Basically, I'm able to send hex commands to the board, successfully, but can't receive a response from the board when required. What do I mean with this?

I have a laptop with Ubuntu 14.04.4 LTS connected directly to the board via an Ethernet Straight through cable (no longer crossover type needed). I have a configuration for this type of network (only two devices). The IP of the imatic board is fixed, 192.168.1.4 with port 3000. My laptop IP has a fixed IP of 192.168.1.2, with netmask 255.255.255.0, and no gateway.

I'm using netcat (in TCP protocol mode) in my laptop to send commands to the board in this format in terminal : echo '580112000000016C' | xxd -r -p | nc 192.168.1.4 3000 How do I know it works? Well, basically the relays from a secondary board are turned on successfully ("SainSmart 16-Channel 12V Relay Module").

There's a list of hex commands to turn on and off each relay. In the previous instruction, I'm telling the board to turn on the relay number 1, leaving the other 15 off. The string '580112000000016C' is converted from hex into binary with xxd, and then sent into the netcat. This part works.

The only instruction that doesn't work is this one: echo '580113000000006C' | xxd -r -p | nc 192.168.1.4 3000 This instruction only asks the board which relays are off an on at the moment, expecting a response in this format: 28 01 00 00 00 XX XX HH (XX XX 16 bit, each bit represents one relay state, "1" indicates on, "0" indicates OFF; HH is the sum of all previous data together, meaning it works as a checksum)

I've already tested and proved that, this is NOT an issue from the board. I wrote a code in visual basic, and windows was able to receive the response from the board, but something has to be wrong in my ubuntu configuration. I've already disabled my firewall, ufw. This is NOT a problem with the Ethernet cable. I've already tried other command representations such as: echo -n '5801100000000069' | xxd -r -p | nc -v -n -w3 192.168.1.4 3000 | xxd I've already used netcat to scan all available ports in the board, and only the 3000 port is shown as available, as stated from the manufacturer. This seems to be a network configuration problem though, but in windows, I specified the same IP, and netmask as in ubuntu.

What am I mising here?

  • Hello, I'm trying to control the board in C++, but I'm not able to find the list of HEX commands to use in order to switch ON/OFF the relays. I have the board with 16 relays. I tried to read the manual, but I didn't find any reference table with the commands. Can you help me, please? – Marcus Barnet Aug 25 '19 at 08:49
  • 1
    Hi, It would be impossible to list them all in here, but i'll post the link. You will see the whole list starting from : "580112000000016C", – Berham Horadrim Aug 27 '19 at 02:56
  • 1
    Here it's the link. https://www.amazon.de/SainSmart-Channels-Network-Controller-Arduino/product-reviews/B00OZ81HV4 – Berham Horadrim Aug 27 '19 at 02:57
  • 1
    Here there's another link: https://www.amazon.de/review/R1UPGUYFD5W15 – Berham Horadrim Aug 27 '19 at 02:57
  • Thank you so much! Since I need to control the board by using C++, I just need to open a TCP connection and send a data packet with "580112000000016C" (or any other command in the list) to turn on/off the relays? – Marcus Barnet Aug 27 '19 at 06:37

1 Answers1

1

Netcat is waiting for an EOF character, which is never sent by the iMatic board. That explains why netcat can't receive the response ever.

On the other hand, I wrote a python script (Python 2.7.6) which successfully receives the data from the iMatic board, after sending to it a certain instruction. Here it is:

import socket 
import binascii  

IPADDR = '192.168.1.4' 
PORTNUM = 3000 
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
s.connect((IPADDR, PORTNUM)) 
data = '5801100000000069'.decode('hex') 
s.send(data) 
response= s.recv(8) #Buffer needs to be 8 for the fastest response without losing information 
print binascii.hexlify(response) 
s.close() 

You can use this board now without a router, and directly connected to any computer through an Ethernet cable.

Regards, Bernext.