Shop OBEX P1 Docs P2 Docs Learn Events
Creating text file using SPIN — Parallax Forums

Creating text file using SPIN

zivepetrovskizivepetrovski Posts: 3
edited 2011-05-03 01:26 in Propeller 1
Hi everyone,

I am new to SPIN and do not have much serial communication experience either. I am trying to create a text file and write data onto it. I only want to write numerical values and am using the full duplex serial communication object file. I am using a SPIN microcontroller. Can anyone help me with a simple code? Thank you for your time.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-05-01 20:09
    First, you need to read the comments in the PUBlic methods in FullDuplexSerial. They explain what the various methods do and what they expect for parameters. You have to initialize the serial port by calling .start with the proper parameters (see the comments).

    To output a single character, use .tx

    To output a numeric value in decimal, use .dec

    To output a constant string or a constructed dynamic string, pass its address to .str
    The string has to be terminated by a zero byte.
  • zivepetrovskizivepetrovski Posts: 3
    edited 2011-05-01 20:30
    I am able to output to the serial terminal but I want to be able to open a text file onto my my pc IE desktop and save data into it. I am unsure if any of these methods do these. Sorry to be so ignorant about this, like I said I'm pretty new to this. And thank you for the quick response :)
  • Mike GreenMike Green Posts: 23,101
    edited 2011-05-01 20:52
    There is nothing the Propeller can do to make the PC put the received text into a file. That is something that has to be done with some kind of a program on the PC. There have been some examples posted on the use of a Visual Basic program on the PC, but I don't have the links. Try a search of the forum for that. You can also use programs written for use with a Stamp like Stamp Plot Pro and PLX-DAQ, both with links on the Downloads webpage for the Basic Stamp. The Propeller can do the same serial I/O as the Stamp.

    I believe the Propeller Serial Terminal can save the text content of the display window to a file. Check the documentation there for details. It's a manual operation, but may be enough for your task.
  • zivepetrovskizivepetrovski Posts: 3
    edited 2011-05-01 20:54
    Thank Mike! I'll see what I can find.
  • StefanL38StefanL38 Posts: 2,292
    edited 2011-05-01 21:02
    Hello zivepetrovski,

    welcome to the forum.

    Writing received data to a textfile on a PC is not a matter of the serial link between the propeller-chip and the PC.
    This has to be done by the receiving software. FullDuplexSerial does nothing else but transferring data.
    The meanings of the data = how the data is interpreted is a different thing. This interpretation has to be done by the receiver.

    As a first test you can use br@y's terminal https://sites.google.com/site/terminalbpp/

    This is a terminal software for PC that has the same functions as PST.EXE but goes beyond that.
    It has a script-interpreter that allows you to code in a PASCAL-style conditional interaction with the propeller-chip

    Of course you can use any kind of programming language that can open/close COM-ports.

    You have to provide more information of what you want to do in the end. How much data? What kind of data?
    It highly depends on your requirements which solution is suitable for your application.

    best regards

    Stefan
  • BluhairBluhair Posts: 7
    edited 2011-05-03 01:26
    Another possible way to write data to a text file is to use the TERMINAL program that is included with Windows (at least up to XP). Use the standard FullDuplexSerial.spin and modifed HelloFullDuplexSerial.spin


    ''HelloFullDuplexSerial.spin
    "Test message to TERMINAL"
    CON

    _clkmode = xtal1 + pll16x
    _xinfreq = 5_000_000


    OBJ

    Debug: "FullDuplexSerial"


    Var
    Long count

    PUB TestMessages

    ''Send test messages to Parallax Serial Terminal.

    Debug.start(31, 30, 0, 57600)

    repeat
    Debug.str(string(" This is a test message!", 13))
    waitcnt(clkfreq + cnt)
    count:= count +1
    debug.dec(count)

    Open the Windows terminal and when prompted enter a name.. "test", ignore telephone numbers. Make sure you are using the correct Serial Port, usually port 1 thru 4. If you only have 1 serial port available. Use the same port as you use to connect to the prop.
    If using only 1 port you will have to run the Prop program prior to connecting to TERMINAL.
    Set the Bits per second (baud to the same as the prop, 57600 in this example) Data bits 8, Parity None, Stop bits 1, Flow Control Hardware.
    Now you can open the Prop Tool, load the above program to ram, click the Terminal and then click Wait for a Call. You should see the results of Prop output in the terminal display. You can use the additional options of the TERMINAL to save to a file or even transmit.
    Hope this helps.
Sign In or Register to comment.