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.