Basically the robot has an XBee module, so a lot of communication will be through that. The robot also has an IR component, so I will be able to control it via a hand held remote control. The FB program will be able to control the robot movements with specific commands, but I am more interested in being able to create script txt files and then have the FB program feed it to the robot, and I will have a specific command that I can get diagnostics from the robot and have the FB program create and store the data in a log file on the computer that it is running on. These are some general ideas of the direction I am heading.
The task at hand, I need to come with a way to communicate with the robot using specific commands. I think I need something like writeStr() to be able to send some string data to the robot, and of course I will need something like readStr() to capture some string data that the robot sends back. But I think on the robot side I will be using commands like 0100, so I will probably need readDec(), or something along those lines.
The one thing I need to do is make the opening of a COM port an interactive event, and get away from having it hard coded like the way it is now. Back to programming...
Code: Select all
' test.bas
'
' January 9, 2017
'
' Specialty Serial Program
'''''''''''''''''''''''''
Dim As String inBuff
Dim As String baud(0 To 7) = {"1200","2400","4800","9600","19200",_
"38400","57600","115200"}
Dim As String port(0 To 10) = {"COM1:","COM2:","COM3:","COM4:","COM5:",_
"COM6:","COM7:","COM8:","COM9:","COM10:","COM11:"}
'''''''''''''''''''''''''
''''' Procedures (subroutines) '''''
''''' serial_open(COM11,9600) '''''
Sub serial_open(getport as string,getbaud as string)
Dim As String baud(0 To 7) = {"1200","2400","4800","9600","19200",_
"38400","57600","115200"}
Dim As String port(0 To 10) = {"COM1:","COM2:","COM3:","COM4:","COM5:",_
"COM6:","COM7:","COM8:","COM9:","COM10:","COM11:"}
if getport = "COM11" then
getport = port(10)
End if
if getbaud = "9600" then
getbaud = baud(3)
end if
Open Com getport & getbaud & ",n,8,1,cs0,ds0,cd0,rs" As #1
If Err <> 0 Then
Print "Error opening", getport
End If
Print "COM11 open"
End Sub
'''''''''''''''''''''''''
''''' writeStr(#1,"String") '''''
' Output data to the COM port
Sub writeStr()
End Sub
'''''''''''''''''''''''''
''''' writeDec(#1, Dec) '''''
Sub writeDec()
End Sub
'''''''''''''''''''''''''
''''' readStr(#1, buffer) '''''
' Input data from the COM port
Sub readStr()
End Sub
'''''''''''''''''''''''''
''''' readDec(#1, buffer) '''''
Sub readDec()
End Sub
'''''''''''''''''''''''''
''''' menu '''''
Sub menu
Print "Menu - Quit or q, help or ?, date, time, "
End Sub
'''''''''''''''''''''''''
''''' Start of main '''''
Print "boterm System Command"
Print "Type help or ? for menu"
' Open a COM port
' Hard coded, will need to make it selectable in live session.
serial_open("COM11","9600")
do
input "> ",inBuff
If inBuff = "Quit" or inBuff = "q" Then
Exit Do
Elseif inBuff = "date" Then
print date
Elseif inBuff = "time" Then
print time
Elseif inBuff = "help" or inBuff = "?" Then
menu
Elseif inBuff = "setserial" Then
print "Future open COM port with BAUD rate."
Else
Print "Invalid Command"
End If
Sleep 1,0
loop
Print "Program End!"
Close
'''''''''''''''''''''''''