Serin
Marcelo Paris
Posts: 3
as a receipt containing ASCII data, text and numbers?
<02>hello123
<02>hello123
Comments
SERIN
Function
Receive asynchronous serial data (e.g., RS-232 data).
ASCII data = any standard ASCII characters
Cheers Vaclav
the data receive is one caracter ascii + two caracter no numeric + two number + one ascii caracter, I need to assign a variable to each of the data received,
Thanks for your help.
Here is some code for you to get you started.
It basically uses the formatter STR to parse required number of characters into variables.
·
Read the "fine print" of SERIN formatting and it will make sense to you.
Of·course this code does not do much, just reads number of characters.
Any more questions - just ask.
·
Cheers Vaclav
·
PS You need to change the processor and adjust the baud rate to whatever processor you are using.
This is what is sent in VB6.0 to the basic stamp but I can not capture.
Private Sub Command1_Click()
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
dato = Chr(2) + Mid(Text1.Text, 1, 2) + Mid(Text1.Text, 1, 2) + Chr(3) + Chr(13)
MSComm1.Output = dato
MSComm1.PortOpen = False
End If
End Sub
Simplify your VB "data" - just send STX (start text chr 2 ) + single·number 1 (chr 49) .
Than change SERIN to wait for STX and then receive single ASCII digit 1.
Comment out the rest of SERIN for now
Add timeout to SERIN if necessary (I did not) to aid in troubleshooting this.
Put your VB code into loop so it sends the data continually after the button is pressed.
But make sure your VB and Stamp data formats match (baud rates, parity, number of bits...) !!!!
Main:
DO
· SERIN 16,16468 ,[noparse][[/noparse]WAIT (2), STR ASCIIData_1 \1]· ' wait for STX then receive another character
· 'SERIN 16,16468 ,[noparse][[/noparse]STR ASCIIData_2 \2]
· 'SERIN 16,16468 ,[noparse][[/noparse]STR ASCIIData_3 \2]
· 'SERIN 16,16468 ,[noparse][[/noparse]STR ASCIIData_4 \1]
· DEBUG CR
· FOR Index = 0 TO 5
··· DEBUG ?· ASCIIData_1(Index)
· NEXT
LOOP
· END
PS Both of your Text1 in data·are same.
·
are you making progress?
I need to add this to make sure it is covered.
1. In your VB program I do not·see where you select your COM port
2. In your VB program you should ( it is good programming practice ) verify that you are connected to your COM port.
3. I have been using Port 16 im my SERIN sample code. The COM port attached is therefore in use by the Stamp Development program. In my case COM1. As far as I know you cannot release this port and·the Operating system will not let you use same port to communicate with VB.
You need to use different I/O pin ( with some harware modification ) and different COM port for you ASCII data input.
Here are some modifications to your VB code.
Private Sub Command1_Click()
Dim Text1
Text1 = "12345"
Dim CommPort
MSComm1.CommPort = 1 ' select COM
CommPort = MSComm1.CommPort ' to make sure - not necessary
If MSComm1.PortOpen = False Then
··· MSComm1.PortOpen = True······ ' open COM port
··· If (MSComm1.PortOpen) Then··· ' verify if port open
·······
······· dato = Chr(2) + Mid(Text1.Text, 1, 2) + Mid(Text1.Text, 1, 2) + Chr(3) + Chr(13)
······· MSComm1.Output = dato
······· MSComm1.PortOpen = False
··· Else
······· ' process error - port in use?
··· End If
···
End If
End Sub