1

SAAT-520Wireless-Communication-Programming-Development-ProtocolI've been trying to send Lowlevel commands to my RFID to get device information. I'm using wireshark to tap the connection and it seams to be fine as packets seem to go and come from my PC to RFID device and vice versa.

But I'm unable to see any response or output on my program. On the device note I have response command, I'm not sure should I and/or where I can use command response.

Import socket

TCP_IP = '192.168.0.238'
TCP_PORT = 7086
BUFFER_SIZE = 20
MESSAGE = '0x55, 0x00~0xFF, 0x01, 0x00, 0x00~0xFF'

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
    s.connect((TCP_IP, TCP_PORT))
except:
    print ('failed' + TCP_IP, 'down')
s.sendall(MESSAGE)
data = s.recv(BUFFER_SIZE)
s.close()
print 'received', repr(data)

I don't understand why there is no response from my program. No error nor program is successful. Just process never ends.

Also please find the notes for commands in the attachment.

System Information Query Command (0x01H)

img1

Command Response

img2

  • I think you send format may be wrong, I think you want a list of strings, not a single strong with commas. Let me know if you still need help and I'll pull up my code to verify. – SteveJ Dec 09 '17 at 02:54
  • Thank you, I would appreciate your help. Somehow this code of mine doesn't seams to get reply – Vijay Reddy Dec 11 '17 at 17:31
  • I was wrong - comma list is how I do it as well. However, look at your message data. I don't think you are supposed to literally put in '0x00~0xFF'. I think that means you need a single value within that range. In the documentation, can you find an example of a successful send-packet? – SteveJ Dec 11 '17 at 19:16
  • I've created a specific room for our back and forth conversation - I'm willing to work with you to get through this if you would like; https://chat.stackexchange.com/rooms/70067/python-rfid-help-for-specific-question – SteveJ Dec 11 '17 at 19:29
  • Unfortunate T_T "You must have 20 reputation on The Stack Exchange Network to talk here. See the faq." – Vijay Reddy Dec 12 '17 at 00:46
  • https://stackoverflow.com/questions/33653345/raw-client-server-socket-python – Vijay Reddy Dec 12 '17 at 18:26
  • All that post is saying essentially is that using raw sockets you don't have a predefined handshaking protocol at the software level. The two sockets in the party have to agree on what data to exchange. To fix your problem -- you NEED to get an example of a successful send packet. The manufacturer should be able to get you that. Then you have to confirm that you packet matches the example. I think you will find at least that '0x00~0xFF' as a single entry is a problem. – SteveJ Dec 12 '17 at 18:33

1 Answers1

0

(From your question)

s.sendall(MESSAGE)
data = s.recv(BUFFER_SIZE)
s.close()

You are sending data via send, immediately asking for the response data, then closing the socket. Enough time will not have passed for you to get a response. For testing, try placing a time delay between.

import time
s.sendall(MESSAGE)
time.sleep(5)
data = s.recv(BUFFER_SIZE)
print(data)
s.close()

You can also wait for the incoming data;

import time
s.sendall(MESSAGE)
while data is None:
    data = s.recv(BUFFER_SIZE)
    print "No data, waiting...."
    time.sleep(0.5)

print "Data arrived"
incoming = data.decode('utf-8')
print incoming
# Process Data

I did personally have an issue if my buffer size was too small -- I had to catch the timeout exception to deal with it. Perhaps try increasing your buffer size.

Below is something close to the actual code I use for my application; It python 3.x, and you will have to condition it a bit -- but it works for me.

            try:
                data = s.recv(buf_len)
                if data is not None and len(data) > 0:
                    while True:
                        new_data = s.recv(buf_len)
                        if new_data is None or len(new_data) == 0:
                            break
                        data = data + new_data

            except socket.timeout:
                if data is not None and self.callback is not None:
                    logger.debug(f"Received packet: {data}")   

incoming = data.decode('utf-8')
print incoming
# Process Data                 
SteveJ
  • 3,034
  • 2
  • 27
  • 47
  • Program in still running but no output response, same as before. Should I be using data.decode('utf-8') to get my output in string ? And am'i missing command response ? – Vijay Reddy Dec 07 '17 at 20:33
  • Im using Python 2.7 and still I never get response. Seams like I am missing something. I also tried sending other commands to activate my device but doesn't work. You getting response for the code? – Vijay Reddy Dec 11 '17 at 19:13
  • 1
    I'm not using RFID, I've written a similar application recently to communicate with a different low-level hardware device, so I cant speak directly to the RFID requirements. What I have in this answer will help you with the receive, but I think that you have a problem with your send data. I think you need to get rid of the "xxxx~yyyy" and replace with a single "xxxx". We should probably move this to a chat room -- I'll see if I can figure out how to set one up. – SteveJ Dec 11 '17 at 19:21