Shop OBEX P1 Docs P2 Docs Learn Events
serial in a word serout a word — Parallax Forums

serial in a word serout a word

CastrovinciCastrovinci Posts: 26
edited 2009-08-10 03:06 in General Discussion
can someone help me serial in a word

I want to send via Visual Basic (serial port)·a word Lets say "hello" and then I want the sxchip to read hello and serial out hello.· I can only seems to serial in 1 char and not a full word.

Here is an example of my idea

SERIN ra.3, n9600, tmpB1,

' ' ' ' tmpb1 should now contain "hello"

then serial out tmpB1

I figured out how to serial out a word, just can't nail down the serin!

Thanks!

Comments

  • natpienatpie Posts: 35
    edited 2009-07-30 23:54
    SX/B serial commands only suport a single character.·· And it does not suport strings.·· So tmpB1 can never contain "hello".··· You can however use arays.··

    FOR myvaribale = 0 to 4

    serin .... ..... tempB1

    mystring(myvarible) = tempB1

    Next



    is a general outline of how you could accomplish this.· If you are planning lots of serial input and output I would recomend using an virtual UART in the interupt.·· There are multiple examples of this in the best of SX stick thread.··
  • CastrovinciCastrovinci Posts: 26
    edited 2009-07-31 01:13
    still having trouble with that. I have this and i am geting invalid number of parameters
    What am I suppose to declare with this
    tmpB1 VAR word ' subroutine work vars
    tmpB2 VAR Byte
    tmpB3 VAR Byte
    tmpB4 VAR Byte
    'tagBuf VAR Byte(10)
    tmpW1 VAR Word
    anthony var byte
    myvarible var byte

    FOR myvarible = 0 to 4
    serin ra.3, n9600, tmpB1
    anthony(myvarible) = tmpB1
    Next

    tx_str anthony

    I shortened this, but what am I missing?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • JonnyMacJonnyMac Posts: 9,213
    edited 2009-07-31 03:27
    I've attached demo that does what you want -- tested with HyperTerminal on a PDB.
  • natpienatpie Posts: 35
    edited 2009-07-31 03:58
    Castrovinci said...
    still having trouble with that. I have this and i am geting invalid number of parameters
    What am I suppose to declare with this
    tmpB1 VAR word ' subroutine work vars
    tmpB2 VAR Byte
    tmpB3 VAR Byte
    tmpB4 VAR Byte
    'tagBuf VAR Byte(10)
    tmpW1 VAR Word
    anthony var byte
    myvarible var byte

    FOR myvarible = 0 to 4
    serin ra.3, n9600, tmpB1
    anthony(myvarible) = tmpB1
    Next

    tx_str anthony

    I shortened this, but what am I missing?

    You declared tmpB1 as a word.·· That is two bytes.·· Change tmpB1 to a byte and that error should go away.··
    You also atempted to cram a word into a byte on the anthony(myvariable)=tmpB1.···
    You didn't declare anthony as an aray.

    The for loop isn't the most eligant answer to this I just offered that as an example of how to populate a sudo string.
    Honestly i realy don't like the serin and serout commands.·· If you program is sitting around waiting for serial input they are okay, but if you want your micro controler to do something else like check a sensor it can miss a serial command.· You also can't recive a byte while you are transmiting a byte.
    Of course I also cant ressist an interupt in my code and that rules them out.·

    One of the examples posted in the best of sx forms has an interupt driven virtual UART with a 16 byte buffer( i think its 16).·· It is writen in such a way as you can plug it into your program without realy knowing·why it works.·· IT has the nessary subs and funcs to get items out of the buffer and push them into the transmit buffer.·· Using this solution you only have to check when it is convenent if it has rescived any bytes, if not you can get back to what you were doing, if you did you can stop and see what you want to do with it.
    Please remember this is only my two cents.·· Some may completly disagree with my opinion, you may be one of them.· Play with the differnt options.·· If a solution works for you it may be the correct way to go.·· There are many solutions, and as it apears you are trying to master serin and serout this may not be the time for you to experiement with Interupt based serial comunication.·· I just wanted to point out the other way and its advantages.
  • CastrovinciCastrovinci Posts: 26
    edited 2009-07-31 15:59
    John, Thank you so much for your responses. John, I was trying your program and I am still getting major error's. You said this was working for you? I get several errors with this. Can you repost or is it something I am doing wrong

    Natpie,

    Thanks for your response as well, its ok to do things differently and I agree not everyone will always agree with you or anyone, but it gets the other person thinking. I would like to learn more about the array's as I lack in that area and its not like VB where you can find tons of examples on this stuff. I wish the sx help section was a little more expressing, but how do you declare array's not matter what way I try I get parameter errors

    test var byte i get an error
    test var byte (2) I get an error
    test var word I get an error
    test var word (4) I get an error

    so how do I make an array from start to finish?
    I have the latest software version.
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2009-07-31 16:13
    test var byte gives the error
    Invalid variable name.

    So that should hint you.

    Try
    test1 var byte
    test2 var byte(2)
    test3 var word

    You cannot use array of words.

    regards peter
  • JonnyMacJonnyMac Posts: 9,213
    edited 2009-07-31 16:21
    When was the last time anyone at Microsoft wrote you a custom VB example? <smirk>

    My program does in fact work and I'm a little disappointed that you can't make it work on your end. Why? Did you change the baud constant to suit your setup? I'm using an inverter on the PDB, I think you're going direct (which means you need N9600"). Are you using the latest version of the SX/B compiler? If not, you should download it from the sticky post at the top of this forum.

    Funny, you wish the help system provided more examples -- I frequently wish new people would ask better, more detailed questions about their projects so that those of us willing to write custom demo code are not left guessing. You have yet to express what you want to do with your SX program (vis-a-vis working with VB) and that knowledge could make a difference. I've written hundreds of SX/B programs and I use it in EFX-TEK products every day. All of our products have some sort of serial interface; this stuff is not difficult one the goal has been defined.

    Stop with the fragments -- spill the beans, <grin>
  • natpienatpie Posts: 35
    edited 2009-07-31 16:21
    test var byte i get an error
    test var byte (2) I get an error
    test var word I get an error
    test var word (4) I get an error

    so how do I make an array from start to finish?
    I have the latest software version.
    Your spaces are killing you.

    indexvar var byte
    myaray var byte(16)


    for indexvar = 0 to 15
    myaray(indexvar) = indexvar
    next
    This should load myaray(0) with 0, myaray(1) with 1 ........
    I haven't played with Version two but I don't think you can do word arays.·


    EDIT:
    I was wrong.·· Id did not realize you can put a space betwen byte and the aray size.·· We'll I've learned my new thing for the day so I guess my day is over.


    Post Edited (natpie) : 7/31/2009 4:31:38 PM GMT
  • JonnyMacJonnyMac Posts: 9,213
    edited 2009-07-31 16:22
    There are no [noparse][[/noparse]automated] word arrays in SX/B.
  • CastrovinciCastrovinci Posts: 26
    edited 2009-07-31 16:54
    John,
    I wasn't saying that to upset you. It seems so hard to please people in online forums. If you ask people to much they come back and tell you to do the work yourself. If you ask to little they said provide more details....... I was trying to be kind and sort of figure my issues out by taking some examples from the reply's and learn it. I can surely post more in depth and again I am trying to learn and by no means mean any disrespect. Now to the help section. If you type in things in the help you dont always get the best explainations or very vague explanations. Same as how the search section is setup here. Try a google search then try searching the forumns here and see the difference. Just a suggestion not critisism. I would like to send you a screen shot, but I dont see attach on the quick post. The error I get is on DELAY_MS 5 invalid parmiters. Then if I removed that line I get an error on TX_BUF @strBuf invalid number of parameters. I am using 3.3.0 software.

    This is what I am trying to do in a nutshell.

    Connect to the sxchip via serial port using VB
    I am then using Vb to grab from an odbc (mysql) database and send that info to the sxchip.
    The sxchip will then turn on or off a certain relay via the database information and send confirmation back to the vb program
    Eventually I want to experiment with frequency's and Digital to anolog converters, etc and have that serial back information to my vb program and update the database.

    John, thanks for taking the time to write what you wrote, let me know what I have to do to get it working (or what I am missing) and if you need more info let me know. thanks!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • JonnyMacJonnyMac Posts: 9,213
    edited 2009-07-31 18:07
    I have only ever replied "do the work yourself" to those that are blatantly lazy. Clearly, you are not. That you seem sincere is the only reason why I'll spend my time helping you -- it's fun to help those that want to learn and I know you do.

    First things first: the IDE does not install the latest beta SX/B compiler and you will need that for my examples. You can get it (and support documentation) from a sticky thread at the top of the SX forum. This will clear the errors you had when running my program. Keep in mind that SX/B is free and changing almost daily so Parallax doesn't release a new installer unless there's a big change. SX/B 2.0 is still in a tiny bit of flux as we all work to wring the most out of it.

    As for your project... I do this kind of stuff all the time. Most of our (EFX-TEK) accessories are simple command processors that are told what to do by a master controller. They can even report information back if instructed to do so.

    Have a look at what I've attached. It uses a very simple protocol to control relays and report their status. Once you get this working you can easily expand on it. Now, if part of your expansion ever includes things like PWM control of outputs you will have to update the program to use interrupts. When you get there I will happily show you how; today I'm working on a new EFX-TEK accessory program that uses interrupt-driven serial comms and can do things in the "background" while the foreground is handling other tasks.

    Start simple. Get this going, then expand on it to build your confidence. Once you have that licked then you can tackle bigger things.
  • CastrovinciCastrovinci Posts: 26
    edited 2009-08-03 22:40
    Ok gents, I am making progress, I download the newer software from the sticky post. It now reads 3.2.92h.· I hope thats the correct version.· Am I right to say that at this stage I can't use my usb key? I got rid of all the errors I was getting, I am now stuck on the one program johnny RX_String_Test.SXB. I get it to write in hyperterminal Please enter string (although it seems to get cut off and only print·"ter a string") when I type 3 letter and hit enter It either freezes up or returns nothing. Not even the "you entered: " part. My connection setting are as follows

    Com 1 N 9600.

    I get no writing when its set at T9600, so i changed it to n9600. I am connecting through serial cable no USB converter. I use the 22k resistors for protection and also use without and get the same issue.

    The external resinator I am using is 20 MHZ

    It appears that the maybe its looping without picking up the chars???

    Serin tx n9600 ,char,1000,main????? would this be a better angle?


    Also can someone better explain to me the serial section. for example when I send data in hyperterminal I am sending the whole string at once to the sx chip or is it one char at a time. How does it come into the stamp as an ascii char or the actuall letter. thanks!

    Post Edited (Castrovinci) : 8/3/2009 10:46:39 PM GMT
  • JonnyMacJonnyMac Posts: 9,213
    edited 2009-08-03 23:42
    The program is fine -- I just ran it again and will post a screen shot to prove it.

    1. Stop shotgunning ideas that you "hope" will work -- as the president would put it, this is "acting stupidly" (out of ignorance, anyway)

    2. Check your connections. Since serial ports can be all over the place direct connections are a bad idea (imho) but if you're going to do it you should have it like this:

    SX.RX <
    22K
    DB-9.3 (PC TX)
    SX.TX
    > DB-9.2 (PC RX)
    GND
    DB-9.5 (GND)

    Using this direct connection you must set your program Baud constant to "N9600".

    The latest version of the SX/B compiler is 2.00.30. You can find this in the SX-Key IDE About dialog by clicking on the version number until the SX/B version is displayed.
    951 x 653 - 167K
    326 x 331 - 169K
  • CastrovinciCastrovinci Posts: 26
    edited 2009-08-04 00:58
    1. raising questions or thought processes not shotgunning ideas.... Grin -

    2. Have all the settings/connections above you stated.

    3. I did the about box and can only find it says version 3.3.0. Even after going to Beans thread and downloading the latest compiler update, I noticed that his update looks like it was for another version then I have, so after I follow his directions It doesnt seems to work, which I think (no shotguns here - bang bang) I am not in the correct·download link or i need the version he lists? can you provide me a link where I need to go if you dont mind, and if I need a certain previous version. Thanks!

    Post Edited (Castrovinci) : 8/4/2009 1:03:47 AM GMT
  • PJMontyPJMonty Posts: 983
    edited 2009-08-04 01:35
    Castrovinci,

    You seem confused by the the version issue, so let me clarify for you:

    1 - The sticky thread at the top of the forum is for SX/B. The current version is 2.00.30.

    2 - You download the IDE from the Parallax site directly. There is no sticky for it here in this forum. This link is:

    www.parallax.com/tabid/460/Default.aspx

    The current version is 3.3.0.

    3 - You can check the version of the various components that make up the SX-Key software by clicking Help->About, and then clicking on the text that starts with "IDE Ver". Each click will show you the version number of one of the software pieces that make up the SX-Key software package.

    4 - In order for SX/B to be updated, you need to copy it into the "\Compilers\SXB" directory located in the directory that the SX-Key software was installed. If you have downloaded the latest SX/B and think you have installed in properly, check for the new version number as indicated in #3 above. If the new version number doesn't show up, you haven't installed SX/B into the correct directory.

    Thanks,
    PeterM
  • CastrovinciCastrovinci Posts: 26
    edited 2009-08-04 01:56
    Thanks I'm glad you explained that, I would have never known.· I now have the latest, but unfortunetly I am still having my serial issues.· I copy the program directly from johns post and run it, I still get issues.· I am sure it is on my end, but I dont know what else it could be, is there anything i need to modify in hyperterminal other then the standard baud rate and com port?· I dont know what else to do.· Its weird because like I stated earlier when I run the program it doesnt show the whole line in hyperterminal, I only get the last say 10 or so chars.· I guess its something to do with the com side.· Maybe I will try another laptop tommrow and see.· Thanks for all your help.
  • JonnyMacJonnyMac Posts: 9,213
    edited 2009-08-04 02:35
    Remember, I ran that program (twice now) on a PDB that has a level shifter circuit so I had to use T9600 -- with your direct connection you must use N9600. Check your HT settings to make sure that it's not expecting hardware flow control.
  • CastrovinciCastrovinci Posts: 26
    edited 2009-08-10 02:38
    OK OK OK· I finally got Rx string test to work.· it was the flow control and after your suggestion I read up on this and i definently did not want that on.· I needed another wire for that.· Anyway I am almost where I need to be, I came into another issue and im not sure about it.· I want to be able to read the WHOLE rx string and then if its equal to a certain string I want to go to another sub or do like shown below.· I just cant figure out how to combine the array into a full word or at least get the full string from rx and store it in a string.· Thanks!

    · TX_BYTE CR
    · TX_BYTE LF
    · TX_STR· "You entered: "
    · TX_BUF @strBuf
    · get strBuf(0),ron1,RON2,RON3,RON4,RON5···'·is this correct????
    ·'WHAT GOES HERE????
    ·If ron = "ANTHONY" then
    · TX_STR "Tx A SPECIAL STRING"
    · endif
    · DELAY_MS 5000
    · GOTO Main
  • JonnyMacJonnyMac Posts: 9,213
    edited 2009-08-10 03:06
    There is no built-in string handling in SX/B. You will be forced to receive the string and then compare it, byte-by-byte, with the possible strings that you want to process.
Sign In or Register to comment.