background image

 

- 23 - 

      6.7 Sample Computation of CRC-16 
      Below is the sample computation of CRC-16 using Visual Basic 6.0. 
 
Declare the variable as shown below. 
Since the unsigned variable cannot be used in VisualBasic6.0, a signed 16-bit integer variable is used for the data. 
Likewise, the computation result of CRC will be placed in the signed 32-bit integer variable. 
 
Dim CRC As Long 
Dim i, j, arry_count As Integer 
 
Dim c_next, c_carry As LongDim crc_arry(64) As Integer 
 
Next, data to be computed will be placed in crc_arry() while the quantity of data will be placed in arry_count. 
 
After that, the computation result will be placed in CRC by executing the following program: 
 
i = 0 
CRC = 65535 
For i = 0 To arry_count 
    c_next = crc_arry(i) 
    CRC = (CRC Xor c_next) And 65535 
    For j = 0 To 7 
        c_carry = CRC And 1 
        CRC = CRC \ 2 
        If c_carry Then 
            CRC = (CRC Xor &HA001) And 65535 
        End If 
    Next 
Next 
 
If it is to be attached at the end of the message as an error code, attach the lower byte of CRC before the upper byte. 
 

 

 

Summary of Contents for TTM-00BW

Page 1: ...HO ELECTRONICS INC Operation Manual Communication Edition TOHO Protocol MODBUS Model TTM 00BW Name Board Type Digital Controller 久德電子有限公司 台中市西區福人街11號 TEL 04 23729418 FAX 04 23724011 Email sales jetec com tw ...

Page 2: ... Response Delay Time 2 9 Switching of Communication Mode 3 TOHO Communication Control Page 7 3 1 Communication Procedures 3 2 Kinds of Message 3 3 Structure of Request Message Data transmission from upper computer to this product 3 4 Structure of Response Message Data transmission from this product to upper computer 3 5 Explanation about Codes e g List of Errors 3 6 Things to Be Noted during the C...

Page 3: ...ing RTU Communication 6 7 Sample Computation of CRC 16 6 8 Structure of ASCII Request Message Data transmission from upper computer to this product 6 9 Structure of ASCII Response Message Data transmission from this product to upper computer 6 10 Explanation about ASCII Codes e g List of Errors 6 11 Things to Be Noted during ASCII Communication 6 12 Sample Computation of LRC 7 Specifications Page ...

Page 4: ...laced by the previous data data that is saved in the EEPROM if the power is turned OFF and then turned ON To save the written data into the EEPROM of this product execute the save request message See 3 6 6 6 and 6 11 Things to Be Noted during the Communication Furthermore unnecessary setting items such as items that are related to the unattached option will not be read and written 1 4 Position Pri...

Page 5: ...y More than 2 seconds Setting Mode Selection Screen Key Communication Setting Mode MODE Key Setting of Communication Protocol TOHO Communication Protocol Initial Value MODE Key Setting of Communication Parameters MODE Key Setting of Communication Speed MODE Key Communication Address Setting MODE Key Setting of Response Delay Time MODE Key Setting of the Switching of Communication Mode MODE Key Bac...

Page 6: ...S 4800 BPS 9600 BPS 19200 BPS 2 7 Setting of Communication Address Set the value by pressing the keys on the Setting of Communication Address screen in a previous page The initial value is Setting Range 1 99 stations Setting of 0 is not allowed 2 8 Setting of Response Delay Time Set the time to take for the upper computer to complete the receiving of request message open the line and get ready for...

Page 7: ...t returns the response message as a reply to the request message that will be sent by the upper computer Therefore the transmission will never be initiated by this product 3 2 Kinds of Message Kinds of message can be briefly classified into the following All codes up to ETX such as STX and data except for BCC will be expressed in ASCII code To code the program for the upper computer see 9 List of ...

Page 8: ...e 3 5 Explanation about Codes for codes from to See 4 1 Sample Communication for Reading and 4 2 Sample Communication for Writing for concrete samples of the request message 3 3 1 Structure of Read Request Message 3 3 2 Structure of Write Request Message 3 3 3 Structure of Save Request Message ...

Page 9: ...lanation about Codes for codes from to See 4 1 Sample Communication for Reading and 4 2 Sample Communication for Writing for concrete samples of the request message 3 4 1 Response Message for Read Request Message 3 4 2 Response Message for Write Save Request Message 3 4 3 Response Message for the Error ...

Page 10: ... L If the blind setting is to be read from the product B If the blind setting is to be written into the product Identifier It is a classification symbol identifier of the data to be read or written that will be expressed by the 3 digit alphanumeric characters See 9 List of Identifiers Codes Numerical Data It is a data for reading or writing which will be expressed in 5 digit characters regardless ...

Page 11: ...attached next to NAK to the response message that will be returned by this product Since error number 0 indicates the breakdown of measuring equipment memory error or A D conversion error it will be included in the response message whether or not there is an error in the request message Since error number 9 indicates AT error it will be included in the response message whether or not there is an e...

Page 12: ... the reasonable time Once STX is received this product clears all codes that were received prior to the said STX 3 6 5 Number of Digits of Data and Position of Decimal Point See 3 5 Explanation about Codes Numerical Data 3 6 6 Operation After the Receiving of Save Request Message This product starts the saving of data once it receives the save request message correctly from the upper computer Only...

Page 13: ...Read Request Message to be sent by the upper computer S T X 2 7 R B C C P V 1 E T X S T X 2 7 A C K B C C P V 1 E T X 0 0 7 7 7 Code Symbol Data ASCII Code Note 2 Start Code STX 02H Address 27 32H 37H Contents of Request R Read 52H Identifier Note 1 PV1 50H 56H 31H Numerical Data 00777 30H 30H 37H 37H 37H End Code ETX 03H BCC Data Request Response 61H 02H Acknowledgment Code ACK 06H Note 1 See 9 L...

Page 14: ...ata separately to check if the data is written correctly Write Request Message to be sent by the upper computer S T X 0 3 A C K B C C E T X S T X 0 3 W B C C E 1 F E T X 0 0 0 1 1 Code Symbol Data ASCII Code Note 2 Start Code STX 02H Address 03 30H 33H Contents of Request W Write 57H Identifier Note 1 EIF 45H 31H 46H Numerical Data 00011 30H 30H 30H 31H 31H End Code ETX 03H BCC Data Request Respon...

Page 15: ... Setting Mode MODE Key MODE Key Setting of Communication Protocol MODBUS RTU Initial Value Setting of Communication Protocol MODBUS ASCII Initial Value MODE Key MODE Key Setting of Communication Parameters Setting of Communication Param eters MODE Key MODE Key Setting of Communication Speed Setting of Communication Speed MODE Key MODE Key Communication Address Setting Communication Address Setting...

Page 16: ...in a previous page The initial value is Setting Range 1 247 stations Setting of 0 is not allowed 5 8 Setting of Response Delay Time Set the time to take for the upper computer to complete the receiving of request message open the line and get ready for the next input Set the value by pressing the keys on the Setting of Response Delay Time screen in a previous page The initial value is Setting Rang...

Page 17: ...uter Therefore the transmission will never be initiated by this product 6 2 Kinds of Message Kinds of message can be briefly classified into the following Data is in binary during RTU mode In case of ASCII mode all codes will be expressed in ASCII code To code the program for the upper computer see 9 List of Identifiers and 10 List of ASCII Codes at the end of this document ...

Page 18: ...sage Data transmission from upper computer to this product See 6 5 Explanation about RTU Codes for codes from a to i 6 3 1 Structure of Read Request Message 6 3 2 Structure of Write Request Message 6 3 3 Structure of Save Request Message ...

Page 19: ...a transmission from this product to upper computer See 6 5 Explanation about RTU Codes for codes from a to h 6 4 1 Response Message for Read Request Message 6 4 2 Response Message for Write Save Request Message 6 4 3 Response Message for the Error ...

Page 20: ...to 0002H e CRC 16 It is an error checking code for the detection of the possible error in the message It sends CRC 16 Cyclic Redundancy Code Generating polynomial of CRC 16 that is used in this product is X16 X15 X2 1 See 6 7 Sample Computation of CRC 16 for the computation method of CRC 16 If it is to be attached at the end of the message as an error code attach the lower byte of CRC before the u...

Page 21: ...e whether or not there is an error in the request message For multiple errors the largest error number will be included Contents and classification of error are the following Error Number Description of errors in the request message that was received by this product 01 Received an unsupported function code 02 Specified register address has no data 03 Numerical value data is out of the setting rang...

Page 22: ...herefore the upper computer should resend the necessary request message if the response message is not returned within the reasonable time 6 6 5 Number of Digits of Data and Position of Decimal Point See 6 5 Explanation about Codes g Numerical Data 6 6 6 Operation After the Receiving of Save Request Message This product starts the saving of data once it receives the save request message correctly ...

Page 23: ...y_count As Integer Dim c_next c_carry As LongDim crc_arry 64 As Integer Next data to be computed will be placed in crc_arry while the quantity of data will be placed in arry_count After that the computation result will be placed in CRC by executing the following program i 0 CRC 65535 For i 0 To arry_count c_next crc_arry i CRC CRC Xor c_next And 65535 For j 0 To 7 c_carry CRC And 1 CRC CRC 2 If c_...

Page 24: ...sage Data transmission from upper computer to this product See 6 1 Explanation about ASCII Codes for codes from a to g 6 8 1 Structure of Read Request Message 6 8 2 Structure of Write Request Message 6 8 3 Structure of Save Request Message ...

Page 25: ...a transmission from this product to upper computer See 6 1 Explanation about ASCII Codes for codes from a to g 6 9 1 Response Message for Read Request Message 6 9 2 Response Message for Write Save Request Message 6 9 3 Response Message for the Error ...

Page 26: ...Since the number of registers of this product is fixed to 2 set it to 0002H e Register Address It specifies the position of data to be read or written with two bytes See 10 List of Identifiers Codes for the address of each command f LRC It is an error checking code for the detection of the possible error in the message It sends LRC LRC that is used in this product is a value where all data in the ...

Page 27: ...he error number will be included in the response message of this product for the reply Since error number 04 indicates the breakdown of measuring equipment memory error A D conversion error or AT error it will be included in the response message whether or not there is an error in the request message For multiple errors the largest error number will be included Contents and classification of error...

Page 28: ...sary request message if the response message is not returned within the reasonable time 6 11 5 Number of Digits of Data and Position of Decimal Point See 6 10 Explanation about Codes h Numerical Data 6 11 6 Operation After the Receiving of Save Request Message This product starts the saving of data once it receives the save request message correctly from the upper computer Only the data that is di...

Page 29: ...l be placed in the signed 16 bit integer variable Dim LRC As Integer Dim i arry_count As Integer Dim lrc_arry 128 As Integer Next data to be computed will be placed in lrc_arry while the quantity of data will be placed in arry_count After that the computation result will be placed in LRC by executing the following program For i 0 To arry_count LRC LRC lrc_arry i And HFF Next LRC Not LRC 1 And HFF ...

Page 30: ...op Bit Length Select and set from 1 bit and 2 bits Data Length Select and set from 7 bits and 8 bits Parity Select and set from none odd and even BCC Checking Select and set from Yes with and No without Communication Address 1 99 2 MODBUS RTU Communication Protocol Start Bit Length 1 bit fixed Stop Bit Length Select and set from 1 bit and 2 bits With parity 1 bit fixed Data Length 8 bits fixed Par...

Page 31: ...own in the figure Use the cable with the same characteristic impedance for the connection between secondary stations as well Attach the terminator to both the primary station and the farthest secondary station secondary station 3 Choose the terminator of which Characteristic impedance of cables Resistance of Resistance of Also use the cable with characteristic impedance where Resistance of Resista...

Page 32: ...R W R W of Priority Screen Function Setting 4 Example INP Identifier PR5 000Ch 40013 Priority Screen Func tion Setting 5 R W R W of Priority Screen Function Setting 5 Example INP Identifier PR6 000Eh 40015 Priority Screen Func tion Setting 6 R W R W of Priority Screen Function Setting 6 Example INP Identifier PR7 0010h 40017 Priority Screen Func tion Setting 7 R W R W of Priority Screen Function S...

Page 33: ... of MV Limiter C1 0044h 40069 Setting of the Control Sensitivity of Output 1 R W R W of the Setting of the Control Sensitivity of Output 1 CP1 0046h 40071 Setting of the OFF Point of Output 1 R W R W of the Setting of the OFF Point of Output 1 MV2 0048h 40073 Manipulated Variable of Output 2 R W R W of the Manipulated Variable of Output 2 P2 004Ah 40075 Setting of the Propor tional Band of Output ...

Page 34: ...rity CM2 007Eh 40127 CT Input Monitor R R of CT Input Monitor CT2 0080h 40129 Event Output 2 Current Abnormality Setting R W R W of the Setting of Event Output 2 Current Abnormality DIF 0082h 40131 Setting of DI Input Function R W R W of the Setting of DI Input Function DIP 0084h 40133 Setting of DI Polarity R W R W of the Setting of DI Polarity SV2 0086h 40135 Control Setting 2 R W R W of the Set...

Page 35: ... 40169 Timer Start Stop R W R W of Timer Start Stop Start 00001 Stop 00000 OM1 00AAh 40171 Output Status Monitor R R of Output Monitor OUT1 1 ON 0 OFF OUT2 1 ON 0 OFF EV1 1 ON 0 OFF EV2 1 ON 0 OFF EM1 00ACh 40173 DI Status Monitor R R of DI Monitor ON 00001 OFF 00000 AT 00AEh 40175 AT Start Cancel R W R W of AT Start Cancel Start 00001 Cancel 00000 STR 00B0h 40177 Save Data W Save Data Identifier ...

Page 36: ... DC3 3 C S c s 04h EOT DC4 4 D T d t 05h ENQ NAK 5 E U e u 06h ACK SYN 6 F V f v 07h BEL ETB 7 G W g w 08h BS CAN 8 H X h x 09h HT EM 9 I Y i y 0Ah LF SUB J Z j z 0Bh VT ESC K k 0Ch FF FS L l 0Dh CR GS M m 0Eh SO RS N n 0Fh SI US O _ o DEL How to Use the ASCII Code Table ASCII Code Upper Lower Example 1 If A 41h 40h 01h Example 2 If m 6Dh 60h 0Dh ...

Page 37: ... 37 TOHO ELECTRONICS INC 4F 0347 ...

Reviews: