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

7
  • 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. Commented Dec 9, 2017 at 2:54
  • Thank you, I would appreciate your help. Somehow this code of mine doesn't seams to get reply Commented Dec 11, 2017 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? Commented Dec 11, 2017 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; chat.stackexchange.com/rooms/70067/… Commented Dec 11, 2017 at 19:29
  • Unfortunate T_T "You must have 20 reputation on The Stack Exchange Network to talk here. See the faq." Commented Dec 12, 2017 at 0:46

1 Answer 1

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                 
Sign up to request clarification or add additional context in comments.

3 Comments

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 ?
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?
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.