C learning Print function
I was experimenting with some of the Learn C examples which use print function. I can't get anything with print function to compile if I use printf function it compiles fine. I searched the simple tools reference but no print. Could someone please point me to a reference or explain the difference between print and printf?
I eventually want to print to the terminal from different cores which seems to be another issue.
Thanks
Steve
I eventually want to print to the terminal from different cores which seems to be another issue.
Thanks
Steve
Comments
I have a library for multicog print - I don't have access to the computer it's on right now, but I'll try to upload it to github or to the Propeller Object Exchange when I can. It gives each cog its own fake serial device that just writes stuff into a circular buffer, and then a cog constantly goes through all of the buffers and, when it finds one with a complete line, it prints a header (i.e. "[cog 0] ") and then the line. IOW, it lets multiple cogs use the terminal at the same time and makes sure their lines don't get mixed up with each other, at the expense of a cog.
http://learn.parallax.com/multicore-approaches/cores-sharing-data
The other is stop the terminal process in one cog, then restart it in another, like this:
http://learn.parallax.com/multicore-approaches/print-different-core
There's an error in the Print from a Different Cor page. It is corrected in the example program in SimpleIDE. cog_run(..., 10) changed to cog_run(...128).
The page has been updated.
The error is Simpletext.h no such file or directory i. I don't know what happened. I tried to reinstall it a couple times but same result.
The latest version for Mac is 1.0 RC2, available for download from this page:
http://learn.parallax.com/propeller-c-set-simpleide/mac
0.9.66 was linked on this page as well, I have removed it to
I still get error missing simple text.h when I try to build.
I don't know what else to try.
Thanks,
I tried to attach a screen shot of the error message.
I don't see any reference to simpletext in your screen shot build info. The build error rescue output is more complete. It's in the help menu.
I'm not sure I used the standard SimpleIDE naming convention, but libserialmerge.c is a demo, while serialmerge.{c,h} are the actualy library files. SimpleIDE seems to be fine with it.
It doesn't do input yet, and uses a whole cog besides FullDuplexSerial, but I'm thinking that both of these could be solved by doing serial in the multiplexer cog and then only looking for input when a cog requests it (pausing other cogs' streams until a newline comes). You can only have one terminal per cog, as the output buffer to use is automatically selected by cogid. If anyone's interested, I can properly document it and add the input stuff, but I don't use PropGCC that much, so I probably won't be needing these improvements for myself any time soon.
PropWare has synchronous output as well via the SynchronousPrinter class. Example usage here.
I should really finish my serial merger library, it will make a lot more sense then... The main benefit of mine is that it has no locks - cogs never have to wait, each cog just throws data in its own circular buffer. The only problem is when buffer overflows happen - right now, it just drops data because losing debug info was better than any delays in the application I wrote it for. Even after I add input, it will still need no locks.
How do you avoid two cogs writing to the same byte in the buffer? You need to lock your buffer I think, or just accept the risk of sometimes overwriting data. Having buffered UART impls does help a lot with execution time. Thankfully, anything that implements the PrintCapable interface can be used with the SynchronousPrinter (by creating a Printer instance). All you have to do is write (or use an existing) object that has two methods (put_char and puts) and uses a buffered implementation of UART. I've started this, but got side tracked trying to finish the SD implementation in PropWare. For anyone reading this that is interested, feel free to follow the progress of this GitHub issue. Once that issue is complete, buffered, synchronous UART will be available to all
Every cog gets its own buffer. The serial merger cog looks at each cog's buffer in turn, and for each that has at least one newline somewhere, it prints everything until and including the first newline. If two cogs want to print stuff at the same time, one doesn't have to wait for the other (unless one of their buffers is full, which this doesn't really handle right now...). Both cogs just throw stuff in their buffers, and the serial merger cog eventually gets around to actually printing it. Yes, it uses more ram, but for my application there was plenty of free ram and speed (i.e. no lock contention) was of highest importance.
For input (which is not implemented yet), the rx function will set a variable in the calling cog's buffer struct to -1 and then busywait until it changes and then return the new value. If the serial merger cog sees -1 in a cog's input field, it will completely flush that cog's buffer, regardless of whether there's a newline at the end of the last line, and then wait for input, servicing no other cogs' buffers in the meantime, and then continue to read input until that cog prints a newline or some other value signifying that it's done.
To prevent other cogs' buffers from overflowing while one is receiving input, I might do something like have it keep the inputting cog's last line and the part of the line entered so far, printing other cogs' data but then reprinting the inputting cog's stuff at the bottom. This would require full duplex serial (another cog!) and a non-echoing terminal, though (so the inputted characters don't get mixed up in other cogs' output).