@echo off
echo status: 204
echo.
echo.
set p1=%QUERY_STRING:~0,3%
set p2=%QUERY_STRING:~4,3%
set p3=%QUERY_STRING:~8,3%
mode com1:9600,N,8,1 >nul
echo %p1%%p2%%p3% >com1
cls
255-001-128
>16.03.2004 03:03, Si Ballenger schrieb:
>
>> Is there a way to replace the below batch file with a VB script?
>> I use this type of batch file as a cgi application to operate a
>> webcam pan/tilt gizmo. The top echos send the "status: 204" and
>> two blank lines to stdout for the web server. The next part
>> splits up the query_string environmental variable set by the web
>> server. The bottom part sends the desired characters to the
>> serial port. The bottom line would be what the query_string
>> looks like. My main interest is that VB script can send bytes in
>> decimal form like chr(255)
>
>VBScript has a Chr()-Function in order to send/print
>Chars by Ascii-numbers. Wscript.Echo Chr(7), e.g.
>prints a "bell"-Char in a console-script,
>Wscript.Echo Chr(9) makes a hTab.
>
>So something like WScript.SdtOut.Write Chr(255)
>writes that special char to the stdout (in a script
>ran by CSCRIPT.EXE)
>
>> which simple echo in a batch file can't.
>
>If you write your batch-files with good ole EDIT.COM
>you can make ECHO echo control-chars by using the Ctrl+P-
>Shortcut and then the NUM+<ascii-code> combination.
>
>So open EDIT, type <CTRL+P> (the status-text changes) then keep
><NUM+ALT> pressed, finally type 255.
>This works at least with the 'Beep'-Char (ascii 7)
>
>> Any info appreciated.
>
>
>'VBScript run by cscript.exe, untested:
>
>Dim wsh, comm, envQueryString
>Dim p1,p2,p3
>
>Set wsh = CreateObject ("WScript.Shell")
>envQueryString = wsh.ExpandEnvironmentStrings("%QUERY_STRING%")
>
>> @echo off
>> echo status: 204
>
>WScript.Stdout.WriteLine "status: 204"
>
>> echo.
>> echo.
>
>WScript.Stdout.WriteBlankLines 2
>
>> set p1=%QUERY_STRING:~0,3%
>> set p2=%QUERY_STRING:~4,3%
>> set p3=%QUERY_STRING:~8,3%
>
>p1 = Mid(envQueryString,1,3)
>p2 = Mid(envQueryString,5,3)
>p3 = Mid(envQueryString,9,3)
>
>> mode com1:9600,N,8,1 >nul
>
>'That's the tricky part, you need an extra control MSCommlib
>'which is licsened and ships with VB 6.0
>
>Set comm = CreateObject("MSCOMMLib.MsComm")
>comm.CommPort = 1
>comm.PortOpen = True
>comm.Settings = "9600,N,8,1"
>
>> echo %p1%%p2%%p3% > com1
>
>comm.Output = p1 & p2 & p3
>
>'I am not too experienced with this control
>'maybe you have to set additional settings first like
>' comm.OutBufferSize = <integer>
>
>> cls
>
>'no equivalent, maybe, in a cscript-file
>'WScript.StdOut.WriteBlankLines 25
>'assuming that the average cmd-window has 25 lines
>
>> 255-001-128
>
>Does this work in DOS? afaik it needs to be echoed.
>
>WScript.Stdout.Write Chr (255) & Chr(1) & Chr(128)
Double clicking on the vbs file to see if it will run, I get an
error on the "status: 204" line. The below will write the bytes
to the hardware com1 port on my XP machine. Not sure if it will
write to a virtual com port, but is one work around for having
the VB MSCOMM. The bottom link has one of th servo pan/tilt cams.
Set fs=CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("COM1:",True)
a.write chr(255)
a.write chr(1)
a.write chr(128)
a.Close
>17.03.2004 00:08, Si Ballenger schrieb:
>
>
>>> WScript.Stdout.WriteLine "status: 204"
>
>> Double clicking on the vbs file to see if it will run, I get an
>> error on the "status: 204" line.
>
>That's most likely because double-clicking starts WScript.Exe
>as Script-Host. Which has no Stdout-handle. Thats why i
>stressed multiple times that the script is designed for CSCRIPT
>which prints to Stdout.
>
>> The below will write the bytes
>> to the hardware com1 port on my XP machine. Not sure if it will
>> write to a virtual com port, but is one work around for having
>> the VB MSCOMM. The bottom link has one of th servo pan/tilt cams.
>>
>> Set fs=CreateObject("Scripting.FileSystemObject")
>> Set a = fs.CreateTextFile("COM1:",True)
>> a.write chr(255)
>> a.write chr(1)
>> a.write chr(128)
>> a.Close
>
>Quite nice. I thought you would need to do some settings
>first like setting baud-rate, parity-bit and so on.
>because of the: 'mode COM1, 9600, N, 8, 1' -line
>I found no way to do so with a TextStream opening COM1
>But as long as it works, it's alright.
I've set cscript as the default script host and don't get errors
now (at least that I can see). Is there a way to incorporate the
above writing to com1 in to the origional script you posted?
I've tried commenting out the getting the query string and just
substituting a line envQueryString = 255-001-128 just to test the
parsing and writing to com1, but no servo action. What would go
in the XXXXXXXXXXXX line below for testing by double clicking? If
I can get the below to move the servo by double clicking, then I
can move the file to the cgi folder and see if it can get the
query_string variable.
Set wsh = CreateObject ("WScript.Shell")
'envQueryString = wsh.ExpandEnvironmentStrings("%QUERY_STRING%")
envQueryString = 255-001-128
WScript.Stdout.WriteLine "status: 204"
WScript.Stdout.WriteBlankLines 2
p1 = Mid(envQueryString,1,3)
p2 = Mid(envQueryString,5,3)
p3 = Mid(envQueryString,9,3)
Set fs=CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("COM1:",True)
XXXXXXXXXXXXXXXXXX
'a.write chr(255)
>Since I've never done serverside scripting so far (although i
>registered my own domain and bought a perl-cgi and php book today)
>i can't say anything specific for cgi or serverside issues...
I've been tinkering with the below. My apache module doesn't
directly execute the vbs file, so tried running it as a bat. It
will run once like that, but only once. The below when run by
itself bydouble clicking it moves the servo OK when the position
is changed in the file and saved. Guess the next experiment is to
add the "255-001-128" as an argument in a batch file and try
running it something like servo.vbs "255-001-128"
'envQueryString = wsh.ExpandEnvironmentStrings("%QUERY_STRING%")
envQueryString = "255-001-128"
'WScript.Stdout.WriteLine "status: 204"
'WScript.Stdout.WriteBlankLines 2
p1 = Mid(envQueryString,1,3)
p2 = Mid(envQueryString,5,3)
p3 = Mid(envQueryString,9,3)
Set fs=CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("COM1:",True)
a.Write Chr(CInt(p1))
a.Write Chr(CInt(p2))
a.Write Chr(CInt(p3))
a.Close