We'll add another widget to Hello BaCon and then look
into processing the information gathered.

Concept- If we want to count out 5 apples, we don't call the
first apple zero. However, computers like to start counting at zero.
(We don't). Bacon has an option that specifies to start counts with
1 instead of zero. "OPTION BASE 1". Put that near the top of the
program. See the BaCon doc for further information.

The ENTRY widget allows the user to type in some piece
of information. Their name for example. This is how we'll
set up an info label and an ENTRY widget.

Now to write a function named FUNCTION PLACE_ORDER.
We'll only do minimal amount of error checking.
GRAB$(widget_) gets the text, if any, that is in the ENTRY widget.
The double set of double quotes stands for a "null" string (ie. nothing).
If ENTRY is blank, we'll just wait until the customer
is ready to let us know their name The CHOP$ command removes any
leading or trailing spaces or tabs.

Next we'll check to see if there are spaces in the name. Maybe they
entered their first and last names. To do this, we use the SPLIT
command. We use the space character as the seperator (if there is one).
ex. SPLIT String_to_split$ BY character_to_split_on TO an_array_name$ SIZE how_many_names.
After SPLIT seperates the string into individual smaller chunks (array), it sets
the "how_many_names" variable to the number of smaller chunks. If the customer
entered their first and last name, how_many_names will be set to 2. If there is only
one name, SPLIT is happy setting how_many to one. By the way, if we hadn't used
the "OPTION BASE 1" mentioned earlier, we'd be working with 0 and 1. One meaning
that there are actually two items. (That can get confusing quick.) Any way,
using SPLIT we can make sure we have a single name and that's all the error
checking we'll do on that item.

Refer to the following function code for the rest of this discussion.
Grab the drink order with Drink$ = GRAB$(Drink_combo_) .

The radio buttons for slice thickness take a little more work. We have
to check each one to see which is selected. It will be TRUE if it is selected,
otherwise FALSE. This is a simple IF/THEN test so we can use the shortened IF/THEN syntax.

Now check if they're ordering eggs, and if so grab that information.
The call to our SHOW_ORDER function opens a message box so that the customer
can confirm the order is correct.

Sooner or later you'll write a program that collects some data that you'd
like to save for later use. That's where File I/O - Input/Output comes in.
The general flow is -
OPEN file
WRITE data
CLOSE file
There are variations on this. For example putting the WRITE data in a loop
to write several data samples. Reading the data back in is -
OPEN file
READ data
CLOSE file
Again with some variations in setup.

BaCon has several directives for File I/O. Here I'll cover plain ASCII
reading and writting which uses the READING, WRITING, APPENDING directives.
READING is for reading in data from a file. WRITING and APPENDING both
write to a file. The difference being that WRITING will overwrite an
existing file with the new data. APPENDING adds the data to the end of
an existing file. Here I'll be using READING and WRITING.

First let's create a gui that asks for three pieces of data, and a button.
(The button doesn't do anything yet.)

Use CONST and variables wherever you can for dimentioning and placing
widgets. It allows you to change your gui with a single edit.
The above code creates our main gui window. Then three labels and three
ENTRY fields. Then the labels and entry (widgets) are attached to the main
window. The button is also created and attached to the bottom of the window.

Our save file will need a name. This can be done with the FILEDIALOG widget
but for now we'll just hard code it to save the file in our HOME directory.
We'll add this to our CONST's -

Code:

CONST Filename$ = CONCAT$( GETENVIRON$("HOME"), "/my_file.txt")

Now we'll add a SUBroutine to write the data to the file (my_file.txt", and a
CALLBACK that runs the SUB when the "Save" button is clicked.

The subroutine name is SAVE_TO_FILE. We'll put this above the MAKE_GUI subroutine.

Compile and run. Enter some data into the blanks. Click "Clear", the data
will erase.

Now we'll add a button, callback and subroutine to "read" the data from the
file, and populate the entries in the gui. Again, button and callback to the
end of MAKE_GUI and the subroutine above MAKE_GUI.

Compile and run. Now you can enter and save data. Clear the data fields and
read and display previously saved data.

This is pretty much Straight Up no frills File I/O. For saving and reading a
few pieces of data, it works fine. For a larger number of fields, a loop of
some sort will make more sense.

*Note: All ENTRY fields are text or string data. That means that even numbers are
GRABed from and ENTRY and treated as text or string data. However! Your program
can write a "number" to a file. But! when you read it in, you read it in as a
string variable and if necessary convert it back to a number with VAL(Var$).

[i]I am trying to write a BaCon glue layer to the FTDI (USB serial port) chip. I plan to use this chip in bitbang mode to get 8 individual IO pins.

I managed to connect to the chip, to write data out, and to read data back. Problem is that each write or read takes 1 msecond.
I want to test if sending out multiple bytes in 1 write command achieves a faster throughput. The C-code header file allows this.

I get a compiler error that data is converted from pointer to integer. Whereas I defined data as a string.

The problem is in the IMPORT definition of 'ftdi_write_data'. This is defined as follows:

Code:

IMPORT ftdi_write_data(long,long,int) FROM library$ TYPE int

As you can see, BaCon now expects the second argument to be a 'long' while you are trying to send a string.

The issue is solved when this definition is corrected. Also according to these docs the second argument should be a string. Therefore, change the IMPORT into the following:

Code:

IMPORT ftdi_write_data(long,char*,int) FROM library$ TYPE int

Of course, you need to remove the ADDRESS construct from the second argument if you invoke this function, and also change the 'ft245bm_poke' function. Its argument should be a STRING also, and should be invoked as follows:

Thanks for your help. It compiles now, and it actually works. GREAT !!
I think I was lucky that the poke worked

Final goal is to implement I2C through this interface, and the functions that I have now are sufficient to do I2C writes, and with carefull design, even I2C ACK. Still need to think about I2C read . If I bitbang that then it will be terribly slow.

Searched but didn`t find any examples of how to use it.
TEXT creates a new tab, and I assumed new widgets go on the new panel.
The list boxes on the panels are good, but the buttons are off the bottom.

TEXT creates a new tab, and I assumed new widgets go on the new panel.

Yes. Attaching new widgets to a tab goes on the currently active tab. If you want
to place something on a previously created tab, you first need to select the tab
with, for ex. SET(tab0_, n). (The first tab being "0" zero).

If you haven't tried bacon3G yet, give it a go. (Gators Gui Guide for HUG).
For example under "Widgets", scroll down to Notebook, and see-

Code:

NOTEBOOK
Notebook_ = NOTEBOOK("caption", xsize, ysize)

Creates a notebook with one tab containing a caption, and a width of xsize
and a height of ysize.

A notebook tab is treated as a window, that is you can directly attach
widgets to it. In essence, notebook tabs are a collection of windows.

- Add a widget to the current tab - ATTACH(Notebook_, Widget_, xpos, ypos)

- Get caption in the active tab - Var$ = GRAB$(Notebook_)

- Get current tab number - Var = GET(Notebook_)

- Set current tab to, (first tab is zero) - SET(Notebook_, n)

- You either populate a tab immediately after defining it or you will have to
set the tab as the current tab with SET(Notebook_, n) before populating it.

As you'll see, it's an attempt to pull the information for HUG widgets together.
There are some examples for using widgets like the MSGDIALOG.
Preview of the gtk-stock buttons and a color chart with hex code and color
names. I keep it handy while I'm makin' Bacon'

The attached is the source and a compiled (standalone) version of bacon3G.

Missing for me also. I don't know if they are missing in Puppy or there's a problem with gtk
I included them so it can be seen first off that the icon isn't working; rather than finding it out over and over again the hard way.

Quote:

It looks like there`s another tab to the right of MEMO, but it`s off the GUI.

Ok thanks for feedback. Did you by chance recompile and change the font size or dpi?
I used the sizes that Barry recommended for use in Puppy, which seems to work well for me.
ie. HUGOPTIONS("BASEXFTDPI 78") and HUGOPTIONS("FONT DejaVu Sans 12")
I think the reason Barry came up with those HUGOPTIONS is so that a GUI would
look good regardless of what "theme" the user is running.
But it would be good to know if there is a problem with them.

You can change "CONST Mainwin_width = 525" to something a little wider (550 for example)
and recompile. Be sure to use at least Bacon beta 24 and hug 61 from a previous post above
or grab the latest beta's from here. Although it doesn't look like HUG is in the beta dir right now.
Or I can recompile one for you with a wider setting.

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum