Script to send data to comport for DMX4ALL controller

Forum over Homeseer scripts (DUTCH forum)

Moderators: TANE, Ruud

raymonvdm
Senior Member
Senior Member
Posts: 1153
Joined: Sun Dec 18, 2011 1:23 am

Script to send data to comport for DMX4ALL controller

Post by raymonvdm »

I`m trying to make a script to send data to com10 (dmx4all interface) to control PAR-LED fixtures. But i`m not shure how to do this

I have found an example but it is not working yet

Code: Select all


sub main
Dim err 
err = hs.OpenComPort(3,"115200,N,8,1", 0, "", "")
If err <> "" Then
hs.writelog "DMX","Unable to Open COM3"
Else
hs.writelog "DMX","COM3 Successfully Opened"
End If
hs.SendToComPort 3,chr(64)&"010"
hs.closecomport 3
hs.writelog "DMX", "Scene 10 activated"
end sub



Can anyone explain what to do, this is my first attempt on making a script


I have installed SerialMon and during an ASCII scan i get the following values

266 2 255 ( 266=unknown 2=channelnr 255=level)

When the interface is idle i see an G and C ? passing by

Image
Running HS3PRO on PC with Z-Wave / OpenTherm / Plugwise / RFXcom / MQTT / XAP400 / Logitech Media Server and Squeezelite on PI`s
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

Re: Script to send data to comport for DMX4ALL controller

Post by Digit »

Sorry, I (and probably no one else either, including you) can't make cheese of the screendumps...
The rest is not enough to be useful.
raymonvdm
Senior Member
Senior Member
Posts: 1153
Joined: Sun Dec 18, 2011 1:23 am

Re: Script to send data to comport for DMX4ALL controller

Post by raymonvdm »

I don`t like cheese :cry:

When i move the slider of channel 2 i see the value changes in the serialmon utility Big Picture

It looks like it is sending valua 226 as start value, followed by a channel number and at last a channel value. Therefore i made the conclusion that i need to open the comport and send value 226,2,200 to get channel 2 on value 200


I found the following "opencomport" script which i`m trying to translate

Code: Select all


Sub Main()
hs.OpenComPort 7,"4800,O,8,1",1,"",""
'hs.SendToComPort 7, rolluik zolder rechts dicht
hs.SendToComport 7, chr(&H7F) &chr(&HF2) &chr(&HFA) &chr(&H01) &chr(&H00) &chr(&H00) &chr(&HA4) &chr(&H78) &chr(&HFA) &chr(&HF4) &chr(&HFD) &chr(&H06) &chr(&H73)       
hs.CloseComPort 7   
End Sub

Running HS3PRO on PC with Z-Wave / OpenTherm / Plugwise / RFXcom / MQTT / XAP400 / Logitech Media Server and Squeezelite on PI`s
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

Re: Script to send data to comport for DMX4ALL controller

Post by Digit »

Don't worry, this forum will help everybody, even those who don't like cheese.
Just be patient and it won't take long... ehh, maybe you like old cheese? :lol:

Just kidding, I'm sure someone will have the answer within 24 hours.
My quick guess is that you're sending "226" instead of chr(226) or doing something similar wrong but to be sure about that I need to start reading the topic all over again and it's a bit too late for that now.
AshaiRey
Senior Member
Senior Member
Posts: 1310
Joined: Mon Feb 02, 2009 5:27 pm
Location: Netherlands
Contact:

Re: Script to send data to comport for DMX4ALL controller

Post by AshaiRey »

What is the error message you get.

Next.
Make the first line like this
Public Sub Main(ByVal Parms As String)

You probaly don't use any parameter so just don't mind them

Make the last line like this
End Sub

Save your script as something.vb. Put it in a test event for example so you can test run is and look in the log for (error) messages

Btw:
Your command hs.SendToComPort 3,chr(64)&"010" will send @010 to the port
chr(64) means the character with ascii value 64 (google for ascii table for more info on this)

You write the command as
266 2 255 ( 266=unknown 2=channelnr 255=level)
Note according the picture 266 should be 226 (Also ascii runs only from 0 to 255)
So sending 226 <space>2<space>255 to the comport must be done as 3 seperate values.
Like this would do:
hs.SendToComPort 3,chr(226)
hs.SendToComPort 3,chr(2)
hs.SendToComPort 3,chr(255)
Bram
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

Re: Script to send data to comport for DMX4ALL controller

Post by Digit »

I come to the same conclusion, the last 3 lines in Brams post should work!

But now I have a question - why would hs.SendToComPort 3, chr(226) & chr(2) & chr(255) not work??
The result is the same as sending a single byte in a 3 separate commands.
raymonvdm
Senior Member
Senior Member
Posts: 1153
Joined: Sun Dec 18, 2011 1:23 am

Re: Script to send data to comport for DMX4ALL controller

Post by raymonvdm »

This is the current script

Code: Select all


Public Sub Main(ByVal Parms As String)
hs.OpenComPort 10,"115200,N,8,1",1,"",""
hs.SendToComPort 10,chr(226)
hs.SendToComPort 10,chr(2)
hs.SendToComPort 10,chr(255)
hs.CloseComPort 10   
End Sub

And this is the error

Code: Select all


28-2-2013 19:42:21  - Error - Script compile error: Methodeargumenten moeten tussen haakjes worden geplaatst.on line 15
28-2-2013 19:45:11  - SCR - Option Strict Offimports Schedulerimports SystemPublic Module scriptcode15#Region "Automatically generated code, do not modify"'Automatically generated code, do not modify'Event Sources Begin	<System.ContextStaticAttribute()> Public WithEvents hs As Scheduler.hsapplication	<System.ContextStaticAttribute()> Public WithEvents hsp As scheduler.hsp	<System.ContextStaticAttribute()> Public WithEvents hssystem As scheduler.phone0'Event Sources End'End of automatically generated code#End RegionPublic Sub Main()hs.OpenComPort 10,"115200,N,8,1",1,"",""hs.SendToComPort 10,chr(226)hs.SendToComPort 10,chr(2)hs.SendToComPort 10,chr(255)hs.CloseComPort 10   End SubEnd Module

Note: I don`t have a line 15 :roll:
Running HS3PRO on PC with Z-Wave / OpenTherm / Plugwise / RFXcom / MQTT / XAP400 / Logitech Media Server and Squeezelite on PI`s
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

Re: Script to send data to comport for DMX4ALL controller

Post by Digit »

The error description is clear, so maybe it has to be like this:
hs.SendToComPort (10, chr(226) & chr(2) & chr(255))
But i'm not sure, I never use scripts myself.
AshaiRey
Senior Member
Senior Member
Posts: 1310
Joined: Mon Feb 02, 2009 5:27 pm
Location: Netherlands
Contact:

Re: Script to send data to comport for DMX4ALL controller

Post by AshaiRey »

Digit wrote:I come to the same conclusion, the last 3 lines in Brams post should work!

But now I have a question - why would hs.SendToComPort 3, chr(226) & chr(2) & chr(255) not work??
The result is the same as sending a single byte in a 3 separate commands.
Sorry but the result isn't the same.

This next statement isn't correct and should be ignored. I leave it here just to enhance your (and mine) learning experience so you will see where the cavecats might be. There correct answer is discussed below.
hs.SendToComPort 3, chr(226) & chr(2) & chr(255) send one string like "value value value" + \n\r (most of the time)
Note: \n is one character for newline and \r is one character for return.

The receiving part must decode this to seperate values.

Sending then as three line then each value will get an enter (\n\r) behind it so the recieving part knows that this chunck of data is finished.
However it's not always like that. It depends mostly on the OS you are talking too.
Last edited by AshaiRey on Fri Mar 01, 2013 12:57 pm, edited 2 times in total.
Bram
AshaiRey
Senior Member
Senior Member
Posts: 1310
Joined: Mon Feb 02, 2009 5:27 pm
Location: Netherlands
Contact:

Re: Script to send data to comport for DMX4ALL controller

Post by AshaiRey »

raymonvdm wrote:And this is the error

Code: Select all


28-2-2013 19:42:21  - Error - Script compile error: Methodeargumenten moeten tussen haakjes worden geplaatst.on line 15
28-2-2013 19:45:11  - SCR - Option Strict Offimports Schedulerimports SystemPublic Module scriptcode15#Region "Automatically generated code, do not modify"'Automatically generated code, do not modify'Event Sources Begin	<System.ContextStaticAttribute()> Public WithEvents hs As Scheduler.hsapplication	<System.ContextStaticAttribute()> Public WithEvents hsp As scheduler.hsp	<System.ContextStaticAttribute()> Public WithEvents hssystem As scheduler.phone0'Event Sources End'End of automatically generated code#End RegionPublic Sub Main()hs.OpenComPort 10,"115200,N,8,1",1,"",""hs.SendToComPort 10,chr(226)hs.SendToComPort 10,chr(2)hs.SendToComPort 10,chr(255)hs.CloseComPort 10   End SubEnd Module

Note: I don`t have a line 15 :roll:
HS need a bit more code to run vbscript like some sort of plugin. To do this it places a few line of extra code to wrap things in something like a container. It's an automatic process thus the few extra line and you ending up at line 15

If you open a com poort it returns the state of the request so you know it's open or not.
A command returns a value and put it in a variable so you can test this. Do like this

Code: Select all

         Dim ComPort As Integer
         Dim Status
         ComPort = 10
         Status = hs.OpenComPort(ComPort, "115200,n,8,1", 1, "", "")

         If Status <> "" Then
             hs.writelog("Error opening COM" & ComPort, Status)
         Else
             hs.writelog("COM " & ComPort, "Com port" & ComPort & " setup complete")
         End If

         hs.SendToComPort(ComPort, Chr(226) )
         hs.SendToComPort(ComPort, Chr(2) )
         hs.SendToComPort(ComPort, Chr(255) )
         hsp.WaitMS(100)            '100ms wait just to be sure. May not needed
         hs.CloseComPort(ComPort)

Bram
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

Re: Script to send data to comport for DMX4ALL controller

Post by Digit »

AshaiRey wrote:Sorry but the result isn't the same.
hs.SendToComPort 3, chr(226) & chr(2) & chr(255) send one string like "value value value" + \n\r (most of the time)
I'm a bit confused, I thought the way 'sendtocomport' worked was widely known.

What you are saying is that Homeseer 'sometimes' adds a \n\r with each call?
I don't believe that. Why? Because if it would be true, virtually NOTHING would work.
It never adds anything you do not specify.

According to your own words, with your 3 lines of code:
hs.SendToComPort(ComPort, Chr(226) )
hs.SendToComPort(ComPort, Chr(2) )
hs.SendToComPort(ComPort, Chr(255) )

, the controller will receive the following (as a series of bytes):

0xe2 0x0a 0x0d 0x02 0x0a 0x0d 0xff 0x0a 0x0d

Right?
Maybe with one or more 0x0a 0x0d left out, cause it happens sometimes

Now look back at SerialMon. What really needs to be sent is: 0xe2 0x02 0xff.
Right?
So will these 3 lines work?
Yes, although they should NOT because of your \r\n story!
Without any test, I'm sure the output of the 3 lines above will be:

0xe2 0x02 0xff

And what will
hs.SendToComPort(ComPort, Chr(226) & Chr(2) & Chr(255)) do?
Exactly the same:

0xe2 0x02 0xff

Let me give some more examples of SendToComPort:

hs.SendToComPort(ComPort, "123" ) will send 0x31 0x32 0x33
hs.SendToComPort(ComPort, "ABC" ) will send 0x41 0x42 0x43
hs.SendToComPort(ComPort, "ABC" & chr(13) & chr(10)) will send 0x41 0x42 0x43 0x0d 0x0a
hs.SendToComPort(ComPort, chr(226) & chr(2) & chr(255)) will send 0xe2 0x02 0xff

You can easily check all this with a Serial Monitor.
This is all theoretical, cause I don't use homeseer. I didn't check it.
But this is how it works and its conform what Homeseer says about how the command works and what the parameters stand for:

Parameter: port
Type: integer
Description: This is the COM port to send the data on or the resource number of the port to send data on if OpenComPortEx was used to open it.

Parameter: data
Type: string
Description: This is the actual data to send out the COM port.

No talk about Homeseer sometimes adding \n\r or whatever. Yes, they do say this:

"Some devices may require a carriage-return and a line-feed character, others perhaps something entirely different. "
But that's something to be done by the user, e.g. by adding those terminators to the data parameter.

Some people may think 'why is he making such an issue out of this?'.
Well, next week someone tries to make a script, searches for "hs.sendtocomport" , finds the wrong examples and gets stuck.
That is the issue I want to prevent from happening, especially because I'm one of the green guys.
AshaiRey
Senior Member
Senior Member
Posts: 1310
Joined: Mon Feb 02, 2009 5:27 pm
Location: Netherlands
Contact:

Re: Script to send data to comport for DMX4ALL controller

Post by AshaiRey »

Digit wrote:
AshaiRey wrote:Sorry but the result isn't the same.
hs.SendToComPort 3, chr(226) & chr(2) & chr(255) send one string like "value value value" + \n\r (most of the time)
I'm a bit confused, I thought the way 'sendtocomport' worked was widely known.
Oops, i made a marginal mistake here.
hs.SendToComPort 3, chr(226) & chr(2) & chr(255) send <value><value><value> without the spaces in between
What you are saying is that Homeseer 'sometimes' adds a \n\r with each call?
I don't believe that. Why? Because if it would be true, virtually NOTHING would work.
It never adds anything you do not specify.
You are 100% right on this one.
Looking back on some comport code i have here i myself did adding vbCrLf to the string to make it work in that particulair case.
It's good that you made that very clear
I've editted my previous statement
Bram
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

Re: Script to send data to comport for DMX4ALL controller

Post by Digit »

Good, so we're on the same track again (and heading in the same direction :lol: )
raymonvdm
Senior Member
Senior Member
Posts: 1153
Joined: Sun Dec 18, 2011 1:23 am

Re: Script to send data to comport for DMX4ALL controller

Post by raymonvdm »

I just dusted off my LED PAR just to test it again, but to no avail yet

Code: Select all


Dim ComPort As Integer
         Dim Status
         ComPort = 10
         Status = hs.OpenComPort(ComPort, "115200,n,8,1", 1, "", "")

         If Status <> "" Then
             hs.writelog("Error opening COM" & ComPort, Status)
         Else
             hs.writelog("COM " & ComPort, "Com port" & ComPort & " setup complete")
         End If

         hs.SendToComPort(ComPort, Chr(226) )
         hs.SendToComPort(ComPort, Chr(2) )
         hs.SendToComPort(ComPort, Chr(255) )
         hsp.WaitMS(100)            '100ms wait just to be sure. May not needed
         hs.CloseComPort(ComPort)

The error code

Code: Select all


21-1-2014 21:08:59  Event  Running script in background: dmx_test.vb 
21-1-2014 21:08:59  Error  Script compile error: Declaratie wordt verwacht.on line 16 
21-1-2014 21:08:59  SCR  Option Strict Offimports Schedulerimports SystemPublic Module scriptcode4#Region "Automatically generated code, do not modify"'Automatically generated code, do not modify'Event Sources Begin Public WithEvents hs As Scheduler.hsapplication Public WithEvents hsp As scheduler.hsp Public WithEvents hssystem As scheduler.phone0'Event Sources End'End of automatically generated code#End RegionDim ComPort As Integer Dim Status ComPort = 10 Status = hs.OpenComPort(ComPort, "115200,n,8,1", 1, "", "") If Status "" Then hs.writelog("Error opening COM" & ComPort, Status) Else hs.writelog("COM " & ComPort, "Com port" & ComPort & " setup complete") End If hs.SendToComPort(ComPort, Chr(226) ) hs.SendToComPort(ComPort, Chr(2) ) hs.SendToComPort(ComPort, Chr(255) ) hsp.WaitMS(100) '100ms wait just to be sure. May not needed hs.CloseComPort(ComPort)End Module 

Running HS3PRO on PC with Z-Wave / OpenTherm / Plugwise / RFXcom / MQTT / XAP400 / Logitech Media Server and Squeezelite on PI`s
Akatar
Senior Member
Senior Member
Posts: 1134
Joined: Thu Nov 22, 2007 12:25 am
Location: the netherlands

Re: Script to send data to comport for DMX4ALL controller

Post by Akatar »

droezel has a homeseer plugin for the lan dmx controller (dmx4all)
Post Reply

Return to “Homeseer Scripts Forum”