2
$\begingroup$

In Blender Game Engine, I'm trying to get input from an RFID reader that reads data in form of 10 digits e.g. 0010293221. I've tried using the 'Keyboard' sensor to get the key. And I've also tried using the 'Always' sensor with true pulse mode too. The key was read fine but not all of it. For example, the RFID that suppose to be read is 0010293221, but I got 01293 or something like this. Let's say it skipped some digit (not particular digit but different digits in each reading) and it didn't read all 10. Sometimes I got 5 digits, sometimes 3, or 1...

I've tried reading and put the input into others program e.g. Notepad and even Blender Text Editor window and it worked just perfect. All 10 digits were read correctly. But within the runtime game there's problem like I describe above.

It seems like the key input from the RFID reader is too quick (frequent) for BGE or else?

Anyone have any solution for this? Please help me.

Thank you.

$\endgroup$
  • $\begingroup$ Does the RFID reader work in a OS console? $\endgroup$ – stacker Mar 10 '14 at 6:50
  • $\begingroup$ Yes. It works perfectly in OS console or any text editor. Only in running BGE doesn't work as expected. $\endgroup$ – Sanchai Noichan Mar 11 '14 at 7:41
  • $\begingroup$ Instead of having the rfid reader imitate a keyboard can you use a python module that talks directly to the reader? What about a script using input()? $\endgroup$ – sambler Mar 11 '14 at 9:09
  • $\begingroup$ I've tried using the input() function in a separated thread but it just waits for input in the console window not the game window. Do you know any other python module that can do so something like that? $\endgroup$ – Sanchai Noichan Mar 12 '14 at 10:18
1
$\begingroup$

This may be a problem with the frequent changing of frames (including logic events) in the game engine. Using the subprocess module to start a new process outside of the game engine main loop may solve the problem.

For example, this is what I used to retrieve data from an HTTP server and communicate what I had fetched back to the game engine.

import bge
import subprocess

gD = bge.logic.globalDict

if gD['OS'] == 'Linux':
    saa = subprocess.Popen(gD['ModulePath']+'RetrieveFormData.py', shell=False, stdin=subprocess.PIPE)
    goa = saa.communicate(bytes(gD['ServerIP']+','+gD['InstallationPath'],'utf-8'))
if gD['OS'] == 'Windows':
    saa = subprocess.Popen([sys.executable,gD['ModulePath']+'RetrieveFormData.py'], shell=False, stdin=subprocess.PIPE)
    goa = saa.communicate(bytes(gD['ServerIP']+','+gD['InstallationPath'],'utf-8'))

I hope this provided you with a clue if nothing more.

$\endgroup$
  • $\begingroup$ Thanks. It worked. I used it to open a new program I wrote in C# to detect keyboard input. After the program get input, it shuts down to send the input back to BGE. $\endgroup$ – Sanchai Noichan May 12 '14 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.