serial in a word serout a word
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!
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
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.··
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 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.
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.
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
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>
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
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!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
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.
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
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.
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
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
· 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