Shop OBEX P1 Docs P2 Docs Learn Events
Javelin RS232 simple example — Parallax Forums

Javelin RS232 simple example

Sabre3487Sabre3487 Posts: 16
edited 2007-01-05 20:17 in General Discussion
I have a Basic stamp activity board, a Bs2p40 demo board, and the DCE 232 app mod.· I have searched and tried to make existing code work for some rs232 operations.· I want to go back and just try something simple.

I just want to send something to from the stamp to a pc, and from a pc back to the stamp.

Advice, sample code etc....· need help

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-11-18 06:32
    Here are a connection schematic and test program.

    regards peter
  • Sabre3487Sabre3487 Posts: 16
    edited 2005-11-18 06:57
    Ok, this might sound stupid but what exactly is supposed to be displayed?· I would assume the character 'A' or ascii value?·

    I am using a usb converter from parallax, and it works fine.· However i have another one for the App mod.· (this did not work to well with the ide port though).· Nothing is happening.· The code is executing and breaks into both while loops however I get no display of any kind to let me know that it has tx and rx'd?
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-11-18 07:16
    The program sends the character 'A' to the pc, you must then reply with just a key, say 'P',

    and what you typed is echoed back. You should try this with hyperterminal.

    Setup hyperterminal for direct connection to a com port. Settings 9600 baud, 8 databits, no parity,

    1 stopbit. Select no handshake. Local echo off.

    If all is well, any character you type in hyperterminal gets displayed in hyperterminal, proceeded

    by the 'A' character. So if you type PQRST you would see APAQARASAT

    Use a straight 9pin DB9male-DB9female cable to connect the DCE appmod connector with the PC.

    If you only have one comport, program the javelin, then close the JIDE program, then disconnect

    the javelin program cable from both board and pc, then connect the DCE appmod connector to your

    pc com port (you can use the program cable as this is a straight 9pin male-female cable).·Then

    start hyperterminal.

    regards peter


    Post Edited (Peter Verkaik) : 11/18/2005 7:25:25 AM GMT
  • Sabre3487Sabre3487 Posts: 16
    edited 2005-11-18 07:38
    Ok, another stupid question. How do you set up the hyper terminal to accept keyboard input? you said what I type then gets the letter A appended to it. When I open the terminal and set up the connection the cursor just blinks.. Sorry I have never used this before.



    I also have seperate question on your window jide terminal etc. files. What exactly is that for?
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-11-18 07:51
    I have attached a slightly adapted program.

    This program sends out continuesly the last received character and it starts

    with sending 'A' characters. So as long as you don't type anything, you should see

    'A' characters in hyperterminal. If you don't see those, your hyperterminal setup is incorrect.

    Could be the wrong comport or baudrate, parity, handshake settings.

    The moment you get the 'A' characters in hyperterminal, then your hyperterminal setup

    is correct. If you then type another key, say 'P', you will see all 'P' characters.

    Try this and let me know.

    regards peter
  • Sabre3487Sabre3487 Posts: 16
    edited 2005-11-18 08:01
    ok, it repeats A, then if I type something on the terminal it repeats that!
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-11-18 08:03
    If that is happening, you· have the correct setup.

    regards peter
  • Sabre3487Sabre3487 Posts: 16
    edited 2005-11-18 08:12
    atleast now I know I am sending and receiving correct? What do I change to send different data type info?

    What are your JIDE_TERMINAL files on the yahoo post? In searching for rs232 i kept reading about that?
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-11-18 08:29
    I have attached an updated schematic. This has the DCE connectors X2 and X3 drawn, and

    it has a picture of the DCE appmod·printed circuit board.



    You can send anything you want.·What do you want to send and how would you like

    to see that in hyperterminal?

    I will explain about JIDE terminal later.



    regards peter
  • Sabre3487Sabre3487 Posts: 16
    edited 2005-11-18 08:38
    Peter,


    Thanks, I am actually using the DCE mod already. That is what is connecting to the HyperTerminal, I am actually using two usb to serial converters as well. New laptop does not have a serial port. Eventually I want to send stuff from the stamp to a VB.net program. I have been aquiring functions to do RS232 communication.

    I want the stamp to read some sensors, when the stamp gets the signal, lets say a high(5) I want to send that sensor name in a (string or integer#) to the VB.net program and then do some User interface junk.

    the sample VB program that comes with the APPmod does not work with VB.net cause they got rid of MScomm. I have found a rs232 class that someone wrote. I just have to figure out on how to use the methods. It works to check the com ports correctly, however I need to run it again and see if the 'A' will print to the text window now.
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-11-18 09:03
    There are several ways to print.

    The easiest way is using the Format class.

    http://groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/util/text/

    I have attached a test program that shows how you send text and values in

    readable form (eg.·a binary number 12 is send as '1','2')

    you need my adapted Uart class:

    http://groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/core/

    First rename your current Uart.java to Uart.org, then copy my Uart.java to the javelin core folder

    (default c:\program files\parallax inc\javelin stamp ide\lib\stamp\core)

    regards peter
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-11-18 09:19
    Here is a free VB.NET serial communication package with example form.

    http://www.codeworks.it/net/VBNetRs232.htm

    regards peter
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-11-18 11:16
    To answer your question regarding Jide_Terminal.

    The javelin program port operates at 28800 baud, 8 databits, no parity, 1 stopbit, no handshake.
    To send data out of the javelin SOUT pin, you use System.out.print() or System.out.println(),
    or you can use my Format class using Format.printf().
    To receive data from the javelin SIN pin, you use Terminal.byteAvailable() and Terminal.getChar(),
    my adapted Terminal class also has a method getString().

    To use the program port to communicate with other devices, those other devices need to know
    about and must implement the javelin protocol. Anything these devices send to the javelin SIN pin,
    is automatically echoed back to those devices. That is how the port hardware works and this echo
    cannot be turned of.

    Data·messages sent from the Javelin conform to the following pattern:
    (each message corresponds to a single CPU.message call)

    0x05 0x03 <messagedata> 0x7E

    <messagedata> is the sequence of bytes being sent by the CPU.message() native method. It is byte-stuffed. This means that if <messagedata> contains a byte <b> that has the value 0x7F or 0x7E then that byte is replaced with 0x7F <b>^0x20. i.e. 0x7F followed by the orginal byte xored with 0x20.

    Terminal characters are sent to the Javelin using the following algorithm:
    1. When it is ready to receive a byte (the Terminal.getByte() native method is called) the Javelin transmits 0x11 out Sout.
    2. If the terminal has no data to send to the Javelin it replies with 0x13.
    3. If the terminal has a byte <b> to send, then it replies with 0x12 <b>.

    After the Javelin is reset it send 0x0F followed a pause followed by 0x50 (the version of the Javelin firmware).

    Running the following simple program:

    public class HelloWorld { public static void main() { System.out.println("Hello World"); } }

    will generate the following on Sout:

    0F 50 05 03 48 65 6C 6C 6F 20 57 6F 72 6C 64 7E 05 03 0D 0A 7E 05 05 7E

    Note that the sequence 0x05 0x05 0x7E indicates that the Java program has ended.


    For existing devices the program port is unusable because of the used protocol.
    For the pc I have written several programs that allow you the catch the javelin output data
    so you can view it and log it to a file. Also these programs allow you to send a file to the
    javelin. Because of the javelin protocol, it is best suited to send text files only, but binary
    files are possible.

    Here are my Jide Terminal programs:
    only·view and log output (command line version only)
    http://groups.yahoo.com/group/JavelinCode/files/JideDebug/
    view and log output and send lines and files (command line and windows version)
    http://groups.yahoo.com/group/JavelinCode/files/JideTerm/

    Regarding receiving data from the SIN pin:
    Make sure you use Terminal.byteAvailable() to test for any data. Terminal.getChar() will wait
    forever until data is received. To operate in slave mode (javelin responds to user input) use

    static void main() {
    · //place initialization code here
    · while (true) { //mainloop
    ··· if (Terminal.byteAvailable()) {
    ····· c = Terminal.getChar();
    ····· //assemble received chars into an array
    ····· //or use·Terminal.getString() but this does not return until·CR,LF is received or a number of chars
    ··· }
    ··· //other mainloop code here
    · }
    }

    The reason to use Terminal.byteAvailable() is that you can disconnect the cable from the
    program port, but this is tricky. If the javelin appears to be stopped running after disconnecting the cable,
    it probably is waiting·for a byte at Terminal.getChar(). ·Then reconnect the cable and send an empty
    string (or a 'no data available' reply) from the terminal program, then disconnect again. The moment of disconnecting determines wether Terminal.byteAvailable() returns true or false. I have found that it
    usually takes 3 or 4 attempts before success. But then the javelin runs with the cable disconnected.
    To gain access to the javelin again, simply connect the cable and send a command (which of course
    you need to program in your javelin code). If you use a Uart you don't have these little problems.

    regards peter

    Post Edited (Peter Verkaik) : 11/18/2005 12:37:46 PM GMT
  • Sabre3487Sabre3487 Posts: 16
    edited 2005-11-18 20:46
    Thanks a bunch. The VB.net file was awesome. I had something similiar but that is straight forward.

    I don't think that I need the Jide files, because I am using a seperate cable for my serial connection and not using the Jide port.
    That is just if you only had the program port and wanted to capture and send data via that port correct??

    Thanks..
    Scott
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-11-18 20:54
    You only need the Jide files if you want to use the program port
    for other purposes than programming.

    In your opinion, as you have researched several rs232 packages, is the
    vb.net package I mentioned a good one, or have you found a better one ?

    regards peter
  • Sabre3487Sabre3487 Posts: 16
    edited 2005-11-18 21:36
    I have found another VB.net package that might cover more a bit more in depth rs232, but I just need simple back and forth communication with some error handling and that file you sent was perfect.·

    It is easy to use and works great going back and forth with Javelin stamp uarttest.java file you sent.· I have been modifying the uarttest file to see about sending other data type information, and have been reading your uart class to see about the parameters.·

    I would definately recommend that VB.net program to anyone, it is easy to use and works great.·· Easy to incorporate into my VB.net project.

    Thanks Again!

    Scott


    I attached the other VB.net Rs232 file.· Someone just needs to add it to thier project.· Then just declare a new rs232 object.· And use the methods desired.·
    vb
    31K
  • yvesByvesB Posts: 22
    edited 2007-01-05 19:18
    Hi Peter, did you release source code for your Windows version of JideTerm?· If not, could you?· I have a need for using the programming port to communicate with a PPC using .NET CF and would appreciate not having to redo idea.gif· what you already accomplished cool.gif with the .NET side.

    Thanks in advance.
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-01-05 19:54
    I did not release any source because I don't have
    the·exact source anymore for the binary that I released.
    I attached the source as it is now. I am not sure
    if this will run. I believe I added a 'LCD' text area
    below the normal display window. The idea was
    to easily test LCD output via the JIDE port.

    The source is for visual c#.
    Good luck.

    regards peter
  • yvesByvesB Posts: 22
    edited 2007-01-05 20:17
    I appreciate this Peter. It'll get me off to a good start with the protocol anyway. Thanks again.
Sign In or Register to comment.