MSCOMM32.ocx
GeorgeL
Posts: 131
Hey, anyone here use the MSCOMM in their program's like me. I cant seem to get data correctly from the BS2 anymore. In fact, I dont really understand as to how its supposed to work. If someone could give a tutorial similar to the http://www.theabramgroup.com/basicstamp/·tutorial, on sending data then ill just move my projects to VB2008 or similar, since I have that at home.
Comments
There is also an interesting thread dealing with Real Basic at this link http://forums.parallax.com/showthread.php?p=766819·though Real Basic is not free.
If you get the template up and running for the VB Express version (which is really quite simple) and you have a more specific problem you want to deal with then post your questions and we will see if they can be answered.
Jeff T.
There is also an example towards the end of the thread called Com Template.zip that expands on the above by providing a GUI to control a device in 4 different directions, the Stamp code is also provided in that same post.
Jeff T.
I still cant get the VB2008 to work with the tutorial.
How bout I make a more specific request, since I know my way around VB I just need 2 specific conversions.
So, what is the VB08 equivalent of:
MSComm1.Output = Chr(255) & Chr(1)
and
how would I recieve this line into VB08 from the BS2:
SEROUT 16,16780,[noparse][[/noparse]1]
SERIN rx,baud,[noparse][[/noparse]DEC3 my_variable] will take the three character codes and place them into one byte as 255
A more economical way to do the same is to place the value 255 into one byte variable before it is transmitted, this will cut the transmission time down by ~66%
Possibly using this method
Dim my_array As Byte()=New Byte(2) {0,0,0}· 'declare an array of bytes
my_array(0) = 255·········· 'assign the first two
my_array(1) = 1············· 'elements with your values
SerialPort1.Write(my_array, 0, 2)· 'write element 0 and 1
SerialPort1.Read(my_array, 2, 1)· 'read value from Stamp into element 2
Jeff T.
For the VB2008 code I set up a form with 1 button and the SerialPort1, NOTE the only property i changed in the serial port is to set it for 2400Baud. COM1 is correct, idk about the rest (the rest is default)
So heres the code in VB:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim my_array As Byte() = New Byte(2) {0, 0, 0} 'declare an array of bytes
my_array(0) = 255 'assign the first two
my_array(1) = 1 'elements with your values
SerialPort1.Open()
SerialPort1.Write(my_array, 0, 2) 'write element 0 and 1
SerialPort1.Read(my_array, 2, 1) 'read value from Stamp into element 2
SerialPort1.Close()
End Sub
End Class
Then in the Stamp, I wrote this:
' {$STAMP BS2}
' {$PBASIC 2.5}
dir VAR Word
pulseCount VAR Byte
SERIN 16,16780,[noparse][[/noparse]DEC3 dir]
IF (dir=1) THEN
FOR pulseCount = 0 TO 50
PULSOUT 13,650
PULSOUT 12,850
NEXT
ENDIF
So....WHAT DID I DO WRONG!!!!!!!!!!!!! (cry)
In your Button_Click event write it like this
Dim sData As Byte················ 'create a variable to transmit for this button
SerialPort1.ReadExisting()····· ·'clear the serial buffer before we transmit
sData=1····························· 'assign a value to our variable
SerialPort1.WriteLine(sData)··· 'send the data
At the Stamp try this
' {$STAMP BS2}
' {$PBASIC 2.5}
dir VAR Byte········ 'make dir a bye value
pulseCount VAR Byte
SERIN 16,16780,[noparse][[/noparse]DEC3 dir]··· 'this instruction will take as much as a·3 digit value terminating when it sees a CR or LF
IF (dir=1) THEN
FOR pulseCount = 0 TO 50
PULSOUT 13,650
PULSOUT 12,850
NEXT
ENDIF
see if that works for you and let me know
Jeff T.
http://www.theabramgroup.com/basicstamp/
This is my VB code (I just added a text box)
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SerialPort1.Open()
Dim sData As Byte 'create a variable to transmit for this button
SerialPort1.ReadExisting() 'clear the serial buffer before we transmit
sData = 1 'assign a value to our variable
SerialPort1.WriteLine(sData) 'send the data
TextBox1.Text = SerialPort1.ReadExisting()
SerialPort1.Close()
End Sub
End Class
and then my BS2 code:
' {$STAMP BS2}
' {$PBASIC 2.5}
dir VAR Byte 'make dir a bye value
pulseCount VAR Byte
DO
SERIN 16,16780,[noparse][[/noparse]DEC3 dir] 'this instruction will take as much as a 3 digit value terminating when it sees a CR or LF
IF (dir=1) THEN
FOR pulseCount = 0 TO 50
PULSOUT 13,650
PULSOUT 12,850
NEXT
SEROUT 16,16780,[noparse][[/noparse]"h"]
ENDIF
LOOP
If you are sending and receiving you can use the Data_Received event of the serial port, we can also use this event as a way to synchronize our transmissions. The Data_Received event will detect any data that the Stamp sends, when it does then we know exactly what point we are at in the Stamps program.
There is a drawback in using the Data_Received event in the fact that it runs in a seperate thread, this gives you the problem that if you should try and pass certain information from this thread to another it will throw an exception, such as to a TextBox in another thread. You would normally overcome the problem using delegates but as that adds a little mor complexity I am not going into it right now. There is an instruction that allows you to ignore the cross thread calls and does no harm in simple examples.
I am attaching a text file with an example of what you want to help you get started. Its not perfect but you should be able to work it to how you need
Jeff T.
George, please do not post BUMP messages. If you have nothing additional to offer and have no replies then nobody has anything to post. Posting the word bump is considered off topic on these forums.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering