AbelCam Forum
Download AbelCam buy Pro
 
 
 
Welcome Anonymous User
04/16/2025 - 05:23 PM
Quick Search:
Quick Jump:
 
Announcements
Latest Topics
 
Controlling lights (or other devices) with Logisphere via serial port
By: JarkkoM
Rank: Frequent User
Topics: 16
From: n/a
Added: 04/20/2006 - 02:13 AM

First I tried to make this with http://realterm.sourceforge.net, but it did not work. Or it worked sometimes and sometimes not, I do not know what the problem was. I had to find some other Way to control serial port and Visual Basic scripts looked the most easy way.

I made four visual basic scripts to control DTR an RTS pins of the serial port. Somebody who knows something about programming may laugh to them, but for me most important is that they work.

With very simple hardware connected to serial port you can control relay or two. When DTR or RTS pin is up there is +12V and -12V when down.

Scripts use MSComm Control. If you have problems with it, here is some help for registering it. That registry entry there helped me. http://www.yes-tele.com/mscomm.html

Scripts use control.txt file. When you run for example DTRon.vbs, it first writes 1 to control.txt. Then it loops and read control.txt every second. Scripts don't create that file it must be created first.

Script off.vbs writes 0 to control.txt and when DTRon.vbr reads it, it will shut down. When for example DTRon.vbs is running the serial port is reserved and can not be controlled by other script. That's why running script must be shut down first.

Other text file is delay.txt. In there you can write on-off delay in seconds for scripts. If you set 0 for delay, there is no delay and scripts will shut down only when 0 is written in the control.txt. Max delay is 99999 seconds.

I placed scripts and text files to folder c:\serveri\VB\ .
Paths must be edited if/when text files are in different folder.

Here is the scripts:

DTRon.vbs

' Writes 1 to c:\serveri\VB\control.txt

ForAppending = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
  ("c:\serveri\VB\control.txt", ForAppending, True)
objTextFile.WriteLine("1")
objTextFile.Close

' Set DTR pin up

set com_port = CreateObject("MSCOMMLib.MSComm")
com_port.commport = 1
com_port.PortOpen = True
com_port.RTSEnable = False
com_port.DTREnable = True


' Read c:\serveri\VB\delay.txt

Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objFile = objFSO.OpenTextFile("c:\serveri\VB\delay.txt", 1)
		Do Until objFile.AtEndOfStream	
			strDelay = objFile.Read(5)
		Loop

' Convert string to integer

intDelay = CInt(strDelay)

' If delay is 0 it will be ignored

if intDelay > 0 Then

inti = 0

' Do while contents of c:\serveri\VB\delay.txt is 1 and inti is smaller than intDelay

intcontrol = 1

Do While intcontrol = 1 And inti < intDelay
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objFile = objFSO.OpenTextFile("c:\serveri\VB\control.txt", 1)
		strcontrol = objFile.Read(1)
	intcontrol=CInt(strcontrol)
' Waits for a second
	Wscript.Sleep 1000
	inti = inti + 1
	
Loop

com_port.PortOpen = False

else

intcontrol = 1

Do While intcontrol = 1
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objFile = objFSO.OpenTextFile("c:\serveri\VB\control.txt", 1)
		strcontrol = objFile.Read(1)
	intcontrol=CInt(strcontrol)
	
' Waits for a second
	Wscript.Sleep 1000
	
Loop
	
com_port.PortOpen = False

End If
RTSon.vbs Only difference to DRTon.vbs is lines.
com_port.DTREnable = False
com_port.RTSEnable = True
BOTHon.vbs
com_port.DTREnable = True
com_port.RTSEnable = True
off.vbs
Write 0 to control.txt
ForAppending = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
  ("c:\serveri\VB\control.txt", ForAppending, True)
objTextFile.WriteLine("0")
objTextFile.Close

Wscript.Sleep 1500
Virus scanners thinks that those scripts are malicious because they write to file. They must be set trusted in virus scanner. VB scripts can not be run from Logisphere so i made some cmd files. DTR.cmd
off.vbs
DTRon.vbs
First in write 0 to control.txt. Then there is some delay (1500ms) at the end of the off.vbs so that possible running script has time to shut down. Time can be adjusted to little longer if serial port is not open error occurs. Then it runs DTRon.vbs RTS.cmd
off.vbs
RTSon.vbs
BOTH.cmd
off.vbs
BOTHon.vbs
OFF.cmd
off.vbs
Other files, these both must exist. control.txt
0
delay.txt
120
I put all those scripts and cmd files to same folder and then added that to Windows path. Then it's easy to run the from Logisphere. There is instruction how to edit path. http://www.cs.ucsb.edu/~teliot/Path_and_Classpath.htm Then the commands in Logishere must be set. Address is what you call from webpage Command is the cmd file, when the folder where they are, is added to path, you can write only the name. Then I made test page like this:
< body >
< p >< a href = "http://host: port/dtr_on" target = "dummy" >DTR ON< /a >< /p >
< p >< a href = "http://host: port dtr_off" target = "dummy" >DTR OFF< /a >< /p >
< p >< a href = "http://host: port rts_on" target = "dummy" >RTS ON< /a>< /p >
< p >< a href = "http://host: port rts_off" target = "dummy" >RTS OFF< /a>< /p >
< p >< a href = "http://host: port both_off" target = "dummy" >BOTH OFF< /a >< /p >
< p >&nbsp;< /p >

< iframe src = "" height = 1 width = 1 name = dummy> < /iframe >



There are little bit too many spaces, but the idea is most important. Host: port is server address and port.

This is test circuit I made:





Real relay circuit will be something like this.

http://b-l-w.de/serialrelay_en.php

Here's screenshot of my webpage:



System works quite nice. Pins can not be controlled separately, that only problem. But I am going to control possible only one lamp so this is enough for me.
By: sse
Rank: Forum Addict
Topics: 73
From: n/a
Added: 04/20/2006 - 07:30 AM

Hello Jarkko,
thank you for describing what you are doing with the external command feature.

I edited your topic a bit to make the URLs clickable and for the code samples to stand out a bit.
Let us know how you get ahead with the hardware required.
By: JarkkoM
Rank: Frequent User
Topics: 16
From: n/a
Added: 04/20/2006 - 01:36 PM


The Realterm worked not like i thought...

So I made some VB scripts to controll RTS and DTR lines. They are my first ever VB scripts... They are not perfect, but they work.

I will write more when I have the real relay hardware ready.