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.
On 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, this even will not works in B4Rh2xml NONUI.
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 as it is exactly the Erel's B4Rh2xml but a GUI version.
Comments and improvements are welcome, but sorry for my not good english.
Hello everyone,
and good programming with B4X tools !!!
B4J Source code:
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.
On 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, this even will not works in B4Rh2xml NONUI.
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 as it is exactly the Erel's B4Rh2xml but a GUI version.
Comments and improvements are welcome, but sorry for my not good english.
Hello everyone,
and good programming with B4X tools !!!
B4J Source code:
B4X:
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
MainForm.SetFormStyle("UNIFIED")
MainForm.RootPane.LoadLayout("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."
MainForm.Show
End Sub
Sub MainForm_CloseRequest (EventData As Event)
ExitApplication
End Sub
Sub sh_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
If Success And ExitCode = 0 Then
AddText("XML file created successfully." & CRLF)
AddText(StdOut)
Else
AddText("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 & CRLF
End Sub
Sub Button1_Action
TextArea1.Text = ""
Private fileChooser As FileChooser
fileChooser.Initialize
If CurrentDir = "" Then
fileChooser.InitialDirectory = File.DirApp
CurrentDir = File.DirApp
Else
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
AddText("XML Path: " & XmlPath)
AddText("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 is 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)
Else
AddText(CRLF & "You Aborted overwrite.")
Return
End If
Else
CreateXmlFileFromHeaderFile(FullHeaderPath, FullXmlPath)
End If
Else
AddText(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")
AddText(CRLF & "Input Path: " & inputPath)
AddText("Output Path: " & outputPath & CRLF)
AddText("Creating XML file: " & outputPath & CRLF)
File.Copy(File.DirAssets, jarFile, File.DirTemp, jarFile)
Dim sh As Shell
sh.Initialize("sh", javaexe, Array ("-jar", jarPath, inputPath, outputPath))
sh.Run(-1)
End Sub
Attachments
Last edited: