programming help
Dirty Howi
Posts: 20
I am trying to send a message to my basic stamp using COM6 (its the port that's id'd by the software). I am sending a string of 4 characters, based on that i want a simple select to turn on one of three lights (to wit)
i can see the lights blink on the basic stamp proto module, so i know i'm sending something, unfortunately i cant run both at the same time (the BS2 debugger and my code)
and to open a com port
any help for the dumb puter programmer would be appreciated
serStr VAR Byte(10) serStr(9)=0 SERIN 1, 16468, [STR serStr\9] SELECT serStr CASE "ormd" HIGH 15 PAUSE 2000 LOW 15 ENDSELECT
i can see the lights blink on the basic stamp proto module, so i know i'm sending something, unfortunately i cant run both at the same time (the BS2 debugger and my code)
private void btnORMD_Click(object sender, EventArgs e) { var c = new communications(); c.SendMessage("ormd"); }
and to open a com port
public class communications { private SerialPort sp = new SerialPort(); public communications() { sp.PortName = "com6"; sp.BaudRate = 9600; sp.Parity = Parity.None; sp.DataBits = 8; sp.StopBits = StopBits.One; sp.Handshake = Handshake.None; } public void SendMessage(string message) { sp.Open(); sp.WriteLine(message); } } }
any help for the dumb puter programmer would be appreciated
Comments
Anyway to send the command via the debugger (i'm still reading the books)
anyone have a example of talking to a basic stamp via .NET (VB or C# dont matter to me, i read/write both and can translate between them)
receives an array of nine bytes. If the array is less than nine or if the length of the array is going to vary then you would need to transmit an end of line character or your Stamp program is just going to hang there.
For example attaching a carriage return as the end of line would be handled as follows by the Stamp
this would inform the Stamp that a complete string had been received and we can move on.
Secondly serStr is an array of byte variables and the values or string that it contains must be extracted one byte at a time using the index of the element eg: serStr(0) ,serStr(1)......... so Select Case will not work on the string as a whole only the individual elements.
As proof of concept try your program with just a one byte variable to begin with.
The following link is a 2007 post that has a few useful references in it although I now know there is plenty of room for improvement.
http://forums.parallax.com/showthread.php/96973-VB-Express-to-Stamp-Template
Jeff T.
thanks
Your project is the kind I get into and the kind I have struggled with in the past.
What you are attempting is well within the capabilities of the Stamp and you have probably witnessed already the willingness to help by the members of this forum.
So just keep posting your questions and you are guaranteed a helpful response.
Jeff T.
edit: never mind the int, the serial port class writeline method will only accept a string
1) write a binary array of one or more values
2) write a string of characters as ASCII character codes with a NewLine character appended. The default newline character has a value of decimal 10 but can be modified with the serial port method.
3) write a string of characters as ASCII character codes without the NewLine appended.
When VB transmits ASCII characters, for example "1" is transmitted as the character code value of 49, then the Stamp must be set up to format the incoming data from a binary value to a string.
1) this accepts a transmitted value of "1" and stores 49 into the variable myvar.
2) this accepts a transmitted value of "1" and stores 1 into the variable myvar.
Formatters such as DEC and HEX take ASCII string character codes and convert them into their respective values at the Stamp.
Jeff T.
what is in the button (i even moved over to VB since that's what your using)
program in the stamp itself
very simple wait for ANYTHING to come across, and light up the light...still no joy
and its snowing in iowa, and i have nothing else to do today cept play with this so...
when dealing with something new it pays to RTFM
SERIN 16, 84 [DEC strStr] works...it helps if you set the rpin portion of the command to the right dad gum pin LOL.