BaCon Bits
Big Bass,
Thanks for the links, but they are not very useful for me.
Your example (parallel port output) uses the SYSTEM command from BaCon to call a compiled C program. The other links show snippets of C functions that could be compiled to a library.
If I could program in C and compile it, I would probably do the whole project in C. This info is simply over my head (capacity)
Does make me feel stupid though...
Volhout
Thanks for the links, but they are not very useful for me.
Your example (parallel port output) uses the SYSTEM command from BaCon to call a compiled C program. The other links show snippets of C functions that could be compiled to a library.
If I could program in C and compile it, I would probably do the whole project in C. This info is simply over my head (capacity)
Does make me feel stupid though...
Volhout
Hey VolhoutVolhout wrote:Big Bass,
Thanks for the links, but they are not very useful for me.
Your example (parallel port output) uses the SYSTEM command from BaCon to call a compiled C program. The other links show snippets of C functions that could be compiled to a library.
If I could program in C and compile it, I would probably do the whole project in C. This info is simply over my head (capacity)
Does make me feel stupid though...
Volhout
you did this which is many times more complex
http://www.murga-linux.com/puppy/viewto ... 7&start=48
first you had to compile the driver "ftdi_drv.bac
you also had to link a lib
you used peek and poke and pure HEXBaCon driver for FTDI USB-SERIAL convertor chips. Uses compiled libraries
' from FTDI : libftdi-0.19. When compiled (./configure, make, make install)
' this library generates libftdi.so.1
then IMPORTED thats a lot of work so
since you can do that this will be easy for you
the way I did it was easy sorry if I did a poor job explaining the easy part
I compiled a C app and showed the needed compile command to do it
so you just cut and paste that in a terminal
* I also linked a pre compiled binary of the C code
you dont have to think in C code because
once you have the binary in the path
it does all the dirty work of communicating with the system automatically
then instead of using HEX
you output in decimal the decimal value of the HEX
you want to send or receive to the port
you can PM me at any time
I would like to learn how to do this with the USB !
so we can share our fun
P.S is the USB code you posted
the final working code you use?
if not could you post the source that does compile correctly
Joe
edited typo code for could
Last edited by big_bass on Wed 21 Dec 2011, 17:41, edited 1 time in total.
FTDI driver for bitbang mode
Hi Big Bass,
Yes, I got the bitbang driver working for the FTDI FT245BM chip.
I'll list the code I used here. The project was abandoned when I readlized that the FTDI chip would be really slow to generate I2C in bitbang mode. But if you need 8 IO pins from USB, you can use my code.
It uses a second BaCon program, I call the driver module.
The ftdi library (libftdi.so.1) is the one I compiled from ftdi source code. Get it from their website. If you used WARY 5.1.4 I can send you the .so file, otherwise you have to compile it yourself.
Good luck with it. You are free to post this anywhere on the BaCon website as a working solution. This location may not be the best place to have this posted.....
Regards,
Volhout
Yes, I got the bitbang driver working for the FTDI FT245BM chip.
I'll list the code I used here. The project was abandoned when I readlized that the FTDI chip would be really slow to generate I2C in bitbang mode. But if you need 8 IO pins from USB, you can use my code.
Code: Select all
'-------------------------------------------------------------
'
' program to test the driver glue layer in ftdi_drv.bac
'
' 2011-09-02 Harm de Leeuw
'--------------------------------------------------------------
INCLUDE "ftdi_drv.bac"
LOCAL data TYPE unsigned char
LOCAL mask TYPE unsigned char
PRINT "connect to USB module with FT245BM"
'<D0,D3> output, <D4,D7> input
mask = 0x0F
ft245bm_open (mask)
PRINT "device connected, enabling bitbang mode"
PRINT "start banging"
FOR data = 0 TO 254
'write 0x00 .... 0xFE
ft245bm_poke (data)
'and read back, but <D4,D7> read actual input values
PRINT RIGHT$(HEX$(ft245bm_peek()),2)
NEXT data
PRINT "stop banging, disable bitbang mode"
ft245bm_close ()
END
Code: Select all
'---------------------------------------------------------------------------
' BaCon driver for FTDI USB-SERIAL convertor chips. Uses compiled libraries
' from FTDI : libftdi-0.19. When compiled (./configure, make, make install)
' this library generates libftdi.so.1
' 2011-09-02 Harm de Leeuw
'---------------------------------------------------------------------------
' Version
' 0.1 Supports open(mask), poke(byte), and close()
' 0.2 Added peek() function
'---------------------------------------------------------------------------
TRAP LOCAL
' Import some calls first
CONST library$ = "libftdi.so.1"
' Get the functions from the library
IMPORT ftdi_init(long) FROM library$ TYPE int
IMPORT ftdi_usb_open(long,int,int) FROM library$ TYPE int
IMPORT ftdi_get_error_string(long) FROM library$ TYPE char* ALIAS ftdi_get_error_string$
IMPORT ftdi_read_chipid(long,long) FROM library$ TYPE int
IMPORT ftdi_usb_close(long) FROM library$ TYPE int
IMPORT ftdi_deinit(long) FROM library$ TYPE void
IMPORT ftdi_write_data(long,long,int) FROM library$ TYPE int
IMPORT ftdi_set_bitmode(long,unsigned char,unsigned char) FROM library$ TYPE int
IMPORT ftdi_disable_bitbang(long) FROM library$ TYPE int
IMPORT ftdi_usb_get_strings(long,long,long,int,long,int,long,int) FROM library$ TYPE int
IMPORT ftdi_read_pins(long,long) FROM library$ TYPE int
CONST TYPE_AM = 0
CONST TYPE_BM = 1
CONST TYPE_2232C = 2
CONST TYPE_R = 3
CONST TYPE_2232H = 4
CONST TYPE_4232H = 5
CONST BITMODE = 0x01
' BaCon does not know types so we define
' a RECORD with the needed members
RECORD ftdic
' USB specific
LOCAL usb_dev TYPE long
LOCAL usb_read_timeout TYPE int
LOCAL usb_write_timeout TYPE int
' FTDI specific
LOCAL type TYPE int
LOCAL baudrate TYPE int
LOCAL bitbang_enabled TYPE unsigned char
LOCAL *readbuffer TYPE unsigned char
LOCAL readbuffer_offset TYPE unsigned int
LOCAL readbuffer_remaining TYPE unsigned int
LOCAL readbuffer_chunksize TYPE unsigned int
LOCAL writebuffer_chunksize TYPE unsigned int
LOCAL max_packet_size TYPE unsigned int
' FTDI FT2232C requirecments
LOCAL interface TYPE int
LOCAL index TYPE int
' Endpoints
LOCAL in_ep TYPE int
LOCAL out_ep TYPE int
' General
LOCAL bitbang_mode TYPE unsigned char
LOCAL eeprom_size TYPE int
LOCAL error_str TYPE char*
LOCAL async_usb_buffer TYPE char*
LOCAL async_usb_buffer_size TYPE unsigned int
END RECORD
'-----------------------------------------------------------------------
SUB ft245bm_open (unsigned char io_mask)
'-----------------------------------------------------------------------
' this function initializes the FTDI 245 BM chip attached to the USB bus
' of the PC in bitbang mode (8 bit wide IO port). The io_mask define the
' data direction ("1"=out, "0"=in).
' timing: every byte write takes 1 milisecond, regardless CPU speed.
IF ftdi_init(ADDRESS(ftdic)) < 0 THEN
PRINT "ftdi_init failed"
END 1
END IF
ret = ftdi_usb_open(ADDRESS(ftdic), 0x0403, 0x6001)
IF ret < 0 THEN
PRINT "unable to open ftdi device: ", ret, " (", ftdi_get_error_string$(ADDRESS(ftdic)), ")"
END 1
END IF
ret = ftdi_set_bitmode(ADDRESS(ftdic), io_mask, BITMODE)
IF ret < 0 THEN
PRINT "unable to set bitmode: ", ret, " (", ftdi_get_error_string$(ADDRESS(ftdic)), ")"
END 1
END IF
END SUB
'-----------------------------------------------------------------------
SUB ft245bm_poke (unsigned char data)
'-----------------------------------------------------------------------
' this function sends out a byte to the 8 bit wide io port of the ftdi
' 245bm chip. The actual data output is masked by the io_mask set in
' the init command.
ret = ftdi_write_data(ADDRESS(ftdic), ADDRESS(data), 1)
IF ret < 0 THEN
PRINT "unable to write: ", ret, " (", ftdi_get_error_string$(ADDRESS(ftdic)), ")"
END 1
END IF
END SUB
'-----------------------------------------------------------------------
SUB ft245bm_close ()
'-----------------------------------------------------------------------
' this function disconnects the ftdi 245bm chip from the USB bus.
' first bitbang mode is disabled, putting the io pins in tristate.
ret = ftdi_disable_bitbang(ADDRESS(ftdic))
IF ret < 0 THEN
PRINT "unable to close ftdi device: ", ret, " (", ftdi_get_error_string$(ADDRESS(ftdic)), ")"
END 1
END IF
ret = ftdi_usb_close(ADDRESS(ftdic))
IF ret < 0 THEN
PRINT "unable to close ftdi device: ", ret, " (", ftdi_get_error_string$(ADDRESS(ftdic)), ")"
END 1
END IF
ftdi_deinit(ADDRESS(ftdic))
END SUB
'-----------------------------------------------------------------------
FUNCTION ft245bm_peek () TYPE unsigned char
'-----------------------------------------------------------------------
' this function reads the 8 io pins from the ftdi 245bm chip, and returns
' the value. The value read is depending on the mask set when opening the
' connection.
LOCAL data TYPE unsigned char
ret = ftdi_read_pins(ADDRESS(ftdic), ADDRESS(data))
IF ret < 0 THEN
PRINT "unable to read: ", ret, " (", ftdi_get_error_string$(ADDRESS(ftdic)), ")"
END 1
END IF
RETURN data
END FUNCTION
'-----------------------------------------------------------------------
Good luck with it. You are free to post this anywhere on the BaCon website as a working solution. This location may not be the best place to have this posted.....
Regards,
Volhout
Hey VolhoutGood luck with it. You are free to post this anywhere on the BaCon website as a working solution. This location may not be the best place to have this posted.....
I wouldnt want to start a thread in BaCon with your code
because if an edit is needed it would be better for you to be the author of the thread
however there are a few Bacon users here and if anyone asks for USB info I will kindly link them to your code here
thanks for posting your code !
Joe
FTDI project posted
Hi BigBass,
I have posted the latest version of the project on the BaCon forum.
http://basic-converter.proboards.com/in ... 196&page=1
Hope it is to someones benefit.
Regards,
Volhout
I have posted the latest version of the project on the BaCon forum.
http://basic-converter.proboards.com/in ... 196&page=1
Hope it is to someones benefit.
Regards,
Volhout
I need to check if a config. file`s setting is the same as the current one.
# Can Bacon read a file that assigns variables like Bash can by sourcing?
IF NOT... Then I came up with this code mess:
The Bacon parser errors on the REPLACE line. Says: Can`t parse it.
# Can Bacon read a file that assigns variables like Bash can by sourcing?
IF NOT... Then I came up with this code mess:
The Bacon parser errors on the REPLACE line. Says: Can`t parse it.
Code: Select all
INCLUDE "/usr/share/BaCon/hug_imports.bac"
'# File: /tmp/0 has the line: A = "aaa"
Set$ = "A"
Val$ = "AAA"
Cmd$ = CONCAT$("cat /tmp/0")
Cfg$ = CHOP$(EXEC$(Cmd$))
SPLIT Cfg$ BY NL$ TO Lines$ SIZE Lsize
OPEN /tmp/0 FOR WRITING AS file
FOR i = 0 TO Lsize - 1
SPLIT Lines$[i] BY " " TO Col$ SIZE size
IF Col$[0] = Set$ THEN
PRINT Col$[2], " ", Val$
IF Col$[2] != Val$ THEN
PRINT Lines$[i]
REPLACE$(Lines$[i], Col$[2], Val$)
END IF
END IF
' WRITELN Lines$[i] TO file
NEXT
CLOSE FILE file
Hey sunburnt
GatorDog has several examples using
http://murga-linux.com/puppy/viewtopic. ... &start=114
I tried also to understand the same thing you are trying to do and this is an
example code I made for myself to get an idea how to get the strings into an array
http://murga-linux.com/puppy/viewtopic. ... &start=382
Joe
GatorDog has several examples using
http://murga-linux.com/puppy/viewtopic. ... &start=114
I tried also to understand the same thing you are trying to do and this is an
example code I made for myself to get an idea how to get the strings into an array
http://murga-linux.com/puppy/viewtopic. ... &start=382
Joe
Code: Select all
COLOR FG TO BLUE
PRINT
PRINT "================================="
PRINT " READ"
PRINT "/etc/rc.d/PUPSTATE"
PRINT "================================="
PRINT
COLOR RESET
OPEN "/etc/rc.d/PUPSTATE" FOR READING AS myfile
WHILE NOT(ENDFILE(myfile)) DO
READLN txt$ FROM myfile
IF NOT(ENDFILE(myfile)) THEN
'---remove all lines that are bash commented # ---'
SYSTEM ("sed /^#/d /etc/rc.d/PUPSTATE > /tmp/newPUPSTATE")
'---remove all lines that have bash single quotes ---'
SYSTEM ("sed \"s/'//g\" /tmp/newPUPSTATE > /tmp/newPUPSTATE2")
PRINT txt$,NL$;
ENDIF
WEND
CLOSE FILE myfile
PRINT "--------"
COLOR FG TO BLUE
PRINT
PRINT "================================="
PRINT " WROTE"
PRINT "/tmp/newPUPSTATE2"
PRINT "================================="
PRINT
COLOR RESET
'--- cat the file into an array using x$ --'
x$ = EXEC$("cat /tmp/newPUPSTATE2")
SPLIT x$ BY NL$ TO myarray$ SIZE mysize
'--- this prints all arrays --'
FOR x = 0 TO mysize - 1
PRINT myarray$[x]
NEXT
COLOR FG TO GREEN
PRINT
PRINT "================================="
PRINT " READ arrays"
PRINT "from /tmp/newPUPSTATE2"
PRINT "================================="
PRINT
COLOR RESET
'--- this prints only the first array --'
PRINT myarray$[0]
'--- this prints only the scecond array --'
PRINT myarray$[1]
'--- this prints only the third array --'
PRINT myarray$[2]
Came up with this simple solution.
READCFG returns the setting value: Val$
WRITECFG modifies the config. file`s setting value.
CfgFile$ = /path/config.file
Set$ = Val$ ................................ Example: FilePath = (/path/file)
.
# Time to start making executables and function files for this reusable code.
Seems best to make this part of an executable library, just run it...
Easier to use in programs that way rather than writing: INCLUDE (file) (function).
But maybe the INCLUDE parser can be extended with added libraries?
.
READCFG returns the setting value: Val$
WRITECFG modifies the config. file`s setting value.
CfgFile$ = /path/config.file
Set$ = Val$ ................................ Example: FilePath = (/path/file)
Code: Select all
' read config. file setting
SUB READCFG(STRING Set$)
IF FILEEXISTS(CfgFile$) = TRUE THEN
Cmd$ = CONCAT$("grep ", Set$, " ", CfgFile$, "|cut -d' ' -f3")
Val$ = CHOP$(EXEC$(Cmd$))
END IF
END SUB
' write config. file setting
SUB WRITECFG(STRING Set$, STRING Val$)
Cmd$ = CONCAT$("echo \"$(<", CfgFile, ")\" |sed \"s/^", Set$, ".*$/", Set$, " = ", Val$, "/\"")
New$ = EXEC$(Cmd$)
SYSTEM CONCAT$("echo \"", New$, "\" > ", CfgFile$)
' PRINT New$
END SUB
# Time to start making executables and function files for this reusable code.
Seems best to make this part of an executable library, just run it...
Easier to use in programs that way rather than writing: INCLUDE (file) (function).
But maybe the INCLUDE parser can be extended with added libraries?
.
No one seems to be responding to vovchik`s thread, so I`ll risk double posting here...
I`m writing a function file to do file I/O for text and arrays.
Strange problem with writing an array to a file.
Error is: Cause: 'Size' undeclared here (not in a function)
It looks like the Size needs to be a literal declaration.
If so, then passing an array to a SUB can`t be done.
To use a global array not a passed one, limits the usefulness of the function.
The Bacon docs say the array dimension isn`t needed to pass it to a SUB.
But that errors saying:
ERROR: cannot pass string array without dimension at line 54 in file 'test_FileIO.bac'!
So you can pass a numerical array without a dimension, but not a string array?
If that`s the case, then the Bacon docs should mention that little detail...
.
I`m writing a function file to do file I/O for text and arrays.
Strange problem with writing an array to a file.
Code: Select all
SUB OUTARRAY(STRING Txt$[Size], int Size)
OPEN File$ FOR WRITING AS file
FOR i = 0 TO Size-1
WRITELN Txt$[i] TO file
NEXT
CLOSE FILE file
END SUB
It looks like the Size needs to be a literal declaration.
If so, then passing an array to a SUB can`t be done.
To use a global array not a passed one, limits the usefulness of the function.
The Bacon docs say the array dimension isn`t needed to pass it to a SUB.
But that errors saying:
ERROR: cannot pass string array without dimension at line 54 in file 'test_FileIO.bac'!
So you can pass a numerical array without a dimension, but not a string array?
If that`s the case, then the Bacon docs should mention that little detail...
.
-
- Posts: 186
- Joined: Sun 17 Jun 2007, 18:25
Bacongui
How do I get Bacongui installed in Racy?
I downloaded and compiled BaCon, and am able to compile and run the examples from the web page using Geany.
But when I try to compile Bacongui, it fails, maybe because the version of Bash is 3.0 and it needs 4? There is a Pet for 4, I installed it, but it says the executable is named to Bash4. Am I going to have to change stuff around?
Thanks for any help you can give ...
Damn I hate being such a noob. I tried all this awhile back in Wary and ended up giving up after breaking a bunch of stuff trying to change and install things, when I had to concentrate on work. Decided I'd be better off waiting for a newer Puppy to try to use for Bacon programming.
--97T--
I downloaded and compiled BaCon, and am able to compile and run the examples from the web page using Geany.
But when I try to compile Bacongui, it fails, maybe because the version of Bash is 3.0 and it needs 4? There is a Pet for 4, I installed it, but it says the executable is named to Bash4. Am I going to have to change stuff around?
Thanks for any help you can give ...
Damn I hate being such a noob. I tried all this awhile back in Wary and ended up giving up after breaking a bunch of stuff trying to change and install things, when I had to concentrate on work. Decided I'd be better off waiting for a newer Puppy to try to use for Bacon programming.
--97T--
- L18L
- Posts: 3479
- Joined: Sat 19 Jun 2010, 18:56
- Location: www.eussenheim.de/
Re: Bacongui
I don't know because I use geany only.NinerSevenTango wrote:How do I get Bacongui installed in Racy?
Maybe a pet from http://bkhome.org/blog2/?page=13 will work for you
NinerSevenTango,
I was not able to compile with the new version of bacongui.bac either.
Try compiling this older version - I have bash 3 and it compiles ok in Precise 5.4.3 using bacon29.
It is very slow starting the first time.
Cheers,
s
I was not able to compile with the new version of bacongui.bac either.
Code: Select all
Problem:
file 'bacongui.bac' line 3150: ptr$ = EXTRACT$(var$, "\"-./_()")
Cause:
passing argument 1 of 'strdup' makes pointer from integer without a cast [enabled by default]
It is very slow starting the first time.
Cheers,
s
- Attachments
-
- bacongui.bac.tar.gz
- older version of bacongui.bac
- (57.84 KiB) Downloaded 390 times
seaside; That`s the same error I was getting.
Compile the latest bacon.bac and use the latest hug.bac
The new command EXTRACT is the problem here...
http://basic-converter.proboards.com/in ... thread=466
http://basic-converter.org/hug.bac
Keep keying the code good buddy.!
Compile the latest bacon.bac and use the latest hug.bac
The new command EXTRACT is the problem here...
http://basic-converter.proboards.com/in ... thread=466
http://basic-converter.org/hug.bac
Keep keying the code good buddy.!
Last edited by sunburnt on Sun 28 Apr 2013, 17:58, edited 1 time in total.
Sunburnt, great to hear from you.
Just got the same type of error compiling the latest bacon.bac 2.1.2 which was being compiled by bacon binary (1.0 build 29 patch 2) on bash 3. # bacon bacon.bac
How did you get it working?
Best regards,
s
Just got the same type of error compiling the latest bacon.bac 2.1.2 which was being compiled by bacon binary (1.0 build 29 patch 2) on bash 3. # bacon bacon.bac
Code: Select all
Problem:
file 'bacon.bac' line 541: ptr$ = EXTRACT$(var$, "\"-./_()")
Cause:
passing argument 1 of 'strdup' makes pointer from integer without a cast [enabled by default]
Best regards,
s