writing to text files?
jtsmith
Posts: 8
I am trying to complete a senior project and using BS2·I need to be·able to write data to text files so my partner can retrieve the info. If anybody and I mean anybody has a idea on how to write to files using BS2 please let me know! examples, sourcecode, links anything would be helpful
Comments
For writing a program, any language that can do serial comms & text files would work. Some easily obtained options are Perl, Python, Tcl, VB.Net, C#, C/C++, and Java.
You could also take a look at StampPlot Pro, which is an inexpensive data logger that is BS2 compatible. You can find more info here: www.selmaware.com
http://www.parallax.com/html_pages/downloads/software/software_plxdaq.asp
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
Not as slick as PLX, but will be available on nearly every PC!
Regards,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·
example: If all you want is a copy of the x variable's output:
debug dec x, cr
But programs like excel want each value to be separated by a comma or a space so do this:
debug dec x,", "
This would give you 3, 5, 11, 52, 255, 5, for example
Then copy and paste the output to a text file and then open it up with whatever program. I figured that's all you may need for your project.
Hope that helps.
Engin
Post Edited (bytor95) : 3/27/2007 6:52:22 PM GMT
If you were to provide me with a sample of what you want to log to a text file - I can knock something together for you in either vb6 or .NET .... where by if you sent a string from the Stamp with Serout - The application would append a log file with Date , Time and the data - for a quicker solution - if you were to stick to a fixed output string length outputted from the stamp this could be done very quickly and easy to format... with no need for timeouts or string manipulation and a 3 wire interface rx,tx,gnd.
Quattro
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Necessity is the mother of invention'
Post Edited (QuattroRS4) : 3/28/2007 1:53:24 AM GMT
There is the SSlogger.exe (simple stamp logger)
·················SSLogger.ini (setup file)
unzip the files to a path of your choice but ensure both files are in the same path...
set the ini file to to your needs - it has [noparse][[/noparse]PORT] - under which is the com port no. default 1
·····················································[noparse][[/noparse]SETTINGS] - default 9600,n,8,1
·····················································[noparse][[/noparse]DATALENGTH] - the data length expected default 10
vb6 runtimes may be required .....
a simple stamp prog. if using the programming cable -
' {$STAMP BS2}
' {$PBASIC 2.5}
DO
SEROUT -1,16468,[noparse][[/noparse]"1234567890"]
PAUSE 1000
LOOP
yes thats a -1 !!!
You can use what ever pin you decide to output to - the examples here show methods using
the programming cable.
Which does the same as the following - except the following example requires that the debug
window which pops (parallax debug window)·up must be closed before the application (sslogger.exe) is started.
' {$STAMP BS2}
' {$PBASIC 2.5}
DO
DEBUG "1234567890"
PAUSE 1000
LOOP
The examples above send '1234567890' repeatedly ...
once the·stamp is programmed start up this application - it will create a txt file in the application path you will see the date and time of the latest log entry on the screen.
When the application loads - the log file is loaded to the top Text area (this will be blank when first loaded) pressing the 'refresh' button reloads the log file with all new entries.
It is a quick and dirty example for you !·- all of 15mins - let me know how you get on...
I can improve it if there is a demand - i.e expect certain chars as start/end chars and not have a defined length of expected data string.... etc..etc..
All comments welcome - I hope I didn't waste 15mins of my life !!!
Quattro
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Necessity is the mother of invention'
Post Edited (QuattroRS4) : 3/29/2007 1:47:48 PM GMT
So basically once I serin the info from the receiver, I need to send that info to a text file.
The example above will allow you to 'serout' the data to a p.c running the application and·append a log file - try it out and let me know ....
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Necessity is the mother of invention'
I'm trying it out now, I'll let you know how it works.
Simple Stamp logger did the trick! thanks again QuattroRS4
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Necessity is the mother of invention'
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
I remember those days - but you could use 'fossil' drivers to get more than 4 ports ...Or better still Power Basic had (still have) a nice QBasic equivalent ..... I'd agree though - I'd rather not have to attach a p.c
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Necessity is the mother of invention'
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Necessity is the mother of invention'
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
I have knocked together an example of a transmit / receive Vb.NET 2005 version for you using serial port control. Is this what you were looking for ?
A small bit of work and an external config file could be added to allow adjustment of settings etc..and add a bit of error checking.. but you get the general idea ..
Currently only set to Com1 9600,n,8,1 .... using the native .NET 'SerialPort' control - for those who are more familiar with the older legacy version of VB6 - it is also possible to port that to .NET - .. but a compiled version would have interop dll's ... this way its much cleaner and smaller..
LATEST UPDATE:
12 August 2007 added the following with new features !
http://forums.parallax.com/attachment.php?attachmentid=48674
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Necessity is the mother of invention'
Post Edited (QuattroRS4) : 8/12/2007 4:02:25 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
I have also included the option to print .....
edit the ini file '[noparse][[/noparse]RECEIVED_DATA_LENGTH]' to set up length of string expected from stamp ....
will include better error checking and improvements if people find this useful...
Unzip and keep all 3 files in the same path.....
default set up is same as VB6 example ...
LATEST UPDATE:
12 August 2007 added the following with new features !
http://forums.parallax.com/attachment.php?attachmentid=48674
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Necessity is the mother of invention'
Post Edited (QuattroRS4) : 8/12/2007 4:02:44 AM GMT
LATEST UPDATE:
12 August 2007 added the following with new features !
http://forums.parallax.com/attachment.php?attachmentid=48674
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Necessity is the mother of invention'
Post Edited (QuattroRS4) : 8/12/2007 4:03:06 AM GMT
It doesn't look like you need it but if you do need any help with routines I have some pieces I coded for the Stamp and an error check routine for the com port.
Jeff T.
Just updated it - to get rid of a silly error ... its pretty basic at the minute ... but as time goes by and there is a greater degree of error checking it will ,hopefully, get better.
I can see the point Chris was making though - the .NET environment is completely changed
a simple thing like 'App.Path' - pointer to application path now becomes 'System.Windows.Forms.Application.StartupPath'
I find myself dimensioning older style names - e.g.
Dim AppPath as string
AppPath = System.Windows.Forms.Application.StartupPath
and so on with so many more .....
I have made modules with all such references -·so as to speed·up the dev....
Chris - has also correctly highlighted the points that
········· 1) serial port contol examples for .NET 2005 are few and far between
········· 2) The extra reference·calls as 'Imports' are·odd.
········· 3) There is a 'Strongly Typed Code' ethos now - no more defining unused variables.
········· 4) Simple updating of·'Controls'·by variables·outside·the actual thread require
············· you to 'Invoke' a 'Delegate' etc .....
With my first introduction to .NET·- I remember thinking 'I am going to throw this p.c. out the window' !! but it sort of grows on you. That said .NET 2005 is streets ahead of .NET 2003.
Ideally though I prefer all things Linux - but because 90% of customers are 'Microslop'! based - it leaves me with no choice. I have had limited success with apps running on Linux using 'Wine' but not enough to seriously consider·it as a sole option. Silly things like form.opacity - on a fade in/out form cause problems and·when the likes of this happen it is difficult enough to debug when its not on its native environment..
Rgds,
Quattro
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Necessity is the mother of invention'
Post Edited (QuattroRS4) : 4/1/2007 1:44:17 PM GMT
I was trying to come up with some simple code for VB or RealBASIC (Both of which I have), but VB has changed so much. It seemed Quattro knows enough about it to help me realize some sort of simple interface for the BASIC Stamps, perhaps for control or logging. Certainly his examples are proof that this isn’t that difficult. I myself needed some concrete examples though…The ones in MSDN are fragments, which, without a standing example leave you more confused amidst the numerous extra requirements of VB over previous versions. I simply don’t have the time to experiment with it so I’m hoping to get enough building blocks to share. I for one am glad for the examples. Thank you Quattro!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
I have a RB project that writes info from several sliders and buttons to text files. The info that it writes could come from anywhere though. You are welcome to gut it and use it for something other than what it does. It could easily take input and append a text file with some work, Quatro's idea is already tops, so no need to reinvent unless you just want to fool around with Rb some.
TC
Post Edited (TChapman) : 4/1/2007 11:39:52 AM GMT
Also added some more error checking ......
I think this will be the last installment for a while - some more pressing (Work Related) issues to sort ....
If somebody finds any Glaring errors or has some ideas on how to improve it - Let me know..
Later -
Quattro
UPDATE
Noticed a BaudRate Change Issue - now sorted
Also a note - If you delete or remove the log file either by accident or for what ever reason - Start the application - select the comport and 'Open' it - go to the log file window - click 'ok' on the Log.HTML file missing error - Press the 'transmit' button - and it should recreate a blank log.html in the application path...
Also I plan a name change 'SSDotNet' has to go - meant to mean 'Simple Stamp .NET' - but has the same name as some virus out there !!!
LATEST UPDATE:
12 August 2007 added the following with new features !
http://forums.parallax.com/attachment.php?attachmentid=48674
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Necessity is the mother of invention'
Post Edited (QuattroRS4) : 8/12/2007 4:01:34 AM GMT
I bought RealBASIC over 2 years ago with the sole intention of giving up VB6 and using RealBASIC for my BASIC Stamp Serial interfacing…I just never got the time to mess with it. As it stands I have yet to re-install it since I rebuilt my computer but am planning on it. I want to get both VB and RB running with some examples for a few BASIC Stamp applications. So basically I am looking for all the examples I can get. I am adept at creating my own programs in general so something that has examples of enumerating ports, opening them and sending receiving data I can easily translate that to my own use. I could of course go through all the tutorials and experiment like in the good ol’ days but I have so many more pressing BASIC Stamp Projects our forum members could use. So anyone who has the above to share it would be most appreciated. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
In Rb there are methods to create a new file, or append. With the temp application, it just keeps appending an existing file, but this could be changed internally to write new files as desired, with a small effort to read the manual and tutorials to get an understanding of files usage. The text file on a PC is just a standard .txt. If can be opened and manipulated just like any other text file. I included a pic of each, the Temp Profiler is for reading a thermocouple and controlling an oven temp for reflow soldering. You can set the times and temp limits, then name the preset. The Store Preset button appends the preset name, plus all values of the sliders and buttons, to the text file in a tab delimited row. There may need to be an empty file located in the same folder as the app called "profiles.txt". (Well, it may just create it if missing, I forgot what I did on it). The idea is that the info written to the text file could be anything, in this example though, it is tab delimited, I think it was space terminated, you can figure out the rest just by digging around in the Rb app. An almost infinite length data logger could be built using incoming serial strings. The strings would just need to be terminated and appended to the file depending on the needs. There is a crude chart feature on the temp profiler, it reads real time temp input and charts it on a graph, I never finished it so that it looks great, but the idea could be used for something else with a little effort. This app requires an SX powered external board with a thermocouple sensor like what Parallax sells, so forget about trying to really get temp with it alone.
The default is 9600, and can be changed inside it by looking around at where it is set. A button could be placed with options as well.