Javelin Stamp and rs232 buffering
steve_b
Posts: 1,563
Hey guys,
I've gotten the hold of a Javelin start kit but must admit I'm somewhat intimidated.· But have found reason to git my Smile in to the Java arena!
At work we have some equipment that passes data between two modules.· We have some fault monitoring in the system and however the company programmed their latest Eproms, whenever we generate a fault, the rs232 data packet goes from 15bytes to 17bytes (basically it sends the first 2 bytes twice (start of string/start of text I think...framing bytes anyhow).
So, the boss asked me about using a stamp to 'filter/buffer' this stream.
The speed is 19.2k and I realize this is getting in to the 'questionable' range for the stamps...but if you can keep your data handling to a minimum it may work.
Anyhow, there's no consistancy with when the messages arrive.· So, the problem we had with the basic stamp is that as it's filtering it's data and sending it back out, a new packet could've been sent to the input pin and we would've missed it.·
Wow, I thought I would've been able to explain it quicker than that! haha
Anyhow, I thought I had read about the Javelin having 4 'virtual' uarts?!· and that they could run in the 'background'.· If this is true then maybe I've found another Parallax product to get my boss in to!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·
Steve
http://members.rogers.com/steve.brady
"Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
I've gotten the hold of a Javelin start kit but must admit I'm somewhat intimidated.· But have found reason to git my Smile in to the Java arena!
At work we have some equipment that passes data between two modules.· We have some fault monitoring in the system and however the company programmed their latest Eproms, whenever we generate a fault, the rs232 data packet goes from 15bytes to 17bytes (basically it sends the first 2 bytes twice (start of string/start of text I think...framing bytes anyhow).
So, the boss asked me about using a stamp to 'filter/buffer' this stream.
The speed is 19.2k and I realize this is getting in to the 'questionable' range for the stamps...but if you can keep your data handling to a minimum it may work.
Anyhow, there's no consistancy with when the messages arrive.· So, the problem we had with the basic stamp is that as it's filtering it's data and sending it back out, a new packet could've been sent to the input pin and we would've missed it.·
Wow, I thought I would've been able to explain it quicker than that! haha
Anyhow, I thought I had read about the Javelin having 4 'virtual' uarts?!· and that they could run in the 'background'.· If this is true then maybe I've found another Parallax product to get my boss in to!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·
Steve
http://members.rogers.com/steve.brady
"Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
Comments
Our data stream isn't consistant.
I was under the impression that the Javelin could multitask (for lack of a better term).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·
Steve
http://members.rogers.com/steve.brady
"Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
The stamp doesn't have one....but if the Javeline will hold it in a buffer while I finish resending a previous thread...then it might work!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·
Steve
http://members.rogers.com/steve.brady
"Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
This gives you a UART that is active all the time, thank goodness.· You have separate TX and RX uarts.· Implement two, and you can have bidirectional.
So, while the Javelin doesn't do 'true' multi-tasking, it DOES implement 'virtual peripherals' which get you around the limitations of the BS2 platform. In other words, you have interrupt-driven functionality underneath your Java code.
Note also the Programming DB-9 has debug information on it all the time, so you can't use that as a general purpose UART port.· The 'other' DB-9 on the lab board IS a general purpose port, though.
Post Edited (allanlane5) : 1/26/2005 8:57:07 PM GMT
I've been playing with the Javelin today...going through some of the projects in the kits' book.· But, I'm having one heck of a time understanding the structure of the programming!
Classes/libraries/modules....Objects.... ·· it's enough to make a man nuts! haha
I'm not understanding how things are named or reference.· I want to use rxUart and a txUart....
All I'm trying to do at the moment is receiver a couple of different ascii strings.· "AA 00" and "AA 00 AA 00" (we have an issue with some equipment sending it's start string twice when in fault mode--which creates other faults).
I've used a bs2 and a pushbutton to send the string....and I've checked that the data is coming out of the stamp.· But I don't even know how to talk to the rxUarts buffer.· Here's a click of my code so far (I've hacked it out from the hypertermCom code).
import stamp.core.*;
public class ACUtest {························ // COM Port (9-pin serial)
· final static int SERIAL_TX_PIN = CPU.pin0;······· //···· 2
· final static int SERIAL_RX_PIN = CPU.pin3;······· //···· 3
· static Uart txUart = new Uart( Uart.dirTransmit, SERIAL_TX_PIN, Uart.dontInvert,
························· Uart.speed9600, Uart.stop1 );
· static Uart rxUart = new Uart( Uart.dirReceive, SERIAL_RX_PIN, Uart.dontInvert,
························· Uart.speed9600, Uart.stop1 );
· static StringBuffer buffer = new StringBuffer(128);
· static char c;
· static void bufferMessage(){
··· c = 0xff;
····· if(rxUart.byteAvailable()){
······· c = (char)rxUart.receiveByte();
······· buffer.append(c);
** Now, if the Uarts are running in the background...then anything coming in goes to the buffer.· And I know to use the 'byteAvailable' module to see if anythings in there....but I don't know how to get the data from the buffer.
I had difficultly with C/C++ back in the day....and am now having flashbacks! haha· But I'm not finding this too easy so far.· Basic is just that....basic and easy (relative)....ah well, I won't moan about it...just need to learn it I guess!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·
Steve
http://members.rogers.com/steve.brady
"Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
The method receiveByte() reads the byte from the buffer
and automatically removes it from the buffer.
regards peter
printl is like a local debug...where the sendbyte will let me use the uarts?
so something like txUart.sendbyte(what?)· does the c go in the brackets?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·
Steve
http://members.rogers.com/steve.brady
"Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
I suggest you read those first so you know what methods are available
and how to use them.
Besides sendByte (sends a single character) there is also sendString.
regards peter
With some effort I've managed some basics.· I'll say that the lacking thing in the help files are examples...at least compared to Pbasics help files.
I've certainly got to learn the programming structure better to understand how to use a given method/module/class/library/etc...
Anyhow, I'm bring in a 59Byte string in to an array (it's "AA 00 AA 00 40 00 FF 74 FF F2 00 00 00 00 00 00 00 00 04 4E").· Now, I have to look and see if the first 2 pairs of bytes are repeated (like in this case) then I have to peal those out and send the rest of the string.
Because this is all 'on the fly' I won't be able to use an array in the end....but will have to do a running look at the buffer.· I'm able to get the program to run somewhat properly first time through (provide that the first set of AA's is first in the buffer--babysteps!) but am running in to problems on the 2nd run.
I'm trying to use the DEBUG option and am struggling understanding exactly what's going on (or wrong!).
I'm able to get the bytes out of the receive buffer.· Are they erased as soon as I 'get' them...and if not, how do I clear the buffer?
Now, how do I go back and test to see if the buffer has something in it?·
There's this:
static void bufferMessage(){
··· c = 0xff;
····· if(rxUart.byteAvailable()){
······· c = (char)rxUart.receiveByte();
······· buffer.append(c);
···· }
· }
But I'm not sure what happens.· the IF statement seems to be missing stuff....like IF (X=1) or something.· It says the byteAvailable function will return a true or false....but we don't even ask if 'rxUart.byteAvailable() == true'· Is this just a shortcut for the same thing?· Like the x++?
Anyhow, I've included the program for the full context!
All help is appreciated!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·
Steve
http://members.rogers.com/steve.brady
"Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
I went through the code and have created an alternative. I have made some assumptions, so correct me if I am wrong.
main2() is the new method.
Joe