반응형
라즈베리파이 보드 / 리눅스 OS에서 Node RED 플랫폼을 올려 사용중인 환경이다.
이전에는 Modbus TCP Protocol 기반에서 작업을 했지만 이번엔 미쯔비시 사 Melsec Protocol
을 사용해볼 것이다.
읽어올 메모리맵이 적고 한정되어 있다면 간단하지만,.
더 광범위 하다면 한번에 많은 데이터를 지속적으로 읽어올 경우 손실도 크고, 보드 메모리 문제로
프로그램이 뻑? 날 수 있다.
그러므로 라운드로빈(Query 를 돌려야 한다)~ 을 적용 시켜야 한다.
라운드 로빈을 할 수 있게 쿼리 처리부분과
var msg_melsec = [];
msg_melsec = [
"D6000,100",
"D6100,100",
"D6200,100",
"D6300,100",
"D6400,110",
"D6510,30" ,
"D7000,100",
"D7100,100"
];
// MELSEC 쿼리는 MAIN타이머(100ms) 마다 n개를 순회하므로
// 쿼리수에 따라 interval 조정
var idx = 0;
var MELSEC_CNT = global.get("MELSEC_CNT1")||0;
global.set("MELSEC_CNT1", ++MELSEC_CNT);
idx = (MELSEC_CNT % msg_melsec.length);
msg.payload = msg_melsec[idx];
return msg;
쿼리로 읽어온 데이터를 global 에 데이터에 넣어 다른 노드/함수 에서 사용할 수 있도록 처리 하는 부분이다.
if(msg.mcReadDetails.error === true)
return null;
var mcpReq = msg.mcReadDetails.request;
var mcp = msg.payload;
var test;
if(mcp === "")
{
var cnt = global.get('MC_ERROR')||0;
global.set('MC_ERROR', ++cnt);
node.status({fill:"red",shape:"dot",text:"error"});
return null;
}
else
{
global.set("ERROR", "");
}
if(mcpReq.address ==="D6000,100")
{
global.set('Memorymap6000', mcp);
}
else if(mcpReq.address ==="D6100,100")
{
global.set('Memorymap6100', mcp);
}
else if(mcpReq.address ==="D6200,100")
{
global.set('Memorymap6200', mcp);
}
else if(mcpReq.address ==="D6300,100")
{
global.set('Memorymap6300', mcp);
}
else if(mcpReq.address ==="D6400,110")
{
global.set('Memorymap6400', mcp);
}
else if(mcpReq.address ==="D6510,30")
{
global.set('Memorymap6510', mcp);
}
else if(mcpReq.address ==="D7000,100")
{
global.set('Memorymap7000', mcp);
}
else if(mcpReq.address ==="D7100,100")
{
global.set('Memorymap7100', mcp);
}
node.status({fill:"green",shape:"dot",text:"good"});
return msg;
반응형
'Java Script' 카테고리의 다른 글
[Node RED] Modbus Protocol JavaScript (0) | 2021.04.22 |
---|---|
[Node RED] JavaScript 부호 비트 연산 (0) | 2021.04.17 |
[Node RED] Node JS 플랫폼 Session Cookie 기반 Login Logout 기능 만들기 (5) | 2021.03.20 |
CSS, JQuery 를 이용한 웹 어플리케이션 적용 (0) | 2021.02.24 |