B4J Question call a Python script in Raspberry Pi

jcohedman

Member
Licensed User
Longtime User
I`m trying to read RFID in a Raspberry Pi.
If I run in the raspi: $ sudo python rfidle.py, functions...
But with B4j, not...
can anybody help me? Thanks!

Sub AppStart (Args() As String)
Dim sh As Shell

' sftp://pi@192.168.1.15/home/pi/pi-rc522/examples/rfidle.py

sh.Initialize("sh", "python", Array As String("rfidle.py", "w", "B4J is", "great"))
sh.WorkingDirectory = "/home/pi/pi-rc522/examples/"
sh.Run(10000)

StartMessageLoop
End Sub

Sub sh_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
If Success And ExitCode = 0 Then
Log("Success")
Log(StdOut)
Else
Log("Error: " & StdErr)
End If
'ExitApplication
 

jcohedman

Member
Licensed User
Longtime User
Yes, sudo java -jar b4j-bridge.jar

Error log:
SyntaxError: invalid syntax

I was searching, and found that the problem is in the python script, it's recomended to do this:
B4X:
print ("HelloWorld",flush=True)

but...
 
Upvote 0

wonder

Expert
Licensed User
Longtime User
Upvote 0

jcohedman

Member
Licensed User
Longtime User
solved at "argentininan" style...

Python script:
B4X:
#!/usr/bin/python3import sys

from pirc522 import RFID

import signal

import time

sys.path.insert(0, "/home/pi/pi-rc522/ChipReader")

rdr = RFID()

util = rdr.util()

util.debug = False

while True:

# Request tag(error, data) = rdr.request()

if not error:

# print ("\nDetected")(error, uid) = rdr.anticoll()

if not error:

file = open("foo.txt", "w")
file.write(str(uid[0])+str(uid[1])+str(uid[2])+str(uid[3]))
file.close() 
print (str(uid[0])+str(uid[1])+str(uid[2])+str(uid[3]))

time.sleep(1)

so, in B4J for raspberry:


B4X:
Sub BuscarRFID_Action
    Dim shl As Shell
    shl.Initialize("shl", "python", Array As String("lectorRFID1.py"))
    shl.WorkingDirectory = "/home/pi"'
    shl.Run(500)
End Sub

Sub shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
    If File.Exists("/home/pi", "foo.txt") Then
    Dim text As String
    text = File.ReadString("/home/pi", "foo.txt")
        If text.Length>5 Then
            Log("RFID: "&text)
            File.WriteString("/home/pi", "foo.txt"," ")
        End If
End If
End Sub
 
Upvote 0
Top