Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Serial Port in VBScript

  1. #1
    Join Date
    May 2008
    Location
    Florida
    Posts
    14
    Rep Power
    37

    Question Serial Port in VBScript

    Hello again,

    I'd like to know how to use VBScript to communicate through a serial port, say COM1, to move servos connected to an SSC-32 board. I saw that RoboRealm was recommended, but I want to go one step at a time: just to move a simple servo with VBScript.

    Thanks!

  2. #2
    Join Date
    Jul 2008
    Location
    Belgium
    Posts
    633
    Images
    2
    Rep Power
    61

    Re: Serial Port in VBScript

    I have a vague recollection of not being able to use the MSCOMM object in VBscript / VBA but you can substitute NETCOMM.ocx for this.. can anyone confirm this?

    Sorry judge, I want to get this cleared before I'd jump in and try to help you out with something that doesn't work
    Artificial Intelligence is no match for Natural Stupidity

    "For a list of all the ways technology has failed to improve life, press three" - Alice Kahn

    Resistance is futile! (if < 1)

  3. #3
    Join Date
    Apr 2008
    Location
    Sacramento, CA, USA Area
    Posts
    5,341
    Rep Power
    176

    Re: Serial Port in VBScript

    You could probably do something like:

    Code:
    Sub MyFunction()
        Set MSComm1=CreateObject("MSCOMMLib.MSComm")
        MSComm1.Settings = "9600,n,8,1"
        MSComm1.CommPort = 1
        MSComm1.InBufferCount = 0
        MSComm1.PortOpen = True
          If Err Then
             MsgBox "COM" & MSComm1.CommPort & ": not opened, Sorry!"
             Exit Sub
          End If
        MSComm1.Output="#1 P1500" & CHR(13)
        WScript.Sleep(1000)
        MSComm1.PortOpen = False
        Set MSComm1 = Nothing
    End Sub
    That's a snippet to point you in the right direction. It's not function-complete. Once the function is completed, that should center the servo on port 1 for an SSC with a 9600baud setting. The & CHR(13) is important. You must terminate commands to the SSC-32 with a <cr> character.

    Does that help? I don't have time to write and test it at the moment, but is it enough of a pointer to get you going?

    [edit] That should be code-complete. You could try that without too much risk. Change the baudrate as appropriate, I have mine set to 9600 for wireless use...

    [edit again]
    added simple error checking and closed comport afterwards...
    Last edited by Adrenalynn; 07-31-2008 at 01:39 PM.
    I Void Warranties�

  4. #4
    Join Date
    Apr 2008
    Location
    Sacramento, CA, USA Area
    Posts
    5,341
    Rep Power
    176

    Re: Serial Port in VBScript

    Since multiple people are in this thread, I'm adding this bump that I'll delete later. I edited the code, please refresh.
    I Void Warranties�

  5. #5
    atari Guest

    Re: Serial Port in VBScript

    I need to print whatever is on the screen of a kiosk when a button is pressed.

    I was hoping to be able to do this in VBSCRIPT -- the code for printing what is on the screen is not the issue, it is "trigger" to launch the vbscript.

    I assume I could somehow wire a button from radio shack up to an DB9 RS232 port and provide input that way? But I would have no clue where to begin...

    any suggestions?

  6. #6
    Join Date
    Apr 2008
    Location
    Sacramento, CA, USA Area
    Posts
    5,341
    Rep Power
    176

    Re: Serial Port in VBScript

    Welcome to the forum!

    Eeek! UARTS! I'd suggest, given it's a PC, that you save some extra headache and use the [dumdumDUM!] printer port if you have an extra available.

    I'd do something like the circuit enclosed (but then, I've been building parallel port toys for close to thirty years(!)...)

    Attachment 1220

    I'm not vbScript expert by any stretch, but I think the code given here: should at least tell you what signal you want to read, and how to get at it through the printer driver. Otherwise, you need to twiddle bits directly.

    Code:
    Displays current status for all printers on a computer. 
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    
    Set colInstalledPrinters =  objWMIService.ExecQuery _
        ("Select * from Win32_Printer")
    
    For Each objPrinter in colInstalledPrinters
        Wscript.Echo  "Name: " & objPrinter.Name
        Wscript.Echo  "Location: " & objPrinter.Location
        Select Case objPrinter.PrinterStatus
            Case 1
                strPrinterStatus = "Other"
            Case 2
                strPrinterStatus = "Unknown"
            Case 3
                strPrinterStatus = "Idle"
            Case 4
                strPrinterStatus = "Printing"
            Case 5
                strPrinterStatus = "Warmup"
        End Select
        Wscript.Echo  "Printer Status: " & strPrinterStatus
        Wscript.Echo  "Server Name: " & objPrinter.ServerName
        Wscript.Echo  "Share Name: " & objPrinter.ShareName
        Wscript.Echo
    Next
    


    If you *really* wanna use the serial port, than we can start talking about the Max232 chip and interfacing.
    I Void Warranties�

  7. #7
    Join Date
    Feb 2009
    Location
    Mesa, AZ
    Posts
    351
    Images
    84
    Rep Power
    48

    Re: Serial Port in VBScript

    With regards to Judge's original post, I am trying to accomplish the same thing. Output serial data through selected comport to SSC. I whipped up this form in VB Express 2008.
    What I envision, are a series of buttons that will correspond to pre-made sequences courtesy of Lynxmotion Visual SEQ. Once I have that basic functionality working, I would like to be able to map the buttons to keyboard, gamepad or joystick. Included is a web browser window to connect to IP-cam and damage readout corresponding to hits registered from impact sensors (10 total or 10% till elimination). I also have a series of status leds whose purpose is still undetermined at this time.

    I found a helpful post on Lynxmotion's forum from a user doin the same thing.
    http://www.lynxmotion.net/viewtopic.php?t=4017
    But, I'm having some problems adapting his code to my prog. Compile errors. So, while I muddle through, I thought I'd present this to anyone interested, for thoughts, critiques, or help. Feel free to adapt to your own purposes, as I release this into GPL.

    Oh, btw, the Eject button triggers my death sequence. You know, just in case...

  8. #8
    Join Date
    Feb 2009
    Location
    Mesa, AZ
    Posts
    351
    Images
    84
    Rep Power
    48

    Smile Re: Serial Port in VBScript

    Using 'Beave's code as a starting point, I started writing a VB program to control my 8DOF mech CLYDE. I have successfully moved one leg on Button_4 using the code provided, but it only sends the first line of servo positions. I am not clear if the 'Sleep' command is a VB statement or a SSC command. Also, when I connect a second button control (Button6_Click) to the same serial port control, nothing is sent. (No blinky on SSC-32)
    Code:
    Public Class Form1 
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
            SerialPort1.Open() 
        End Sub 
     
        Public Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click 
            'Walk Forward       LH,       LT,       LK,       LA,      speed 
            SerialPort1.Write("#28 P1500 #29 P1500 #30 P1500 #31 P1500 T1000" + Chr(13)) 
            Sleep(900) 
            SerialPort1.Write("#28 P1573 29 P1292 #30 P1292 #31 P1427 T1000" + Chr(13)) 
            Sleep(900) 
            SerialPort1.Write("#28 P1573 #29 P1708 #30 P1708 #31 P1427 T1000" + Chr(13)) 
            Sleep(900) 
            SerialPort1.Write("#28 P750 #29 P750 #30 P750 #31 P750  T1000" + Chr(13)) 
            Sleep(900) 
        End Sub 
     
        Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click 
            'Walk Backward       LH,       LT,       LK,       LA,      speed 
            SerialPort1.Write("#28 P1500 #29 P1500 #30 P1500 #31 P1500 T1000" + Chr(13)) 
            Sleep(900) 
            SerialPort1.Write("#28 P1573 29 P1292 #30 P1292 #31 P1427 T1000" + Chr(13)) 
            Sleep(900) 
            SerialPort1.Write("#28 P1573 #29 P1708 #30 P1708 #31 P1427 T1000" + Chr(13)) 
            Sleep(900) 
            SerialPort1.Write("#28 P750 #29 P750 #30 P750 #31 P750  T1000" + Chr(13)) 
            Sleep(900) 
        End Sub 
    End Class
    Can anybody figure out what I'm doing wrong?

  9. #9
    Join Date
    Mar 2008
    Location
    Knoxville, TN
    Posts
    274
    Images
    35
    Rep Power
    53

    Re: Serial Port in VBScript

    Sleep is a VB command.. Causes a delay.. and it's set to 900. Which is 9/10 of a second.. You might try increasing it a tad since you have the speed set to 1000. (maybe 1100)

    Thanks, Connor

  10. #10
    Join Date
    Apr 2008
    Location
    Sacramento, CA, USA Area
    Posts
    5,341
    Rep Power
    176

    Re: Serial Port in VBScript

    Hi there,

    As Connor alluded to - sleep(900) is telling VB to sleep for 900ms. The T1000 command is telling the SSC32 to take 1000ms to complete the move you've requested. Is there a good reason for asking for every move to take 1000ms?

    It doesn't look like you're looping, I don't think the event handler code is there (did you write the event handler?) - with as much as we can see, I suspect you press the button, good things happen, you fall out of the subroutine and that's it. Is that what you're observing?
    I Void Warranties�

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Question(s) Cannot figure out how to write to the serial port in C++
    By Superlaxstar112 in forum Software and Programming
    Replies: 4
    Last Post: 07-23-2008, 05:02 PM
  2. Lassen GPS Eval kit and serial connection
    By IntoMo in forum Sensors
    Replies: 2
    Last Post: 06-30-2008, 11:24 AM
  3. Question(s) servo and motor controllers
    By csdude in forum Arbotix, Microcontrollers, Arduino
    Replies: 7
    Last Post: 06-15-2008, 08:23 PM
  4. Kyosho 32 Port Sensor Board for RCB3
    By Droid Works in forum Arbotix, Microcontrollers, Arduino
    Replies: 4
    Last Post: 05-02-2008, 08:07 PM
  5. Kondo web page translated.
    By Droid Works in forum Humanoids, Walkers & Crawlers
    Replies: 4
    Last Post: 10-06-2007, 05:49 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •