Read the ground pounds in PB

zhaozj2021-02-16  43

Read the ground pounds in PB

In PB development enterprise applications, we often encounter the processing with the instrumentation interface. Here I summarize the way to read the number of data with the Web scounds.

The general territory is equipped with the following parameters:

Serial number

Serial port parameter

Clock cycle

Reading length

Reading string start bit

Reading string length

First final character marker

First end judgment (whether to read from the first place) '0' is the first

Whether the string is in descent

Code type (1.ascii 2.bcd 3. Others)

Most of the weighs currently used are connected to the computer using the serial port, and the meter sends a data to the serial port in each of its clock cycles. The handler needs to read instrument data in each clock cycle of the device (using Timer in PB. Processing).

There are many serial number methods, and you can read them directly, you can also read it with a third party space, which is not described here. Here mainly describes the analysis processing process of data, corresponding to ASCII coding and BCD encoding, respectively.

ASCII encoded data processing process (relatively simple):

1. Read serial port data (which is generally read is the BLOB type, you need to convert to string types).

2. Intercept the numeric string according to the instrument parameters (read strings start, read strings, first-last character markers).

3. If the instrument parameter indicates that the string of the read string is required to reselect the string of the intercepted string.

4. Display strings.

BCD encoded data processing process (relatively complicated):

Instruments with BCD encoding may be different, specific implementation of technical information to refer to the instrument.

Most of the BCD encoded is a sign bit, one status bit, three BCD digital bits (preceding before), which are previously described.

BCD is a compressed digital storage method, and one is stored for every 4 binary bits.

The BCD code value uses a compressed format, with one byte to store two digits.

The storage method of the value 99bcd code is as follows (as an example of the compression of 99):

Binary representation 1001 1001

ASCII code characters represent 153

Hexadecimal character represents 0x99

The compressed storage is to store data, high 4 bits and low 4 digits of each storage one number.

The binary operation in the PB is inconvenient, so this method uses a method of converting the ASCII value to a 16-en-character to take its two digits.

1. Read serial data (read using blob)

2. Convert BLOB data one by one with a string type to convert to an ASCII encoded string, and each ASCII encoding is divided by a symbol (not a meter using symbol), and a symbol bit is required at the end of the new string.

3. Find the format flag in the string Check if this clock cycle receives the format data, and does not receive the formatted data stop processing Wait for the next clock cycle.

4. The first bit of the general string is the status bit, and the state bit processing is removed.

The value of the status bit is an ASCII code value, and we can take the status information to the ASCII code value to take out status information, the program is as follows:

IF li_state> 128 Then Li_State - = 128 // data overflow

IF li_state> 64 Then Li_State - = 64 // Stable

IF li_state> 32 Then Li_State - = 32 // Symbol

IF li_state> 16 THEN / / Unit: Ton

li_state - = 16

Ls_unit = "t"

END IF

If Li_State> = 8 THEN LI_STATE - = 8 // Weight, LI_STATE is the decimal symbol bit 5. Remove BCD1 processing: Convert the ASCII code value to 16 into two as a number of two digits as a number The value of the number of bits and saves the BCD1 value. (At this point, the two digits and ten)

6. Remove the BCD2 processing: with BCD1. (At this point, the two digits and thousands)

7. Remove the BCD3 processing: with BCD1. (At this time, the two digits and 100,000)

8. Numerical value of three BCD bits after combining conversion: BCD = BCD3 * 10000 BCD2 * 100 BCD1

9. Handling a decimal position: The small digits at this time is stored in the result of the status bit ASCII value calculating. Li_STATE, so as long as the operation: BCD = BCD / 10 ^ li_state.

10. Processing unit conversion, if the unit is tonnaph: BCD = BCD * 10 ^ 3

11. Display meter data.

The above is the most critical part of the data in the area of ​​the area, I hope everyone can more valuable comments.

转载请注明原文地址:https://www.9cbs.com/read-27309.html

New Post(0)