If you're looking for a simple way to use the COM port for just about anything, look no further. VBS is the scripting language you're looking for. The only requirement is having the ActiveXperts Comport module installed. I have used the script in this tutorial for the Coffee PC mod, as well as the fully automated computercontrolled coffeemaker.

First of all, you need to initialize the module:

Set objComport = CreateObject( "ActiveXperts.Comport" )

objComport.Device = "COM1"

Afterwards you can use the COM port as you please. I made a prompt in VBS so there can be a range of stuff the script can do. That's done like so:

promptInput=inputbox("Hey dude, you can choose from the following:" &
vbCrLf & "" & vbCrLf & "1. Coffee" & vbCrLf & "2. Pie")

Of course the prompt can be much simpler if the options weren't displayed with the necessary CrLf's. How the interface works is up to you. With promptInput the input is captured in the variable. The choices you can make are processed by a switch:

select case promptInput


' Option nr. 1 - Coffee

case "coffee"

' do something here

' do something here


' Option nr. 2 - Pie

case "pie"

' do something here

' do something here


' No option

case Else

meh=msgbox("Thats not one of the options.", vbcritical, "Option: none")


end select

The exceptions are caught by the case Else. All that's left is the connection to the COM port itself. The example below is connecting the COM port and keeping the connection alive for 10 seconds:

objComport.Open ()

objComport.Sleep 100000

objComport.Close ()

In this example i'm using Sleep, because my implementation on the script is just that (turning the coffeemaker on and off, the PCB the COM port is connected to does all the work). For more information on the ActiveXperts Comport module and the place to download it from is found here.



Since I'm just a little bit lazy, I used my coffeemaking script for the complete example below, instead of the snippets above put together. Below you can see the whole script, using a correct implementation on the module and connecting the COM port:

Set objComport = CreateObject( "ActiveXperts.Comport" )

objComport.Device = "COM1"



var1=inputbox("Hey dude, you can choose from the following:" & vbCrLf & "" & vbCrLf & "1. Coffee" & vbCrLf & "2. Stop" & vbCrLf & "3. Start")


select case var1


' Option nr. 1

case "coffee"

objComport.Open ()

objComport.Sleep 360000

objComport.Close ()


' Option nr. 2

case "stop"

objComport.Close ()


' Option nr. 3

case "start"

var2=inputbox("Insert the number of ms the COM port should stay connected")

objComport.Open ()

objComport.Sleep var2

objComport.Close ()


' Option nr. 4

case "alarmclock"

var4=msgbox("This option is not implemented in this version.", vbinformation, "Option: Alarm Clock")


' Functie nr. 5

case "about"

var5=msgbox("This script is made by US! Ha. Ha. Ha."" & vbCrLf & "" & vbCrLf & "The options are:" & vbCrLf & "" & vbCrLf & "1. Coffee" & vbCrLf & "2. Stop" & vbCrLf & "3. Start")


' No option

case Else

var3=msgbox("Thats not one of the options", vbcritical, "Option: none")


end select




React on this article







Enter the code here: