rs485通信基础知识-九游会登录
add date: 2019-7-6 views: 4852
1. 485 communication
1.1. communication connection
1.1.1. interface definition:
intelligent digital display instruments generally adopt rs485 communication interface mode, generally three terminals: a , b-, com. as shown in figure 1:
when there are multiple 485 communication devices on one bus, the connection should be hand-in-hand. the maximum recommended number of devices on a bus is no more than 32 devices. figure 2
figure 1: 485 communication wiring method
figure 2: 485 bus connection for multiple devices
1.1.2. communication interface and converter
since the instrument adopts the rs485 communication interface, the common plc, touch screen, etc. all have this interface. however, this interface is generally not available on computers. when communicating with a computer, interface conversion is required. common devices include: usb to rs485 converter, rs232 to rs485 converter, ethernet to rs485 serial server, communication management machine, etc. figure 3:
figure 3: common serial converter
1.2. communication settings
1.2.1. protocol: the instrument supports the standard modbus-rtu serial communication protocol; refer to relevant national standards: gb/t 19582.1-2008, gb/t 19582.2-2008;
1.2.2. the data transmission format is: 1 bit start bit, 8 data bits, 1 stop bit, no parity bit.
1.2.3. general setting of the instrument factory default: add address: 1, baud rate: 9600, crc check: n
1.2.4. data byte order: h-l (high first, low last)
1.2.5. data format: integer (32-bit long integer, 16-bit short), 32-bit floating-point float. according to different series of instruments.
1.3. register address
1.3.1. the register address in our company's manual, also called variable address or address mapping table, is represented by hexadecimal address code. for example, 0x2000 means hexadecimal address 2000. 32-bit data occupies 2 register positions (4 words) section), 16-bit data occupies 1 register position (2 bytes). the 32-bit data address indicates the register position occupied by each parameter with addresses such as 0, 2, 4, 6, ...; 16-bit data is represented by addresses 0, 1, 2, 3, ... the register location occupied by each parameter.
as shown in figure 4 below:
figure 4: parameter list of sensor table and power meter
1.3.2. when the computer reads the data, it reads the corresponding data from the above variable address. when the computer communicates with the instrument, the upper computer directly accesses the data in hexadecimal data; however, most industrial control configuration software, monitoring system software, plc, touch screen, etc. need to be converted to decimal address code for reading.
as shown in figure 5, figure 6, and figure 7, read the phase a voltage value starting from 0x4000, you need to convert 0x4000 to decimal number to get 16384, then use 400001 16384=416385
figure 5: register address setting during configuration king serial device test
figure 6: kunlun open state touch screen device channel acquisition settings
figure 7: siemens s7-200smart plc read command settings
1.4.1. the meter is generally sent with hexadecimal data. after the host computer receives the data, it needs to perform data conversion processing. the commonly used ones are generally long, short, and floating. long long integer data is 32 bits, occupying 2 registers, 4 bytes; short short integer data is 16 bits, occupies 1 register, 2 bytes; float floating point type is 32 bits of data, occupying 2 registers and 4 bytes .
1.4.2. when the upper computer processes the data, it needs to be converted according to the actual data type of the product. the following table is an example:
1.4.3. plc storage area data description
let the read data be stored in the v memory area starting with vb100, then for different types of data such as long\short\float, it should be converted according to the type defined by plc:
1.5. display processing
1.5.1. after the integer data is converted to decimal, the decimal point needs to be processed. the magnification conversion of the decimal point can be performed according to the manual. generally, the integer of the converted decimal number is multiplied by the number of decimal places. such as:
2. brief introduction of modbus-rtu communication protocol
2.1. introduction
the modbus protocol is a standard protocol for the industrial control industry. it is divided into two protocols, one is the modbus-rtu serial protocol and the other is the modbus-tcp network port protocol.
the modbus protocol was developed for modicon and was later acquired by schneider and is now a standard protocol for schneider. the modbus protocol has been widely used in industrial control and has become a common industry standard that supports rs-232, rs-422, rs-485 and ethernet devices. the control devices produced by different manufacturers can be connected to the communication network through the modbus protocol for centralized monitoring. many industrial products, such as plc, inverters, human-machine interfaces, dcs, and automated smart meters, are widely used in the modbus protocol.
according to the type of transmission network, it is divided into modbus on serial link and modbus based on tcp/ip protocol.
the modbus serial link protocol is a master-slave protocol. in the request-response mode, the master station sends a request message with a slave address, and the slave station with the address sends a response message to respond.
in the modbus protocol, there is only one master station in an rs-485 serial bus, which can have 1 to 247 slave stations. modbus communication can only be initiated by the primary station. when the secondary station does not receive a request from the primary station, it will not send data and the secondary stations will not communicate with each other.
2.2. modbus message transmission mode---rtu mode
the rtu mode message on the modbus network is transmitted in bytes, and one byte consists of two hexadecimal numbers. each byte transmitted contains a start bit, 8 data bits (send the lowest valid bit first), the parity bit, the stop bit are the same as the ascii mode, and the message length is up to 256 bytes.
the last two bytes of the modbus rtu mode message are the cyclic redundancy check code (crc). the verification method is to shift all the bytes (excluding the last two bytes) of the entire message in a prescribed manner and perform xor (exclusive or) calculation. the receiver calculates the same way in the same way, and compares the result with the received cyclic redundancy check code. if it is consistent, the communication is considered correct. if it is inconsistent, the communication is considered incorrect. a crc error response will be sent.
in modbus, rtu uses the redundancy check mode of crc-16.
2.3.modbus function code
2.4. communication message example