FlexBasic open SendRecvDevice() problem
in Propeller 1
I am having a bit of trouble implementing the use of input #, and print #, in the link_rpi sub COG. The error is showing that there is something wrong with "open SendRecvDevive(@rpi.tx, @rpi.rx, @rpi.stop) as #3", but it looks like I got the right amount of parameters. Must be some thing that I am missing on the usage part.
Ray
Ray
' cr2rpi.bas ' ' Aug 07, 2020 ' ' dim telnet as class using "spin/efds.spin" dim cr2 as class using "spin/efds.spin" dim rpi as class using "spin/efds.spin" telnet.start(31, 30, 0, 115200) cr2.start(0, 1, 0, 115200) rpi.start(2, 3, 0, 115200) open SendRecvDevice(@telnet.tx, @telnet.rx, @telnet.stop) as #2 open SendRecvDevive(@rpi.tx, @rpi.rx, @rpi.stop) as #3 dim inBuff, rpiBuff as string dim cr_volts, highbyte, lowbyte, cr_vval as ushort dim rpi_stack(32) var x_rpi = cpu(link_rpi(),@rpi_stack(32)) cr2.tx(128) 'Passive mode pausems(300) cr2.tx(131) 'Safe mode print #2, "Type 'help' for System Menu!" do print #2, "> "; input #2, inBuff if inBuff = "help" then print #2, "Will be help menu." else if inBuff = "crvolts" then crVolts() else if inBuff = "crpassive" then cr_Passive() else if inBuff = "crsafe" then cr_Safe() else if inBuff = "crreset" then cr_Reset() else if inBuff = "crquit" then cr_Quit() else print #2, "Invalid Command!" end if loop sub crVolts cr2.tx(142) cr2.tx(22) pausems(150) highbyte = cr2.rx() lowbyte = cr2.rx() cr_vval = (highbyte << 8) + lowbyte cr_volts = (cr_vval / 1000) print #2, cr_volts end sub sub cr_Passive cr2.tx(128) end sub sub cr_Safe cr2.tx(128) cr2.tx(131) end sub sub cr_reset cr2.tx(128) cr2.tx(7) end sub sub cr_Quit cr2.tx(173) pausems(1000) end sub sub link_rpi do 'rpiBuff = rpi.Str() input #3, rpiBuff if rpiBuff = "help" then print #3, "Will be..." else print #3, "Invalid Command!" end if pausems(500) loop end sub
"E:/flexgui/bin/fastspin" -D_BAUD=115200 -l -O1 -I "E:/flexgui/include" "E:/programs/flexc/basic/cr2rpi/cr2rpi.bas"
Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2020 Total Spectrum Software Inc.
Version 4.3.1 Compiled on: Aug 15 2020
cr2rpi.bas
|-efds.spin
|-|-FullDuplexSerial.spin
|-efds.spin
|-efds.spin
E:/programs/flexc/basic/cr2rpi/cr2rpi.bas:15: error: Bad number of parameters in call to _basic_open: expected 4 found 2
child process exited abnormally
Finished at Sun Aug 16 17:10:07 2020
Comments
A general question, how many COGs is the program using. My efds.spin uses the fds.spin program. I start up efds.spin three times, does the program use three COGs or is it using six COGs? Also, are the SendRecvDevice() subs using any COGs. Again, I note, the program size is 13948 bytes, close to half the available memory is used up. Not sure how much code refinement could be done to reduce the program size.
I am not sure that the code that I have is starting rpi.start(2, 3, 0, 115200), which is used in the "link_rpi" sub. I did a test by inserting a "print #3, "xxxxx", in the main loop, and nothing is being received on the RPi side. Is there something special about how and where the start() functions should be used. I know the wiring is correct because when I use a SimpleIDE program, it seems to work, as expected.
Ray
I think that in SimpleIDE, when you use Serial, which basically uses FullDuplexSerial.spin, I think you are using two COGs for that functionality, correct. I just wanted to get a better understanding of what .spin programs that are being linked to FlexBasic and FlexC, and COG usage.
I will try to implement that snippet for COGs in use and see if it gives me an indication of how many COGs are in use.
Ray
P.S. I am starting to lament all this programming stuff.
I will "assume" that three of those COGs are the serial("edfs.spin"), and the other one is the "link_rpi" sub. In that case, why is it that when I use "print #3, "xxxxx", in the "link_rpi" COG, I am not getting anything on the RPi side. On the RPi side I used a regular terminal program, and nothing is appearing.
I guess the next question is, does the "SendRecvDevice()" function work the same way in its own COG, as it does in the main program loop? Does the "SendRecvDevice()" call have to be put in the new COG?
Also, the code snippet, will that work in FlexC?
Ray
I'm guessing your problem is that you're doing the rpi.start() on COG 0, but then trying to use it in the link_rpi COG. As I said, I don't know the details of how efds.spin works, but I assume it sets up some pins for I/O. Normally that has to be done on the COG that's going to use them.
The code snippet won't work in FlexC because it's written in BASIC; you'd either have to put it into an object and link to it from C that way, or else translate it to C. The C equivalent of "cpuchk()" is "_cogchk()".
rpi.start(2, 3, 0, 115200)
open SendRecvDevice(@rpi.tx, @rpi.rx, @rpi.stop) as #3
into the "link_rpi" sub COG, after running the COGs snippet, it is now showing that 7 COGs are in use now. I would have thought that only five COGs would be in use. I commented out the "rpi.start(2, 3, 0, 115200)" at the top of the program. Not sure why their was a gain in COGs "in use".
Ray
Running the COGs snippet
The program below compiles, but I am getting some weird feedback. I count 4 COGs that should be started, but the check_cogs() sub is showing 5 COGs in use. Maybe I am missing what the fifth COG is? The link_rpi COG is still not pushing any text out.
Am I missing some big coding idea here?
Ray
I do see one potential big problem: don't use @rpi_stack(32) for the stack in cpu(), use @rpi_stack(0). That could make a big difference, since it means a stack is being corrupted and almost anything could happen.
In the link_rpi sub I used "rpi.tx("a")" to verify that something is working. Yes, it is now showing a "9" instead of an "a". I get a compile error when I tried to use "rpi.tx('a')", for some reason.
I am not sure, but I think there might be a problem when you try to use SendRecvDevice(), the way I was trying to use it.
Ray
I did a compile&run on P1, and the terminal screen is repeatedly printing !!! out of memory !!!, this is a first.
I am also trying to find out if there is a problem with SendRecvDevice(), earlier testing was showing some missteps. Trying to narrow the problem down.
I am giving up on the WiFi SIP module, to many inconsistencies in the way it is responding. I just had a big problem with FlexGUI scanning an trying to find the WiFi. I always double check by using SimpleIDE to see if it makes the WiFi connection.
Ray
Add “CONST HEAPSIZE=8192” to the top of your code and see if that fixes it.
EDIT: if this is compiling on the P1, you will need to change HEAPSIZE=1024 or maybe 2048 seeing how precious memory is.
ADDED: Now that I'm on a real keyboard I can flesh this out a bit better for you. FlexBASIC starts with a default setting for the heap that is very small. The default is 256 bytes for P1 and 4096 bytes for P2. This works well for the P2, but the P1 value is really too small. Even a couple of PRINT statements can swamp that default P1 setting, so start edging the HEAPSIZE value higher until this "out of memory" behavior quits. You can also use _gc_collect() to force the garbage collection to run, but frankly Eric seems to have things so well tuned under the hood that this trick no longer works (ie, FlexBASIC does it automatically, and by the time the programmer tries to tell it what to do, it's already done it and moved along). That being said, an extra _gc_collect() or two is harmless except for the time taken for the call.