试了一下,是不是这样:
CLEAR
? TRANSFORM(ModBusCRC(0h01),"@0") && 0x7E80
? TRANSFORM(ModBusCRC(0h02),"@0") && 0x3E81
? TRANSFORM(ModBusCRC(0h0103),"@0") && 0x4021
? TRANSFORM(ModBusCRC(0h0105),"@0") && 0xC023
? TRANSFORM(ModBusCRC(0h55FEFE030501),"@0") && 0x26B2
RETURN
FUNCTION ModBusCRC(cStr)
LOCAL i, j, nLen, n16CRC, nRet
nLen = LEN(cStr)
IF (nLen == 0)
RETURN 0
ENDIF
n16CRC = 0x0000FFFF
FOR i=1 TO nLen
n16CRC = BITXOR(n16CRC, ASC(SUBSTR(cStr,i,1)))
FOR j=1 TO 8
IF BITAND(n16CRC,1)==1
n16CRC = BITXOR(BITRSHIFT(n16CRC,1),0xA001)
ELSE
n16CRC = BITRSHIFT(n16CRC,1)
ENDIF
ENDFOR
ENDFOR
nRet = BITLSHIFT(BITAND(n16CRC,0x000000FF),8)
nRet = BITOR(nRet,BITRSHIFT(n16CRC,8))
RETURN nRet
ENDFUNC