PDA

View Full Version : BS2 and VB2005



Nate Smith
08-04-2005, 04:05 AM
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,[STR cmd\1]
и SELECT cmd
иии CASE "S"
иииии 'set time
иииии GOSUB readTimeFromPC
иииии GOSUB setCurrentTime
иии CASE ELSE
иииии GOTO checkAlarm
и ENDSELECT
GOTO mainLoop

readTimeFromPC:
иииии SERIN 16,pcComm,[DEC hh]
иииии TOGGLE hbeat
иииии SERIN 16,pcComm,[DEC mm]
иииии 'DEBUGIN DEC2 mm
иииии TOGGLE hbeat
иииии SERIN 16,pcComm,[DEC ss]
иииии 'DEBUGIN DEC2 ss
иииии TOGGLE hbeat
иииии SERIN 16,pcComm,[DEC mo]
иииии 'DEBUGIN DEC2 mo
иииии TOGGLE hbeat
иииии SERIN 16,pcComm,[DEC dd]
иииии 'DEBUGIN DEC2 dd
иииии TOGGLE hbeat
иииии SERIN 16,pcComm,[DEC yr.HIGHBYTE, DEC yr.LOWBYTE]
иииии 'DEBUGIN DEC2 yr.HIGHBYTE, DEC2 yr.LOWBYTE
иииии TOGGLE hbeat
иииии SEROUT 16,pcComm,["OK",CR]
RETURN

allanlane5
08-04-2005, 04:32 AM
You are aware, that if the BS2 is not 'waiting' in a SERIN command, then it will not get the data, right?

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, [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.