Добрый день. Такая ситуация. Необходимо отправлять команду через RS-485 на устройство и получать от него ответ, отправляя его в топик.
Привожу правило:
defineVirtualDevice("WindSensor2", {
title: "WindSensor",
cells: {
StartReading: {
type: "switch",
value: false
},
Result:{
type: "text",
value: "",
readonly: true
},
}
});
defineRule("repeatTimer",{
asSoonAs: function () {
return dev["WindSensor2/StartReading"] ;
},
then: function () {
startTicker("two_seconds", 2000);
}
});
var portUART = "/dev/ttyRS485-1";//порт
defineRule("GetValue",{
when: function () { return timers.two_seconds.firing; },
then: function () {
if (dev["WindSensor2/StartReading"] == true){
var buf='2430312C57563F2A2F2F'
var hexBuf = buf.toString();//force conversion
var dataString = "";
for (var i = 0; i < hexBuf.length; i += 2)
dataString += String.fromCharCode(parseInt(hexBuf.substr(i, 2), 16));
dataString+="\n"
//log.info("Output String to Device", dataString);
log("Output String to Device", dataString);
//dev["WindSensor2/Result"] = dataString;
var commandName = "echo -en "+"\""+dataString+"\""+" > "+portUART;
log("Command to Send", commandName);
//log.info("dataString",dataString)
runShellCommand(commandName,
{
captureOutput: true,
captureErrorOutput: false,
exitCallback: function (exitCode, capturedOutput, capturedErrorOutput) //Функция, в которую попадает вывод
{
var result = capturedOutput;
log("Result output: ", capturedOutput); //строка полностью
dev["WindSensor2/Result"] = capturedOutput.toString();
log("cmd Erroroutput: ", capturedErrorOutput);
if (exitCode){
log.error("Ошибка: "+capturedErrorOutput);
}
}
});
}
else {
timers.two_seconds.stop();
}
}
});
Драйвер mqtt-serial отключил. Параметры пора выставил необходимые. Но результат такой. Ответа нет.
Параметры порта:
Перепробовал и в HEX кидать, и строка. Без изменений.
Общение должно быть подобным образом:
Отправил: $01,WV?//<cr><lf>
Получил: $WI,WVP=020.0,045,073<cr><lf>
<cr><lf> - символы \r и \n соответственно.
В чём может быть дело?