Share My Creation B4Rh2xml UI Simple tool to create B4R xml file from B4R header file

Discussion in 'B4R Share Your Creations' started by max123, Jun 22, 2017.

  1. max123

    max123 Active Member Licensed User

    Hi all,

    I'm trying to learn how to create B4R libraries and convert libraries that I wrote with Arduino IDE for Arduino and ESP8266. I have to convert six libraries already working on Arduino IDE and all with sample code, and one library is about 1600 lines of code, so I start my work here for B4R conversion.

    In this direction I used the B4Rh2xml tool made by Erel to create B4R xml files from B4R header files.

    Since this tool is a command line, I decided to create a simple GUI version with B4J.

    This simple tool internally uses B4Rh2xml from Erel. It is very easy to use, just copy the Jar file on your hard drive on any position you want, launch it, push a button, at this point you are prompted to choose the header file on your hard drive, select it and then if all goes well, the tool create the xml file in the same directory of the header file. If you see errors, then your header file is not in correct format.

    The first time you press a button after the tool started, it point to Jar file directory, after this the tool remember your last directory, this happens until it restarts. (if averyone interested I can change it to save permanently last directory on exit, so next time you start, it remember last directory before close it)

    Anyway, I decided to release both the simple source code, either the entire B4J project and also the already compiled executable jar file.

    I hope you'll use this tool when creating your B4R libraries.

    Comments and improvements are welcome, but sorry for my not good english.

    Hello everyone,
    and good programming with B4X tools!!!

    B4J Source code:
    Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private sh As Shell
    Private CurrentDir As String = ""
    Private TextArea1 As TextArea
    Private Button1 As Button
    End Sub

    Sub AppStart (Form1 As Form, Args() As String)
        MainForm = Form1
    "Layout1"'Load the layout file.
        MainForm.RootPane.Style = "-fx-background-color: lightgray;"
        MainForm.Title = 
    " B4Rh2xml  -  Utility to create B4R xml file from B4R header file."
    End Sub

    Sub MainForm_CloseRequest (EventData As Event)
    End Sub

    Sub sh_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
    If Success And ExitCode = 0 Then
    "XML file created successfully." & CRLF)
    "Error: " & StdErr)
    End If
    End Sub

    Sub sh_StdOut (Buffer() As Byte, Length As Int)
    End Sub

    Sub sh_StdErr (Buffer() As Byte, Length As Int)
    End Sub

    Sub AddText(Text As String)
        TextArea1.Text = TextArea1.Text & Text & 
    End Sub

    Sub Button1_Action
        TextArea1.Text = 

    Private fileChooser As FileChooser

    If CurrentDir = "" Then
    fileChooser.InitialDirectory = File.DirApp
            CurrentDir = 
    fileChooser.InitialDirectory = CurrentDir
    End If

    fileChooser.SetExtensionFilter("B4R Header file"Array("*.h"))
    Dim FullHeaderPath As String = fileChooser.ShowOpen(MainForm)

    If FullHeaderPath <> "" Then
    Dim FullXmlPath As String = FullHeaderPath.Replace(".h",".xml")
    Dim XmlPath As String = File.GetFileParent(FullXmlPath)
    Dim XmlFileName As String = File.GetName(FullXmlPath)
            CurrentDir = XmlPath

    "XML Path: " & XmlPath)
    "XML Name: " & XmlFileName)

    If File.Exists(XmlPath, XmlFileName) Then
    Dim response As Int = fx.Msgbox2(MainForm, "The file " & FullXmlPath & " already exists." & CRLF & CRLF & _
    "This operation are undone, remember to make a backup copy before overwrite it." & CRLF & CRLF & _
    "Do you want overwrite this file?" & CRLF," ATTENTION: FILE ALREADY EXISTS!","Yes, overwite it""", _
    "No, don't overwrite it", fx.MSGBOX_CONFIRMATION)
    If response = fx.DialogResponse.POSITIVE Then
                    CreateXmlFileFromHeaderFile(FullHeaderPath, FullXmlPath)
    CRLF & "You Aborted overwrite.")
    End If
                CreateXmlFileFromHeaderFile(FullHeaderPath, FullXmlPath)
    End If
    CRLF & "You Aborted last operation.")
    End If
    End Sub

    ' To pass arguments on jar file:
    ' Pass them after the jar File name, they will be treated as strings, then in the
    ' called jar they will be available in the args() array.
    ' Example: java -jar myJarFileToRunWithShell.jar arg1 arg2 arg3
    ' Spaces separate the items so if you sent hello world, that is two arguments.
    ' To make it one argument enclose in double quotes "hello world".
    Sub CreateXmlFileFromHeaderFile(inputPath As String, outputPath As String)
    Dim jarFile As String = "B4Rh2xml.jar"
    Dim jarPath As String = File.Combine(File.DirTemp, jarFile)
    Dim javaexe As String = File.Combine(GetSystemProperty("java.home"""), "bin/java")

    CRLF & "Input Path: " & inputPath)
    "Output Path: " & outputPath & CRLF)
    "Creating XML file: " & outputPath & CRLF)

    File.Copy(File.DirAssets, jarFile, File.DirTemp, jarFile)

    Dim sh As Shell
    "sh", javaexe, Array ("-jar", jarPath, inputPath, outputPath))
    End Sub

    Attached Files:

    Last edited: Oct 30, 2018
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice