亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? udbldmsg.c

?? 工業組態軟件modbus驅動源代碼, 包括幫助文件.共享.
?? C
?? 第 1 頁 / 共 3 頁
字號:
    /* starting address, number of items to read */
    ptr = put_bin_word (ptr, addr1);   len+=2;
    ptr = put_bin_word (ptr, (BYTE) numRd);  len+=2;

    /* get length, allowing for checksum */
    // len = (WORD) ((unsigned long)(ptr - (LPSTR) msg) + 1);

    /* checksum */
	// 2/29/2000 modify by Chen jun
	cks = CRC16((LPSTR)msg,len);           // Checksum
    //cks = BldCks ((LPSTR) &msg[0], len-1, &errflg);
    *ptr++ =  cks%256; len += 1;
    *ptr++ =  cks/256; len += 1;

    /* return the address and the length of the message built */
    *plpMsg = (LPSTR) msg;
    if (Verbose)
        ShowBldMsg ((LPSTR) &msg[0], len);
    return (len);
} 
/* BldRead */


/***********************************************************************/
/** build message to write data to a point in the PLC,
    return length of message **/

/************************************************************************\
  Note: The last four arguments to this routine are protocol-dependent.
  Modify them as required.
\************************************************************************/

WORD
WINAPI
BldWrite(BYTE	   plcAddr,	   /* 2/28/2000 Modify by Chen jun local PLC address */
		 LPSTR    *plpMsg,     /* pointer to where the message is stored */
         BYTE FAR *pData,      /* pointer to data values to be sent */
         BYTE      plcDataType,/* type of device data to generate */
         BYTE      DDEType,    /* type of data to transfer */
         WORD      addr1,      /* address of point(s) to be accessed */
         WORD      numWrt)     /* number of items to write */
{
    LPSTR  ptr;
    BYTE   msgCmd;
    WORD   len;
    WORD   cks;
    WORD   i;
	int    b;
    int    errflg;

    len = 0;

     /* determine message command */
	// 3/1/2000 modify by chen jun
    //msgCmd = (BYTE) (plcDataType | 0x80);
     switch (plcDataType){
		case ITEM_HOLDING_COIL: 
			msgCmd = 15;
			break;
		case ITEM_HOLDING_REG: 
		    msgCmd = 16;
			break;
	}
    /* initialize message buffer pointer */
    ptr = (LPSTR) msg;

    /* message type */
    //ptr = put_bin_byte (ptr, msgCmd);
	ptr = put_bin_byte (ptr, plcAddr);	len+=1;
	ptr = put_bin_byte (ptr, msgCmd);   len+=1;
    /* starting address, number of items to write */
    ptr = put_bin_word (ptr, addr1);			len+=2;
	/* number of byte to write */
	b =  numWrt;
	if(plcDataType == ITEM_HOLDING_COIL)
	{	
			 ptr = put_bin_word (ptr, (WORD) numWrt);	len+=2;
			 ptr = put_bin_byte (ptr, (BYTE)(b/8+1));	len+=1;
			/* data for each item */
			 for( i=0; i<(numWrt/8+1); i++ ) {
				ptr = put_bin_byte (ptr, (BYTE) (*(INTG FAR *)pData));
				pData += 1;
				len += 1;
			}
	}
	else{
		ptr = put_bin_word (ptr, (WORD) numWrt);	len+=2;
		ptr = put_bin_byte (ptr, (BYTE)(b*2));	len+=1;
           /* data for each item */
        for( i=0; i<numWrt; i++ ) {
			ptr = put_bin_word (ptr, (WORD) (*(INTG FAR *)pData));
			pData += 2;
			len += 2;
		}
	}
    /* get length, allowing for checksum */
    //len = (WORD) ((unsigned long)(ptr - (LPSTR) msg) + 1);

    /* checksum */
    //cks = BldCks ((LPSTR) &msg[0], len-1, &errflg);
   // ptr = put_bin_byte (ptr, cks);
 
	cks = CRC16((LPSTR)msg,len);
    //cks = BldCks ((LPSTR) &msg[0], len-1, &errflg);
    *ptr++ =  cks%256; len += 1;
    *ptr++ =  cks/256; len += 1;
 
	//Modify end

    /* return the address and the length of the message built */
    *plpMsg = (LPSTR) msg;
    if (Verbose)
        ShowBldMsg ((LPSTR) &msg[0], len);
    return (len);
} /* BldWrite */


/***********************************************************************/
/* display built message for tracing purposes */

static
VOID
WINAPI
ShowBldMsg (LPSTR lpStr, WORD len)
{
    BYTE FAR *rd;
    int i, n, L;
    int max_str, max_msg;

    /* get message length and pointer */
    n = (int) len;
    rd = (BYTE FAR *) lpStr;

    /* get number of characters that can be stored in display string */
    max_str = DBG_BUF_SIZE - 1;

    /* format message for display */
    sprintf (dbgBuf, "BldMsg (%d) -- ", n);

    /****************************************************************\
        Format the rest of the message and append it to dbgBuf.
        Depending on the protocol, it may be appropriate to
        convert bytes to hex ASCII, or simply copy an ASCII string.
    \****************************************************************/

    L = strlen (dbgBuf);
    if (n == 0) {
        sprintf (&dbgBuf[L], "<nothing>");
    } else {
        if (bBldSendMsgInBinary) {
            /* convert characters to hex ASCII */
            max_msg = (max_str - L) / 2;
            if (n > max_msg)
                /* make sure message doesn't overflow buffer */
                n = max_msg;
            if (n > 0) {
                for (i = 1; i <= n; i++) {
                    sprintf (&dbgBuf[L], "%02X", *(rd++));
                    L += strlen (&dbgBuf[L]);
                }
            }
        } else {
            /* take characters just as they are */
            max_msg = max_str - L;
            if (n > max_msg)
                /* make sure message doesn't overflow buffer */
                n = max_msg;
            f_lstrncpy (&dbgBuf[L], (LPSTR) rd, n);
            dbgBuf[L+n] = '\0';
        }
    }

    /* output display string to logger */
    debug (dbgBuf);
} /* ShowBldMsg */

/***********************************************************************/
/** verify that the command header format is valid,
    return the expected total length of the message **/

BOOL
WINAPI
IsHeaderValid (LPSTR lpStr, int len, int *total_len)
{
    /*******************************************************************\
        The contents of this routine are protocol dependent.

        This routine is called at the point when we have received
        enough bytes to pick the length out of the message header.
        Validate the message header and calculate the total length
        of the message.  Then return the new expected length.

        The example code below assumes a header of the form
            :BBAAAANN
        where response to a write will be of the form
            :BBAAAANNXX;
        and the response to a read will be of the form
            :BBAAAANN[CCCC]....[CCCC]XX;
        where BB   is a  command in hex ASCII
              AAAA is an address in hex ASCII
              NN   is a  number of words in hex ASCII
              CCCC is a  word value in hex ASCII
              XX   is a  checksum in hex ASCII
        Alternatively, an error message may be received, which will
        have one of the following forms:
            :000000000000FF;
        for a garbled message
            :00BBAAAANN00XX;
        for an invalid command BB
            :00BBAAAANNDDXX;
        for an invalid number of "cells" to read or write
        So by the ninth character, we know how many are coming.
    \*******************************************************************/

    int    num_words, errflg;
    BYTE   cmd;
    BOOL   valid;

    /* initialize return status, length */
    valid = TRUE;
    *total_len = len;

    /* check start of message */
    if (lpStr[0] != ':')
        valid = FALSE;

    /* get command */
    if (valid) {
        cmd = (BYTE) GetHexVal (lpStr+1, 2, &errflg);
        if (errflg)
            valid = FALSE;
    }

    /* check for error message */
    if (valid) {
        if (cmd == 0x00) {
            /* error message, set up for response length */
            *total_len = 16;
        } else {
            /* get number of words handled by message */
            num_words = (int) GetHexVal (lpStr+7, 2, &errflg);
            if (errflg) {
                valid = FALSE;
            } else {
                /* check whether read or write */
                if ((cmd & 0x80) != 0) {
                    /* command is a write, response is fixed length */
                    *total_len = 12;
                } else {
                    /* command is a read, response is based on count */
                    *total_len = 12 + num_words * 4;
                }
            }
        }
    }

    /* indicate whether message header is valid */
    return (valid);
} /* IsHeaderValid */

/***********************************************************************/
/** verify that the command format is valid **/

BOOL
WINAPI
IsCommandValid (LPSTR lpStr, int len)
{
    /*******************************************************************\
       The contents of this routine are protocol dependent.

       The following example assumes that the received message is in
       the format
            :AABBCCDDEE...ZZ;
       where AA, BB, ..., ZZ are pairs of hexadecimal digits,
       and ZZ is the checksum for the message.
    \*******************************************************************/

    int cks, byteval, err1, err2;
    BOOL ok;

    /* initialize return value */
    ok = TRUE;

    /* check length of command */
    if ((len < 6) || ((len & 0x01) != 0)) {
        /* too short, or odd number of bytes */
        ok = FALSE;
    } else {
        /* check beginning, ending characters */
        if ((lpStr[0] != ':') || (lpStr[len-1] != ';')) {
            /* invalid delimiters */
            ok = FALSE;
        } else {
            /* calculate checksum */
            cks = BldCks (lpStr+1, len-4, &err1);
            /* compare to checksum in message */
            byteval = (int) GetHexVal (lpStr+(len-3), 2, &err2);
            if (err1 || err2 || (cks != byteval))
                /* invalid characters or mismatched checksum */
                ok = FALSE;
        }
    }
    /* indicate success or failure */
    return (ok);
} /* IsCommandValid */

/***********************************************************************/
/** convert indicated message to binary,
    return TRUE if resulting string is valid binary data **/

BOOL
WINAPI
GetMsgAsBinary (LPSTR lpStr, int *len)
{
    /*******************************************************************\
       The contents of this routine are protocol dependent.

       The following example assumes that the received message is in
       the format
            :AABBCCDDEE...ZZ;
       where AA, BB, ..., ZZ are pairs of hexadecimal digits,
       and ZZ is the checksum for the message.
       The checksum, leading ':' and trailing ';' characters are ignored.
    \*******************************************************************/

    BYTE FAR *rsp;
    LPSTR     cp;
    int       i;
    BOOL      valid, ok;

    /* initialize return value */
    valid = TRUE;

    /* convert string from ASCII to binary */
    rsp = (BYTE FAR *) lpStr;            /* pointer to binary string  */
    cp  = lpStr + 1;                     /* pointer to ASCII string   */
    i   = *len;                          /* length of ASCII string    */
    if (i >= 4)                          /* check length              */
        i = i - 4;                       /* drop head, tail, checksum */
    else i = 0;
    i = i / 2;                           /* length of the response    */
    *len = i;                            /* return length of binary   */
    while (i--) {                        /* for each ASCII pair       */
        *(rsp++) = ah_to_bin (cp, &ok);  /*  convert it and save byte */
        valid = (valid && ok);           /*  identify if non-hex char */
        cp += 2;                         /*  point to next ASCII pair */
    }

    /* indicate whether binary message is valid */
    return (valid);
} /* GetMsgAsBinary */

/***********************************************************************/
/** determine size of block needed for message to read data
    returns size for a new block of data
    and size for extending an existing block of data **/

/************************************************************************\
  Note: The last four arguments to this routine are protocol-dependent.
  Modify them as required.
\************************************************************************/

VOID
WINAPI
GetBldMsgReadBlockSizes (WORD *blockSize,
                         WORD *extSize,
                         BYTE msgType,
                         BYTE plcDataType,
                         WORD addr1,
                         WORD count)
{
    WORD len;
    WORD bytesToWrite;

    /* determine length of data */
    bytesToWrite = (WORD) (count * 2);

    /* length of characters needed to specify data */
    len = 0;

    /* return length of data extension */
    *extSize = len;

    /** allow for type, address prefix, length count:  TT AAAA NN **/
    len += 8;

    /** allow for leading ':', checksum XX, and trailing ';' */
    len += 4;

    /* return length of block */
    *blockSize = len;
} /* GetBldMsgReadBlockSizes */

/***********************************************************************/
/** determine size of block needed for message to write data
    returns size for a new block of data
    and size for extending an existing block of data **/

/************************************************************************\
  Note: The last four arguments to this routine are protocol-dependent.
  Modify them as required.
\************************************************************************/

VOID
WINAPI
GetBldMsgWriteBlockSizes (WORD *blockSize,
                          WORD *extSize,
                          BYTE msgType,
                          BYTE plcDataType,
                          WORD addr1,
                          WORD count)
{
    WORD len;
    WORD bytesToWrite;

    /* determine length of data */
    bytesToWrite = (WORD) (count * 2);

    /* length of characters needed to specify data */
    len = (WORD) (bytesToWrite * 2);

    /* return length of data extension */
    *extSize = len;

    /** allow for type, address prefix, length count:  TT AAAA NN **/
    len += 8;

    /** allow for leading ':', checksum XX, and trailing ';' */
    len += 4;

    /* return length of block */
    *blockSize = len;
} /* GetBldMsgWriteBlockSizes */

#else
/* >>>>>>>> USE_ASCII_HEX_MESSAGES not defined <<<<<<<< */
/***********************************************************************/
/** calculate checksum of message **/

/*************************************************************\
    The content of this routine is protocol dependent.
    Modify it as required.
\*************************************************************/

BYTE
WINAPI
BldCks(LPSTR       lpBuf,     /* pointer to buffer containing message */
       int         len,       /* length of message */
       int        *errflg)    /* nonzero if invalid characters */
{
    int cks, byteval;
    char ch;

    /* initialize checksum, error flag */
    cks = 0;
    *errflg = 0;

    /************************************************\
        include byte lpBuf[i] in the checksum
        Example:
    \************************************************/

    /* get byte values */
    while (len > 0) {
        /* get byte from message buffer */
        ch = *(lpBuf++); len--;
        byteval = (int) ((BYTE) ch);
        /* update checksum */
        cks = (cks + byteval) & 0xFF;
    }

    /* invert checksum and return it */
    cks = 0xFF - cks;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品人人做人人爽人人添| 毛片不卡一区二区| 男人操女人的视频在线观看欧美| 国产精品99久| 欧美一区二区三区免费在线看 | 一区二区久久久久久| 久久se精品一区二区| 欧美日韩在线播| 中文字幕乱码一区二区免费| 日本最新不卡在线| 在线欧美日韩精品| 日韩一区中文字幕| 国产在线视视频有精品| 9191国产精品| 午夜电影一区二区| 日本精品视频一区二区三区| 国产精品久久久久影视| 国产在线国偷精品免费看| 欧美理论片在线| 一区二区三区免费看视频| 99精品黄色片免费大全| 欧美激情一区三区| 福利一区在线观看| 久久嫩草精品久久久精品一| 六月婷婷色综合| 欧美一区午夜视频在线观看 | 中文字幕中文字幕一区二区| 国产精品夜夜嗨| 久久精品亚洲国产奇米99| 麻豆精品精品国产自在97香蕉| 欧美日韩国产乱码电影| 夜夜嗨av一区二区三区网页 | 亚洲黄色免费网站| 91亚洲国产成人精品一区二三 | 国产欧美精品一区二区色综合朱莉| 美女视频黄频大全不卡视频在线播放| 666欧美在线视频| 日韩经典中文字幕一区| 日韩亚洲电影在线| 麻豆国产一区二区| 久久精品视频在线免费观看| 国产suv一区二区三区88区| 国产婷婷色一区二区三区四区| 国产一区二区0| 日本一区二区不卡视频| 成人国产精品免费观看| 亚洲免费在线播放| 欧美性色黄大片| 蜜乳av一区二区三区| 久久亚洲综合色一区二区三区 | 欧美日韩在线直播| 亚洲成人中文在线| 9191精品国产综合久久久久久 | 91官网在线观看| 日韩综合一区二区| 久久久精品国产99久久精品芒果| 高清免费成人av| 亚洲精品一卡二卡| 日韩一卡二卡三卡| 国产精品一区在线观看你懂的| 国产欧美一区二区在线观看| 色www精品视频在线观看| 婷婷六月综合亚洲| 久久精品视频在线看| 欧美在线你懂得| 极品销魂美女一区二区三区| 国产精品国模大尺度视频| 精品视频一区二区不卡| 国产精品 日产精品 欧美精品| 一区二区三区欧美日韩| 欧美成人vps| 色婷婷激情综合| 国产综合久久久久久鬼色| 亚洲伦理在线精品| 日韩午夜激情av| 91亚洲国产成人精品一区二区三| 免费一级欧美片在线观看| 国产精品久久久久久久久搜平片 | 蜜臀av性久久久久av蜜臀妖精 | 久久久久久久国产精品影院| 在线观看区一区二| 国产福利视频一区二区三区| 亚洲一区电影777| 国产欧美一区二区三区网站| 欧美日韩不卡一区二区| 99视频在线精品| 激情综合色丁香一区二区| 一区二区久久久久久| 亚洲国产精华液网站w | 蜜桃视频在线一区| 亚洲午夜久久久久久久久电影院| 国产午夜亚洲精品理论片色戒| 日本高清无吗v一区| 国产成人av电影在线播放| 青青草一区二区三区| 亚洲午夜久久久久久久久电影网| 欧美激情中文字幕| 久久香蕉国产线看观看99| 欧美二区乱c少妇| 色天天综合色天天久久| 99视频一区二区| 粉嫩13p一区二区三区| 精品制服美女久久| 免费精品视频在线| 五月天激情综合| 亚洲激情在线激情| 中文字幕制服丝袜一区二区三区| 国产亚洲精品bt天堂精选| 日韩一级大片在线| 在线不卡的av| 欧美情侣在线播放| 91麻豆精品国产91久久久久久| 欧美唯美清纯偷拍| 欧美精品日日鲁夜夜添| 717成人午夜免费福利电影| 欧美猛男超大videosgay| 91精品福利视频| 欧美色区777第一页| 91精品1区2区| 欧美高清精品3d| 日韩一二三四区| 欧美电视剧免费观看| 久久一日本道色综合| 国产欧美日韩另类视频免费观看| 国产精品久久久久久久久晋中| 国产精品青草久久| 亚洲综合在线免费观看| 亚洲成人三级小说| 精东粉嫩av免费一区二区三区| 国产成人午夜99999| 成人av中文字幕| 一本久久精品一区二区| 国产一区福利在线| 国产自产视频一区二区三区| 成人动漫视频在线| 99精品一区二区三区| 国产无一区二区| 欧美又粗又大又爽| 91麻豆精品国产91久久久久久 | 中文一区二区在线观看| 久久亚洲一级片| 欧美一区二视频| 久久久三级国产网站| 日韩精品一区二区三区中文不卡| 日韩色在线观看| 欧美mv和日韩mv的网站| 国产精品欧美久久久久一区二区 | 麻豆专区一区二区三区四区五区| 日日摸夜夜添夜夜添精品视频 | 亚洲欧美综合在线精品| 国产精品免费视频观看| 午夜av一区二区三区| 日本成人在线看| 激情久久久久久久久久久久久久久久| 国产一区美女在线| www.99精品| 欧美日韩一级黄| 日韩精品一区二区在线| 欧美激情在线一区二区| 精品卡一卡二卡三卡四在线| 国产精品区一区二区三| 亚洲高清视频在线| 久久99久久精品| 色哟哟精品一区| 国产三级精品视频| 一区二区三区自拍| 紧缚奴在线一区二区三区| 成人影视亚洲图片在线| 日韩午夜电影av| 亚洲美女在线一区| 美女一区二区久久| 成人a区在线观看| 日韩三级视频在线看| 国产精品超碰97尤物18| 麻豆成人综合网| 91激情五月电影| 欧美一区二区高清| 亚洲免费av观看| 国产**成人网毛片九色| 7777精品伊人久久久大香线蕉的 | 国产欧美精品一区| 日韩国产高清在线| 99久久精品国产麻豆演员表| 欧美另类高清zo欧美| 国产精品欧美一区二区三区| 蓝色福利精品导航| 欧美日韩精品一区二区在线播放| 国产欧美日本一区二区三区| 日韩高清在线观看| 国产99精品视频| 久久理论电影网| 日韩国产精品久久久久久亚洲| 99riav一区二区三区| 欧美激情在线看| 久久99国产乱子伦精品免费| 欧美日韩一区视频| 亚洲图片欧美激情| 国产精品99久| 久久先锋影音av鲁色资源| 婷婷一区二区三区|