문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 다음 판 | 이전 판 | ||
cublocapp:an61004:index [2017/10/19 23:18] Comfile Technology |
cublocapp:an61004:index [2017/10/19 23:19] (현재) Comfile Technology |
||
---|---|---|---|
줄 1: | 줄 1: | ||
+ | ====== AN61004 - HMI와 큐블록 연결해서 온도센서 값 읽어오기 ====== | ||
+ | ComfileHMI 에서 MSB630TA-DC 에 연결된 온도센서(NTC 서미스터)를 읽어와 HMI 에 표시하는 샘플 프로젝트입니다. | ||
+ | |||
+ | [[http://www.comfile.co.kr/download/hmi/hmi_msb_mlntc2.zip|프로젝트 파일 과 큐블록 소스 다운로드]] | ||
+ | |||
+ | {{ :cublocapp:an61004:hmitemp.png?nolink |}} | ||
+ | |||
+ | {{ :cublocapp:an61004:20170201_153648.jpg?nolink |}} | ||
+ | |||
+ | <html><center> | ||
+ | <iframe width="560" height="315" src="https://www.youtube.com/embed/g8WhURhSjk4" frameborder="0" allowfullscreen></iframe> | ||
+ | </center></html> | ||
+ | |||
+ | ===== 큐블록 MSB 소스 프로그램 ===== | ||
+ | |||
+ | <code xbasic> | ||
+ | '================================================= | ||
+ | ' | ||
+ | ' MSB rs485 CH3 으로 ML-NTC2 온도변환모듈 연결후 HMI에 온도값 표시 | ||
+ | ' | ||
+ | '================================================= | ||
+ | |||
+ | ' 큐블록 제품에 rs485포트가 있는 제품은 ML-NTC2 바로연결 가능하며, rs232만 있다면 컨버터 사용하여 연결해야함. | ||
+ | |||
+ | #include "msb6xx" | ||
+ | ' ======= HMI 통신을 위한 채널 오픈 | ||
+ | Opencom 1,115200,3,100,100 ' 채널1을 115200,8,none,1stopbit로 오픈 | ||
+ | Set Modbus 1,1,100 ' 모드버스 RTU 시작, 슬레이브 어드레스는 1, 수신응답은 100 (약 10mS) | ||
+ | Usepin 8,In ' 레더에서 사용될 입출력 포트설정 | ||
+ | Usepin 9,In | ||
+ | Usepin 10,In | ||
+ | Usepin 11,In | ||
+ | Usepin 12,In | ||
+ | Usepin 13,In | ||
+ | Usepin 14,In | ||
+ | Usepin 15,In | ||
+ | Usepin 16,In | ||
+ | Usepin 17,In | ||
+ | Usepin 18,In | ||
+ | Usepin 19,In | ||
+ | Usepin 20,In | ||
+ | Usepin 21,In | ||
+ | Usepin 22,In | ||
+ | Usepin 23,In | ||
+ | Usepin 20,In | ||
+ | Usepin 32,Out | ||
+ | Usepin 33,Out | ||
+ | Usepin 34,Out | ||
+ | Usepin 35,Out | ||
+ | Usepin 36,Out | ||
+ | Usepin 37,Out | ||
+ | Usepin 38,Out | ||
+ | Usepin 39,Out | ||
+ | Usepin 40,Out | ||
+ | Usepin 41,Out | ||
+ | Usepin 42,Out | ||
+ | Usepin 43,Out | ||
+ | Usepin 44,Out | ||
+ | Usepin 45,Out | ||
+ | Set Ladder On ' 레더시작 | ||
+ | |||
+ | Dim K As Byte ' 변수 선언 | ||
+ | Dim txb(10) As Byte | ||
+ | Dim c As Integer | ||
+ | Dim data(10) As Byte | ||
+ | Dim data1 As Long | ||
+ | |||
+ | On Recv3 Gosub RCV_RTN ' ch3 수신 인터럽트, 데이터가 들어오면 RCV_RTN | ||
+ | Ramclear | ||
+ | |||
+ | Do | ||
+ | MLNTC_TX 1,0,2 ' *슬레이브어드레스 (ID설정), *시작어드레스(Start address)채널0은 0, 채널1은 1, *읽어올 채널수 1, 또는 2 | ||
+ | Delay 100 ' 100ms 주기 | ||
+ | Loop | ||
+ | | ||
+ | RCV_RTN: '수신 데이터 값 | ||
+ | If Blen(3,0) > 0 Then '버퍼에 데이터 수신시 | ||
+ | data(K)=Get(3,1) '수신된 패킷중 9바이트 data()배열 변수에 저장 | ||
+ | Incr K | ||
+ | '==수신값 디버그창에서 확인 == | ||
+ | 'Debug Dec data(0),Cr 'slave address 수신된패킷내용은 온도모듈 설명서 참조 | ||
+ | 'Debug Dec data(1),Cr 'function | ||
+ | 'Debug Dec data(2),Cr 'byte count | ||
+ | 'Debug Dec data(3),Cr 'data(high) | ||
+ | 'Debug Dec data(4),Cr 'data(low) | ||
+ | 'Debug Hex data(5),Cr 'data(high) | ||
+ | 'Debug Hex data(6),Cr 'data(low) | ||
+ | 'Debug Hex data(7),Cr 'crc | ||
+ | 'Debug Hex data(8),Cr 'crc | ||
+ | '============================== | ||
+ | data1.BYTE3 =data(3) '온도값만 변수에 저장 | ||
+ | data1.BYTE2 =data(4) | ||
+ | data1.BYTE1 =data(5) | ||
+ | data1.BYTE0 =data(6) | ||
+ | _d(0)=data1.Word0 'CH0 온도값 D0 저장 | ||
+ | _d(1)=data1.Word1 'CH1 온도값 D1 저장 | ||
+ | 'Debug Dec data1.Word1,Cr | ||
+ | Endif | ||
+ | If K=9 Then '9바이트 수신시 수신버퍼 clear | ||
+ | K=0 | ||
+ | Bclr 3,0 | ||
+ | Endif | ||
+ | Return | ||
+ | |||
+ | Sub MLNTC_TX( _slavead As Byte,_startad As Byte, _lench As Integer ) '송신 데이터 전송 값 | ||
+ | txb(0)= _slavead | ||
+ | txb(1)= 3 | ||
+ | txb(2)=_startad.Byte1 | ||
+ | txb(3)=_startad.Byte0 | ||
+ | txb(4)=_lench.Byte1 | ||
+ | txb(5)=_lench.Byte0 | ||
+ | Getcrc c,txb,6 ' ┐ | ||
+ | txb(6)=c.Byte1 ' │ 자동 계산하여 넣은 CRC값 | ||
+ | txb(7)=c.Byte0 ' ┘ | ||
+ | Puta 3,txb,8 '배열에 저장됐던 데이터값 송신 | ||
+ | End Sub | ||
+ | |||
+ | </code> | ||
+ | |||
+ | [[cublocapp:index|한단계 뒤로]] |