Shop OBEX P1 Docs P2 Docs Learn Events
writing to text files? — Parallax Forums

writing to text files?

jtsmithjtsmith Posts: 8
edited 2007-08-12 03:29 in BASIC Stamp
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
«1

Comments

  • Kevin WoodKevin Wood Posts: 1,266
    edited 2007-03-27 01:05
    The BS2 can't directly write to a text file - you will need to write or use a program that can do so.

    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
  • jtsmithjtsmith Posts: 8
    edited 2007-03-27 01:07
    thank you!! I really appreciate it.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-03-27 01:14
    You could also use PLX-DAQ Data Acquisition for Excel, available for free download from the following link. Take care.

    http://www.parallax.com/html_pages/downloads/software/software_plxdaq.asp

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • jtsmithjtsmith Posts: 8
    edited 2007-03-27 01:20
    thanks!
  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-27 03:08
    Bean (Hitt Consulting) make a very easy to use data logger that works well with a Stamp and comes with some examples of this use. It can write text to a PC compatible file on an SD card. It can also read such a file. Have a look: hittconsulting.com/products/.
  • stamptrolstamptrol Posts: 1,731
    edited 2007-03-27 12:26
    The other thing you can do is set up a terminal program ( Hyperterminal, Procomm, etc) on the PC and put it into "log" or "capture" mode. The incoming text will get saved in one file for later use.

    Not as slick as PLX, but will be available on nearly every PC!

    Regards,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
  • bytor95bytor95 Posts: 53
    edited 2007-03-27 16:59
    The simplest and cheesiest thing you can do is to send the data to the debug terminal

    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
  • QuattroRS4QuattroRS4 Posts: 916
    edited 2007-03-27 20:31
    Jtsmith,
    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
  • QuattroRS4QuattroRS4 Posts: 916
    edited 2007-03-28 03:00
    I wrote that utility ... attached find utility.zip

    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
  • jtsmithjtsmith Posts: 8
    edited 2007-03-28 18:10
    for my project I am building a traffic system that detects when someone has violated the traffic laws i.e. running a red light. Once a car runs a red light a transmitter located on each car will send a unique id to the receiver. Once the receiver gets this unique id I need to send that id to a text file so that my partner can retrieve this info and identify the person in his database and send the violator a online ticket.

    So basically once I serin the info from the receiver, I need to send that info to a text file.
  • QuattroRS4QuattroRS4 Posts: 916
    edited 2007-03-28 18:24
    will the unit be attached to a p.c ?

    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'
  • jtsmithjtsmith Posts: 8
    edited 2007-03-29 19:11
    yes, the unit will be attached to a p.c.

    I'm trying it out now, I'll let you know how it works.
  • jtsmithjtsmith Posts: 8
    edited 2007-03-29 20:42
    Thanks, to everyone for all your suggestions!

    Simple Stamp logger did the trick! thanks again QuattroRS4
  • QuattroRS4QuattroRS4 Posts: 916
    edited 2007-03-30 02:33
    Great ..

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Necessity is the mother of invention'
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-03-30 14:53
    On the subject of writing data to text files I had written a small program some time ago in QuickBASIC 4.5 which was a small stand-alone EXE that would simply take serial input and write/append it to a TXT file. The limitations were 9600 bps and you could only use COM1 through COM4 (Nothing higher was supported). Now with the Vinculum it would be easier to have the BASIC Stamp write directly to a USB Thumb Drive and get the data from there. That way you wouldn’t be tied to the PC during logging. Either works though. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • QuattroRS4QuattroRS4 Posts: 916
    edited 2007-03-30 17:12
    Chris,
    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 SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-03-30 21:35
    Yeah, but QB45 and PDS7 were all I owned until VB3...Now I have VB6 abd VB2005 and was thinking about building a few Serial front ends for BASIC Stamps but the serial port stuff is pretty weak in the newer VB. It seems everything is dependant on outside code to do most of the work.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • QuattroRS4QuattroRS4 Posts: 916
    edited 2007-03-31 02:14
    You are right - It is pretty weak - but dev. the samples with vb6 - using all the nicities of vb2005 and have a few interop dlls and its not so bad - but yeah - not ideal

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Necessity is the mother of invention'
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-03-31 02:37
    Do you have any straight serial examples for VB2005 without adding user code?· Based on an article in Circuit Cellar I was thinking about experimenting with what's in the free version so anyone could use the resulting code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • QuattroRS4QuattroRS4 Posts: 916
    edited 2007-03-31 17:00
    Chris,
    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 SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-03-31 17:35
    Thanks! I will check it out this afternoon! I was up late last night trying out a few examples I found but unlike previous versions of VB these required references to external objects (imports)...Ah how things have changed...Seems like I can't keep up with VB...I was going to break out my copy of RealBASIC today if I didn't come up with something.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • QuattroRS4QuattroRS4 Posts: 916
    edited 2007-03-31 22:19
    I have Included a .Net logging tool which writes sent and received data to a html file and displays it on web browser
    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
    542 x 742 - 77K
    543 x 742 - 64K
  • QuattroRS4QuattroRS4 Posts: 916
    edited 2007-04-01 04:16
    Based on recommendations by Chris Savage - whereby he pointed out that it would be nice to have a serial port setup form rather than an external file (e.g. Ini file) - I have included the latest version - this has a tabbed main form where the serial port setup is on Tab 1 and the logging utility is on Tab 2 ... Com port look up etc included...





    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
    552 x 694 - 42K
    552 x 694 - 65K
    554 x 695 - 78K
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-04-01 05:08
    Hi Quatro, I think what you and Chris are hatching is going to prove to be a popular extension or accessory to the Stamp environment. The screen shots look professional, the inclusion of a tab or a menu screen makes it more user friendly. If it were possible I might suggest several tabs or a menu structure with generic interfaces that can tackle different scenarios. I am sure it will grow as you go.

    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.
  • QuattroRS4QuattroRS4 Posts: 916
    edited 2007-04-01 05:16
    Jeff T I appreciate it .... I may just drop the source here and see what comes of it ..
    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
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-04-01 06:49
    Jeff,

    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
  • T ChapT Chap Posts: 4,223
    edited 2007-04-01 11:18
    Chris

    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
  • QuattroRS4QuattroRS4 Posts: 916
    edited 2007-04-01 15:00
    Hello All - Decided to add a 'Refresh Port List' button - I was testing Port Enumeration and noticed that if I removed or Added a USB to Serial device I Had to Close/Open the application to Re-Enumerate the Ports ... Now sorted with a 'Refresh Port List' button on the 'Setup' window.

    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
    554 x 694 - 49K
    552 x 694 - 65K
    554 x 695 - 78K
    408 x 253 - 13K
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-04-01 16:47
    TC,

    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
  • T ChapT Chap Posts: 4,223
    edited 2007-04-01 17:55
    Anyone that already has Rb or wants to dl the demo, here are some things you can play around with. There are two files uploaded. One is just a serial port tester where you can see incoming data in one window, and you can type and send in another. There is a user defined button where you can set that button to output a string of your own definition inside the code, which is fairly easy to find by looking around, then clicking on the methods to see the code. The second file is where you can extract parts of the "write to text" section for your own use.

    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.
    1081 x 526 - 109K
    424 x 313 - 31K
Sign In or Register to comment.