📜 ⬆️ ⬇️

Chinese AIBUS protocol and laboratory chemical reactor

Greetings Habr! Once upon a time I wrote an article about reaction flavors. It took a long time, I returned to this issue.

In this article, I will not go into the details of the development technology of reaction flavors, but I will tell you about my experience in automating my working time and sharing code that can be useful to anyone. I came across a Chinese-made laboratory chemical reactor and, unfortunately, it lacked tools for automating cooling, reading and writing data, programming modes, which was very important. The reactor itself was a usual metal blank on a tripod, with heating elements up to 350 degrees. For temperature control is responsible controller Yudian AI518 .



')
The good news for me was the presence of an RS-485 port in it.

Yes, in Yudian AI518 there are timers and some very simple programs, but first of all, it was very interesting to make your “blackjack” with windows and buttons, and secondly it’s not very convenient to poke at a regular controller, I would like it all do on the computer.

Since I had experience with Arduino controllers, I initially decided to make communication and control through it, then I had an idea to write a program on Qt which would be responsible for management and automation, and Arduino Mega for forming and decrypting packages with AI518.

Since the cold water on valve can be located at a distance from the computer and the installation itself, it was decided to build an additional controller that will, on command, turn on / off the cold water valve and read-send the cooling temperature. Yes, at the end of the project, I realized that a lot of construction was piled up, it would have been possible to use the RS485 whistle on a computer to get rid of one program, but my ambitions to make my own device fueled interest.

Total in our bundle:

  1. Regular controller Yudian AI518.
  2. Arduino Mega + 2 RS485 Converters (MAX485)
  3. Arduino nano + 1 RS485 converter (MAX485) + thermocouple + 12V transistor.
  4. 12V cold water valve.

First of all, the structure of communication between mega and nano was written.

struct packet_arduino_pomp // Arduino nano { byte start_byte_one;//    212 byte start_byte_two;//    211 byte temp_pomp;//  byte on_of_pomp;//on-off  (1  0) byte CRC8;//  /**/ void pask() { CRC8 = (start_byte_one + start_byte_two + temp_pomp + on_of_pomp + tmp) / 10; } /* */ bool test_pask() { if (CRC8 == (start_byte_one + start_byte_two + temp_pomp + on_of_pomp + tmp) / 10) return 0; // return 1; //  } }; 

When everything worked steadily, I began to read a lot about different data transfer protocols, but I could not find the one I needed. The fact is that the regular controller Yudian AI518 communicates with the outside world via the AIBUS protocol, as I understand it is a Chinese analogue of MODBUS. ( documentation ) I did it for the first time and focusing on the documentation and help of all possible forums.

Outgoing packet structure for Yudian AI518:

 struct tagREQ_FRM_T { uint8_t u8DevAddr1; uint8_t u8DevAddr2; uint8_t u8ReqType; uint8_t u8DevPara; uint8_t u8LoParam; uint8_t u8HiParam; uint8_t u8LoSumCheck; uint8_t u8HiSumCheck; } ; 

The structure of the incoming package for Yudian AI518:

 struct tagANS_FRM_T { uint8_t u8LoPV; uint8_t u8HiPV; uint8_t u8LoSV; uint8_t u8HiSV; uint8_t u8MV; uint8_t u8ALm; uint8_t u8LoParam; uint8_t u8HiParam; uint8_t u8LoSumCheck; uint8_t u8HiSumCheck; }; 

In fact, it turned out that packets from all devices come from Mega (from nano with cooling temperature values, from AI518 with updated reactor temperature and other values ​​and commands from the computer). Then Mega combined everything into one package and sent it to the computer where the QT program read it.

The structure of the package mega-computer:

 struct packet_big // PC { byte start_byte_one;//    254 byte start_byte_two;//    232 byte temp_pomp;//  byte on_of_pomp;//on-off  (1  0) byte ex_temp_reactor_one;//    1 byte ex_temp_reactor_two;//    2 byte current_temp_reactor;//    byte timer_ex;// byte tmp;//   byte CRC8;//   void pask() { CRC8 = (start_byte_one + start_byte_two + temp_pomp + on_of_pomp + ex_temp_reactor_one + ex_temp_reactor_two + current_temp_reactor + timer_ex + tmp) / 10; } /* */ bool test_pask() { if (CRC8 == ((start_byte_one + start_byte_two + temp_pomp + on_of_pomp + ex_temp_reactor_one + ex_temp_reactor_two + current_temp_reactor + timer_ex + tmp)) / 10) return 0; // return 1; //  } }; 

Since the Chinese protocol is silent, if the sent packet does not fit the description, selecting the structure, I generally started to think that it was broken, but in the end everything turned out. When I saw the first correct numbers in the log, there was happiness ...

In order to protect the controller on the Arduino nano from moisture, I decided to etch my own board and place it in the case. The matter is not tricky, there are many descriptions of how to do it, but I chose LUT technology. ( LUT ). The hardest part was finding the right glossy inkjet paper on which the laser printer normally prints. But after all the trial and error, it turned out such a device.



But what about the program on the computer, with buttons and windows. The blessing on Qt is very easy to do such things. We are able to form requests and read them from the “bassurman” device, now it is necessary that we can set the modes, build a time-temperature graph, issue a report on the heating rate to the set temperature at the end of the reaction, the reaction time itself, the cooling rate to a certain temperature and etc. By combining all this into a separate structure, via QSerialPort, through the COM port to which Arduinka itself is connected, we transmit and receive values.

The most difficult thing was to compile the finished project under Windows XP. Unfortunately, these systems are at work and I had to dance with a tambourine for a couple of days to make it work. Since I did this for the second day, unconsciously and going through all the proposed options from the forums, I will not post exact instructions.

The result was a program that works and helps me at my workplace and saves a lot of time (I will not post the QT project, as there is nothing interesting there. Data transfer through QSerialPort, and then what the soul desires).

Links to firmware for Arduynok:

→ For Nano
→ For Mega

Source: https://habr.com/ru/post/448212/


All Articles