Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define BYTE unsigned char
- #define WORD unsigned int
- #define DWORD unsigned long
- #define STX1 0x55 //Header1
- #define STX2 0xAA //Header2
- #define SB_OEM_PKT_SIZE 12
- #define SB_OEM_CHK_SUM_SIZE 2
- enum {CMD_OPEN = 0x01}
- typedef struct {
- BYTE Head1;
- BYTE Head2;
- WORD wDevId;
- DWORD nParam;
- WORD wCmd;// or nAck
- WORD wChkSum;
- } SB_OEM_PKT;
- WORD CalcChkSumOfCmdAckPkt( SB_OEM_PKT* pPkt ){
- WORD wChkSum = 0;
- BYTE* pBuf = (BYTE*)pPkt;
- int i;
- for(i=0;i<(sizeof(SB_OEM_PKT)-SB_OEM_CHK_SUM_SIZE);i++){
- wChkSum += pBuf[i];
- }
- return wChkSum;
- }
- void SendCmdOrAck(WORD wDevID, WORD wCmdOrAck, DWORD nParam) {
- SB_OEM_PKT pkt;
- int nSentBytes;
- pkt.Head1 = (BYTE)STX1;
- pkt.Head2 = (BYTE)STX2;
- pkt.wDevId = wDevID;
- pkt.wCmd = wCmdOrAck;
- pkt.nParam = nParam;
- pkt.wChkSum = CalcChkSumOfCmdAckPkt( &pkt );
- nSentBytes = gtmSerial->write( (BYTE*)&pkt,SB_OEM_PKT_SIZE);
- }
- WORD gwDevID = 1;
- int main(){
- SendCmdOrAck(gwDevID, CMD_OPEN, 1);
- return 0;
- }
- ser.write(pack('<BBILII', 0x55,0xAA,0x0001,1,1,258))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement