앉아있는 프래그래머

C# RS232-시리얼통신 코드 2 - 프로토콜(2) ALT-8RSD 본문

프로그래밍/C#,ALT-8RSD-12V - RS232 시리얼 통신

C# RS232-시리얼통신 코드 2 - 프로토콜(2) ALT-8RSD

맛있는 단무지! 2018. 7. 18. 15:26

ALT-RSD의 경우에는 프로토콜이 2가지 이다. 하나는 앞에서 말한 내용이고 다른 하나는 밑에 내용이다.


참고로 이번 프로토콜은 앞에 내용과는 다르게 10진수를 굳이 16진수로 바꿔줄 필요는 없다.


Start  ,  Command ,   Ch1   Ch2    Ch3    Ch4   Ch5 ~~~ Ch(8) , Check Sum , End

2byte ,     1byte    ,  1byte  1byte  1byte  1byte  1byte~~~ 1byte  ,      1byte    , 2byte


start ->  0xef , 0xef  2byte로 구성

Command -> 0x00   1byte로  구성

ch1          -> 100  = 0x64

ch2          -> 100  = 0x64

ch3          -> 100  = 0x64

ch4          -> 100  = 0x64

...................................

ch(8)        -> 100  = 0x64

Check Sum-> ch1^ch2^ch3^ch4^ch5^ch6^ch7^(ch8+0x01) 결과.

End           -> 0xee, 0xee 2byte로 구성

//=====================================================================================

사용예시

                byte[] temp = new temp[14]; 

             

                temp[0] = 0xef;
                temp[1] = 0xef;
                temp[2] = 0x00;

                temp[3] = 100;
                temp[4] = 100;
                temp[5] = 100;
                temp[6] = 100;
                temp[7] = 100;
                temp[8] = 100;
                temp[9] = 100;
                temp[10] = 100;

                int test = temp[2] ^ temp[3] ^ temp[4] ^ temp[5] ^ temp[6] ^ temp[7] ^ temp[8] ^ temp[9] ^ (temp[10] + 0x01);

                temp[11] = (byte)test;
                temp[12] = 0xee;
                temp[13] = 0xee;


                //채널에 전부 100을 입력


                port.Write(temp,0,14);    //temp배열에 14개를 읽는다. 

                                                  //만약에 14가 아닌 12라든지 다른 수를 적게 되면 프로토콜 에러로 작동이 안된다.

 

 

Comments