15.09.2023, 12:04
(14.09.2023, 20:37)Bitver Wrote:(14.09.2023, 13:41)Joep Wrote: With the script below i now can control one motor. But that motor was already programmed by a remote control. Now my question is if someone can tell me if and how it's possible to program a new motor from scratch on please as i totaly don't understand the protocol and all of its functions. There is no manuel explaining the RTS protocol so i'm really confused..
value = event.getvalue()
require('serial')
port = serial.open('/dev/RS485', {
baudrate = 4800,
databits = 8,
stopbits = 1,
parity = 'odd',
duplex = 'half'
})
if value == false then
res, err = port:write(string.char(0x7F,0xF2,0xFA,0xC9,0x7B,0xFA,0x00,0x00,0x00,0xFE,0xFE,0x06,0xA5))
else
res, err = port:write(string.char(0x7F,0xF2,0xFA,0xC9,0x7B,0xFA,0x00,0x00,0x00,0xFE,0xFD,0x06,0xA4))
end
log(res, err)
You should know address of motors and implement your sendRS485 function with your connection parameters.
Check code below it would be great if it works you, but I can't be responsible for it.
It work with my motors.
Code:-- 1/0 up/down
function rs485windowControl(value, address)
msg = bit.bxor(0x80, 0xFF)
len = bit.bxor(0x0D, 0xFF)
con = bit.bxor(0x05, 0xFF)
sr1 = bit.bxor(0xFE, 0xFF)
sr2 = bit.bxor(0xFF, 0xFF)
sr3 = bit.bxor(0xFF, 0xFF)
de1 = bit.bxor(0x72, 0xFF)
de2 = bit.bxor(0xBB, 0xFF)
de3 = bit.bxor(0x05, 0xFF)
da1 = bit.bxor(address, 0xFF) -- address
local da2
if value then
da2 = bit.bxor(0x01, 0xFF)
else
da2 = bit.bxor(0x02, 0xFF)
end
sum = msg + len + con + sr1 + sr2 + sr3 + de1 + de2 + de3 + da1 + da2
sum1, sum2 = Int16ToBytes(sum, 'little')
sendRS485(string.char(msg, len, con, sr1, sr2, sr3, de1, de2, de3, da1,da2, sum2, sum1))
end
function rs485windowStop(address)
msg = bit.bxor(0x80, 0xFF)
len = bit.bxor(0x0D, 0xFF)
con = bit.bxor(0x05, 0xFF)
sr1 = bit.bxor(0xFE, 0xFF)
sr2 = bit.bxor(0xFF, 0xFF)
sr3 = bit.bxor(0xFF, 0xFF)
de1 = bit.bxor(0x72, 0xFF)
de2 = bit.bxor(0xBB, 0xFF)
de3 = bit.bxor(0x05, 0xFF)
da1 = bit.bxor(address, 0xFF) -- address
da2 = bit.bxor(0x03, 0xFF)
sum = msg + len + con + sr1 + sr2 + sr3 + de1 + de2 + de3 + da1 + da2
sum1, sum2 = Int16ToBytes(sum, 'little')
sendRS485(string.char(msg, len, con, sr1, sr2, sr3, de1, de2, de3, da1,da2, sum2, sum1))
end
function rs485windowSetChannel(address)
msg = bit.bxor(0x97, 0xFF)
len = bit.bxor(0x0C, 0xFF)
con = bit.bxor(0x05, 0xFF)
sr1 = bit.bxor(0xFE, 0xFF)
sr2 = bit.bxor(0xFF, 0xFF)
sr3 = bit.bxor(0xFF, 0xFF)
de1 = bit.bxor(0x72, 0xFF)
de2 = bit.bxor(0xBB, 0xFF)
de3 = bit.bxor(0x05, 0xFF)
da1 = bit.bxor(address, 0xFF) -- address
sum = msg + len + con + sr1 + sr2 + sr3 + de1 + de2 + de3 + da1
sum1, sum2 = Int16ToBytes(sum, 'little')
sendRS485(string.char(msg, len, con, sr1, sr2, sr3, de1, de2, de3, da1, sum2, sum1))
end
function rs485windowMy(address)
msg = bit.bxor(0x80, 0xFF)
len = bit.bxor(0x0D, 0xFF)
con = bit.bxor(0x05, 0xFF)
sr1 = bit.bxor(0xFE, 0xFF)
sr2 = bit.bxor(0xFF, 0xFF)
sr3 = bit.bxor(0xFF, 0xFF)
de1 = bit.bxor(0x72, 0xFF)
de2 = bit.bxor(0xBB, 0xFF)
de3 = bit.bxor(0x05, 0xFF)
da1 = bit.bxor(address, 0xFF) -- address
da2 = bit.bxor(0x04, 0xFF)
sum = msg + len + con + sr1 + sr2 + sr3 + de1 + de2 + de3 + da1 + da2
sum1, sum2 = Int16ToBytes(sum, 'little')
sendRS485(string.char(msg, len, con, sr1, sr2, sr3, de1, de2, de3, da1,da2, sum2, sum1))
end
function rs485windowHeight(value, address)
local tilt = 1
if value <= 127 then
value = 128 - value
else
tilt = 0
value = 256 - value + 127
end
msg = bit.bxor(0x81, 0xFF)
len = bit.bxor(0x0D, 0xFF)
con = bit.bxor(0x05, 0xFF)
sr1 = bit.bxor(0xFE, 0xFF)
sr2 = bit.bxor(0xFF, 0xFF)
sr3 = bit.bxor(0xFF, 0xFF)
de1 = bit.bxor(0x72, 0xFF)
de2 = bit.bxor(0xBB, 0xFF)
de3 = bit.bxor(0x05, 0xFF)
da1 = bit.bxor(address, 0xFF) -- address
da2 = value
sum = msg + len + con + sr1 + sr2 + sr3 + de1 + de2 + de3 + da1 + da2
sum1, sum2 = Int16ToBytes(sum, 'little')
sendRS485(string.char(msg, len, con, sr1, sr2, sr3, de1, de2, de3, da1,da2, sum2, sum1))
end
function Int16ToBytes(num, endian)
if num < 0 then
num = bit.band(num, 0xFFFF)
end
highByte = bit.rshift(bit.band(num, 0xFF00), 8)
lowByte = bit.band(num, 0xFF)
if endian == "little" then
lowByte, highByte = highByte, lowByte
end
return highByte,lowByte
end
Thanks for your answer and sharing your code. My biggest issue is how to set the correct channel? How is this done? First with a Somfy remote and once paired you can also control it by the script or how does it work?