I am getting close to introducing some kind of scripting function. Not sure if I should create txt files, separately and then have the program feed it down to the robot, or be able to create script files within the program itself. It seems like it would be easier to deal with the script files as something separate, and then just have my program open the file and send the data line by line to the robot. Probably will have to add in some kind of, did you get it code, to make sure that the data got delivered.
I remember I did something like this using Python, which seemed to have the appropriate functions for accomplishing this, I hope it will be just as easy using FB.
Code: Select all
' test.bas
'
' January 9, 2017
'
' Specialty Serial Program
'''''''''''''''''''''''''
Dim As String inBuff,tmpbuf,cmdbuf,timbuf
Dim temp as integer
Dim Shared as String Gport,Gbaud,errbuf
Dim Shared as Long Gfile
Dim As String baud(0 To 7) = {"1200","2400","4800","9600","19200",_
"38400","57600","115200"}
Dim As String port(0 To 12) = {"COM1:","COM2:","COM3:","COM4:","COM5:",_
"COM6:","COM7:","COM8:","COM9:","COM10:","COM11:","COM12:","COM13:"}
'''''''''''''''''''''''''
''''' Procedures (subroutines) '''''
''''' serial_open(COM11,9600) '''''
Sub serial_open(getport as string,getbaud as string, getfile as Long)
Dim As String baud(0 To 7) = {"1200","2400","4800","9600","19200",_
"38400","57600","115200"}
Dim As String port(0 To 12) = {"COM1:","COM2:","COM3:","COM4:","COM5:",_
"COM6:","COM7:","COM8:","COM9:","COM10:","COM11:","COM12:","COM13:"}
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 #getfile '1
If Err <> 0 Then
Print "Error opening", getport
Else
Print getport
Print " open"
End If
End Sub
'''''''''''''''''''''''''
''''' writeStr(#1,"String") '''''
' Output string to the COM port
Sub writeStr(fileno as Long, strbuff as String)
Print #fileno,strbuff;
Print #fileno,Chr(13);
End Sub
'''''''''''''''''''''''''
''''' writeDec(#1, Dec) '''''
' Output number to the COM port
Sub writeDec(fileno as Long, outdec as Integer)
Print #fileno,outdec
'Print #fileno, Chr(13)
End Sub
'''''''''''''''''''''''''
''''' readStr(#1, buffer) '''''
' Input string from the COM port
Sub readStr()
End Sub
'''''''''''''''''''''''''
''''' readDec(#1, buffer) '''''
' Input number from the COM port
Sub readDec()
End Sub
'''''''''''''''''''''''''
Sub setSerial()
Dim as String newPort, newBaud
Dim as Integer newFile
input "Port:",newPort 'Example-"COM11"
Gport = newPort
input "Baud:",newBaud ' Example - "9600"
Gbaud = newBaud
input "File #:",newFile ' Example - 5
Gfile = newFile
serial_open(newPort,newBaud,newFile)
End Sub
Sub showSerial()
Print "Open Port",Gport
Print "BAUD",Gbaud
print "File",Gfile
End Sub
Sub errchk
' Check for error
sleep 50,0
While( Loc(1) > 0)
errbuf = Input(Loc(1),#Gfile)
Print errbuf
Wend
End Sub
''''' menu '''''
Sub menu
Print "Menu - QUIT or q or quit, help or ?, date, time, "
Print " writestr, "
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" or inBuff = "quit" Then
Exit Do
Elseif inBuff = "date" Then
print date
Elseif inBuff = "time" Then
print time
Elseif inBuff = "help" or inBuff = "?" Then
menu
Elseif inBuff = "writestr" then
input "String: ",tmpbuf
writeStr(Gfile,tmpbuf)
errchk()
Elseif inBuff = "writetstr" then
input "command and time: ",cmdbuf,timbuf ' Example 0001,3000
writeStr(Gfile,cmdbuf)
sleep 50,0
writeStr(Gfile,timbuf)
errchk()
Elseif inBuff = "setserial" Then
setSerial
Elseif inBuff = "showserial" Then
showSerial
Elseif inBuff = "test" then
tmpbuf = "1000"
'temp = val(tmpbuf)
'temp = 1000
'print #Gfile, tmpbuf
Else
Print "Invalid Command"
End If
Sleep 1,0
loop
Print "Program End!"
Close ' Close all files that are open.
'''''''''''''''''''''''''