B4J Question python run in B4J directly

jinyistudio

Well-Known Member
Licensed User
Longtime User
Hi

lots of Raspberry PI shield(Hardware) have always supported with python.
Cloud I directly call python function to access those Raspberry shield and i don't need to transfer python to b4j ?

Bye
 

alwaysbusy

Expert
Licensed User
Longtime User
I run python scripts like this on my raspberry pi (where the output in the script is written to the stdout):

B4X:
Sub btn1_Clicked(Target As String)
    page.Pause
    Dim shl As Shell
    shl.Initialize("shl", "python", Array As String("myscript.py"))
    shl.WorkingDirectory = "/home/pi/B4J/Reader"
    shl.Run(30000)   
End Sub

Sub shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
   If Success And ExitCode = 0 Then
         Log("Success")    
         Log(StdOut)
        Dim list3 As ABMList = page.Component("list3")
         list3.Clear
        Dim lbl As ABMLabel = page.Component("lbl")
        lbl.Text = ""
         Dim sp() As String = Regex.Split("\n", StdOut)
         For i = 0 To sp.Length-1
             Select Case True
            Case sp(i).StartsWith("SERIAL:")
                i = i + 1
                lbl.Text = "Scanner: " & sp(i).SubString2(sp(i).Length-6,sp(i).Length)
               
            Case sp(i).StartsWith("BARCODES")
                i = i + 1
                Do While Not(sp(i).StartsWith("DONE"))
                    list3.AddItem("list" & i, BuildSimpleItem("lbl" & i, sp(i)))
                    i = i + 1
                Loop
               
            End Select       
         Next
        Log("done")
        lbl.Refresh
        list3.Refresh
        myToastId = myToastId + 1   
        page.ShowToast("toast" & myToastId, "toastgreen", "De scanner is uitgelezen", 5000)       
        list3.refresh
  Else
        Log("Error: " & StdErr)
        myToastId = myToastId + 1   
        page.ShowToast("toast" & myToastId, "toastred", "De scanner is niet uitgelezen", 5000)       
        list3.refresh
  End If
 
   page.Resume  
End Sub
 
Upvote 0

jinyistudio

Well-Known Member
Licensed User
Longtime User
Hi

Thank's your information.
Do you know how to call python sub-function(Or Python Object) inside a python script(or library) ? as following http://pi-plates.com/code/
 
Upvote 0
Top