BS2 and VB2005
Nate Smith
Posts: 1
I am trying to develop an application in Visual Basic 2005 Beta 2 which communicates with a Basic Stamp processor.· The bulk of this communication consists of a 1 byte command character, then 12 bytes of data.· I am having issues with the Stamp receiving all of the data from the VB program.· I have verified that the Vb app is indeed sending all the data that the stamp is looking for(through a virtual serial port emulator), and have been able to send the data successfully through the debug window.· I am currently running communications via SERIN/SEROUT at 2400/8/N/1/Inverted (16780).· The VB and Stamp code are below:
----START VB2005 CODE---
Using com As IO.Ports.SerialPort = My.Computer.Ports.OpenSerialPort(sCommPort)
ConfigurePort(com) 'Set port settings to 2400 8/N/1
com.NewLine = Chr(13)
com.Write("S")
For Each c As Char In value
com.Write(c)
Next
'now, send the alarm
com.DiscardInBuffer()
com.Write("N")
For X As Integer = 1 To 10000 : Next X
value = Format(AlarmTime, "HH mm ss MM dd yyyy")
For Each c As Char In value
com.Write(c)
Next
End Using
START BS2 COMM CODE
mainLoop:
· TOGGLE hbeat
· SERIN 16,pcComm,500,checkAlarm,[noparse][[/noparse]STR cmd\1]
· SELECT cmd
··· CASE "S"
····· 'set time
····· GOSUB readTimeFromPC
····· GOSUB setCurrentTime
··· CASE ELSE
····· GOTO checkAlarm
· ENDSELECT
GOTO mainLoop
readTimeFromPC:
····· SERIN 16,pcComm,[noparse][[/noparse]DEC hh]
····· TOGGLE hbeat
····· SERIN 16,pcComm,[noparse][[/noparse]DEC mm]
····· 'DEBUGIN DEC2 mm
····· TOGGLE hbeat
····· SERIN 16,pcComm,[noparse][[/noparse]DEC ss]
····· 'DEBUGIN DEC2 ss
····· TOGGLE hbeat
····· SERIN 16,pcComm,[noparse][[/noparse]DEC mo]
····· 'DEBUGIN DEC2 mo
····· TOGGLE hbeat
····· SERIN 16,pcComm,[noparse][[/noparse]DEC dd]
····· 'DEBUGIN DEC2 dd
····· TOGGLE hbeat
····· SERIN 16,pcComm,[noparse][[/noparse]DEC yr.HIGHBYTE, DEC yr.LOWBYTE]
····· 'DEBUGIN DEC2 yr.HIGHBYTE, DEC2 yr.LOWBYTE
····· TOGGLE hbeat
····· SEROUT 16,pcComm,[noparse][[/noparse]"OK",CR]
RETURN
----START VB2005 CODE---
Using com As IO.Ports.SerialPort = My.Computer.Ports.OpenSerialPort(sCommPort)
ConfigurePort(com) 'Set port settings to 2400 8/N/1
com.NewLine = Chr(13)
com.Write("S")
For Each c As Char In value
com.Write(c)
Next
'now, send the alarm
com.DiscardInBuffer()
com.Write("N")
For X As Integer = 1 To 10000 : Next X
value = Format(AlarmTime, "HH mm ss MM dd yyyy")
For Each c As Char In value
com.Write(c)
Next
End Using
START BS2 COMM CODE
mainLoop:
· TOGGLE hbeat
· SERIN 16,pcComm,500,checkAlarm,[noparse][[/noparse]STR cmd\1]
· SELECT cmd
··· CASE "S"
····· 'set time
····· GOSUB readTimeFromPC
····· GOSUB setCurrentTime
··· CASE ELSE
····· GOTO checkAlarm
· ENDSELECT
GOTO mainLoop
readTimeFromPC:
····· SERIN 16,pcComm,[noparse][[/noparse]DEC hh]
····· TOGGLE hbeat
····· SERIN 16,pcComm,[noparse][[/noparse]DEC mm]
····· 'DEBUGIN DEC2 mm
····· TOGGLE hbeat
····· SERIN 16,pcComm,[noparse][[/noparse]DEC ss]
····· 'DEBUGIN DEC2 ss
····· TOGGLE hbeat
····· SERIN 16,pcComm,[noparse][[/noparse]DEC mo]
····· 'DEBUGIN DEC2 mo
····· TOGGLE hbeat
····· SERIN 16,pcComm,[noparse][[/noparse]DEC dd]
····· 'DEBUGIN DEC2 dd
····· TOGGLE hbeat
····· SERIN 16,pcComm,[noparse][[/noparse]DEC yr.HIGHBYTE, DEC yr.LOWBYTE]
····· 'DEBUGIN DEC2 yr.HIGHBYTE, DEC2 yr.LOWBYTE
····· TOGGLE hbeat
····· SEROUT 16,pcComm,[noparse][[/noparse]"OK",CR]
RETURN
Comments
It looks like you are sending "value" byte by byte as fast as Basic can go. Yet in the BS2, you're making all these decisions, and toggling that heartbeat signal.
You should read the full time as a single SERIN.
SERIN 16, pcComm, [noparse][[/noparse]DEC hh, DEC mm, DEC ss, DEC mo, DEC dd, DEC yr]
This is MUCH more likely to recieve the string completely and accurately.
And why did you break up your 'yr.HIGHBYTE' etc.? You are sending a 4-digit value. You might want to send a CR (/n, CHR(13)) as the last thing, to tell the BS2 'DEC' modifier that you are done with the year.