Upper and lower computer communication method of microbial fermentation online concentration analyzer

文档序号:1683004 发布日期:2020-01-03 浏览:11次 中文

阅读说明:本技术 一种微生物发酵在线浓度分析仪的上下位机通讯方法 (Upper and lower computer communication method of microbial fermentation online concentration analyzer ) 是由 李俊 伍倩倩 薄翠梅 于 2019-09-27 设计创作,主要内容包括:本发明公开了一种微生物发酵在线浓度分析仪的上下位机通讯方法。微生物发酵在线浓度分析仪包括:上位机MCGS、下位机STM32主控系统和检测系统。上、下位机之间进行指令传输和数据传输,采用了带有CRC校验的自定义通信协议。对上、下位机分别进行通讯设置和协议设计,上位机通过串口设置和调用库函数,下位机通过keil软件编写协议函数以实现通讯。根据整个检测流程,设计一种通讯协议格式,微生物发酵在线浓度分析仪的具体通信指令分为上位机、下位机主控系统和检测系统三部分,按照地址位判别接收指令的具体模块,按照功能码的不同执行不同的操作。通过上下位机的准确、稳定通讯,实现在线采样和在线检测组分浓度。(The invention discloses a communication method of an upper computer and a lower computer of a microbial fermentation online concentration analyzer. The online concentration analyzer of microbial fermentation includes: host computer MCGS, lower computer STM32 major control system and detecting system. The upper computer and the lower computer transmit instructions and data, and a user-defined communication protocol with CRC is adopted. The upper computer and the lower computer are respectively subjected to communication setting and protocol design, the upper computer sets and calls library functions through a serial port, and the lower computer compiles protocol functions through keil software to realize communication. According to the whole detection process, a communication protocol format is designed, a specific communication instruction of the microbial fermentation online concentration analyzer is divided into an upper computer, a lower computer main control system and a detection system, a specific module for receiving the instruction is distinguished according to address bits, and different operations are executed according to different function codes. The online sampling and the online detection of the component concentration are realized through the accurate and stable communication of the upper computer and the lower computer.)

1. A communication method of an upper computer and a lower computer of a microbial fermentation online concentration analyzer is characterized in that: the microbial fermentation online concentration analyzer system consists of the following units:

(1) the upper computer MCGS is used for controlling the whole process of the detection of the microbial fermentation online concentration analyzer, displaying a data curve, feeding back information and storing data;

(2) the lower computer STM32 main control system and the lower computer STM32 main control system are mainly responsible for controlling the whole instrument flow path, controlled objects comprise hardware equipment for realizing sampling operation such as mechanical arms, valves, pumps, motors and the like, and receive instructions of the upper computer MCGS for cleaning, sampling and other operations;

(3) and the lower computer detection system collects current response signals of the biological sensing electrodes mainly through Prussian blue biological sensing electrodes, finishes the calibration of the sample, returns concentration information, and performs the operations of detection, switching on and switching off a stirring motor and the like when receiving the instruction of the upper computer MCGS.

2. The communication method of the upper computer and the lower computer of the microbial fermentation online concentration analyzer according to claim 1, wherein the communication setting and protocol design are carried out in a main control system and a detection system of the lower computer STM32, functions are written in keil software according to the flow and the protocol of the detection system, and three subprograms of mcheck.c, mport.c and protocol.c and corresponding subprograms are mainly designed, and h header files are from defining protocols and are respectively used for realizing port configuration, bottom layer transceiving, verification algorithms and communication protocols.

3. The communication method of the upper computer and the lower computer of the microbial fermentation online concentration analyzer according to claim 1, wherein the communication is realized in configuration software of the upper computer MCGS through serial port setting and library function calling; and sending frames byte by byte to a serial port 2buffer by using a library function in a script program, receiving data from a serial port buffer area by using the library function, taking out each bit of received data by using a character string processing function after receiving the data, splicing into frames, and taking out the data from corresponding positions according to a communication protocol.

4. The upper and lower computer communication method of the microbial fermentation online concentration analyzer according to claim 1, characterized in that: the self-defined communication protocol format is that the address bit + the function code + the data length + the data bit + the check bit, except that the CRC check code and the data bit occupy 2 bytes, other Bits all occupy 1 byte, and the length is 8 Bits; the specific communication instruction is divided into an upper computer MCGS, a lower computer STM32 main control system and a lower computer detection system, the address bit of the upper computer is represented as 01, the address bit of the main control system is 02, the address bit of the detection system is 03, the specific instruction receiving module is judged according to the address bit, and different operations are executed according to different function codes.

5. The upper and lower computer communication method of the microbial fermentation online concentration analyzer according to claim 1, characterized in that: the communication software program flow of the upper computer and the lower computer comprises the following steps:

(1) receiving an instruction from a serial port;

(2) judging whether the address code is the local address, if so, carrying out the next step, and if not, directly ending;

(3) judging whether the CRC is correct or not, if so, carrying out the next step, and if not, directly ending;

(4) reading a function code from the received instruction;

(5) performing task processing;

(6) sending a corresponding response instruction; the transmission of one instruction ends here.

Technical Field

The invention relates to the technical field of communication and electrical control, in particular to a design of upper and lower computer communication of a microbial fermentation online concentration analyzer.

Background

During fermentation, the microorganisms are able to metabolically synthesize or convert the starting materials (sugars) into the desired products in an orderly manner. Scientific research shows that: the types and concentrations of substrates and products, as well as the interactions, all have a significant impact on the reaction rate, product yield and the selection of metabolic pathways by cells during microbial fermentation. The real-time monitoring of the concentration of the key components is very important for improving the fermentation production efficiency. By monitoring the concentration of key components (substrate, intermediate metabolite and product) on line, the physiological state of cells is identified in real time, the growth and metabolism rules and stage characteristics of the cells are revealed, and the real-time regulation and control of the microbial fermentation process are guided.

The common communication modes in the industrial control field are RS485 and RS232, the two interface standards are different regulations on electrical characteristics and physical characteristics, and the data transmission modes are different. And RS485 adopts differential communication, so that interference in the communication process can be avoided to the greatest extent. The online analyzer is a huge interference source, has a large number of magnetic components and high-speed changing signal quantity, and adopts differential communication to ensure the reliability of communication.

The upper computer used in the invention is MCGS (micro computer controlled system), wherein the MCGS is a product of the Beijing Kunlun general state automation software science and technology limited company, comprises MCGS configuration software and an MCGS display screen, is used for quickly constructing and generating an upper computer monitoring system, and mainly completes the acquisition of field data, the processing of front-end data and the output control of equipment. The communication interface of the MCGGS is RS485, and the configuration software has flexible script commands and can develop a self-defined communication protocol to communicate with a lower computer.

With the development of fermentation engineering, the requirements on the real-time performance, integrity and reliability of information are increasingly raised. Most of the existing component concentration analysis instruments in the current market adopt offline sampling and dilution and need manual sampling, so that the detection period is greatly prolonged, detection data cannot reflect the component concentration change (such as substrate, key intermediate metabolite and product) in the current fermentation system in time, and the wide application of the fermentation process control technology based on concentration feedback is greatly limited. Therefore, the accurate communication of the upper computer and the lower computer has important significance for realizing online sampling and online detection of the component concentration.

Disclosure of Invention

The invention aims to solve the problems of long detection period and unreliable data caused by untimely communication in the detection process of a microbial fermentation online concentration analyzer, adopts an RS485 communication mode and a self-defined communication protocol, and provides a communication design of an upper computer and a lower computer of the microbial fermentation online concentration analyzer.

The technical scheme adopted by the invention is as follows: the communication design of the upper computer and the lower computer of the microbial fermentation online concentration analyzer comprises communication setting and protocol design of an upper computer MCGS (micro-grid-System), a lower computer STM32 master control system and a detection system, and software program flow design of communication.

The STM32 main control system is mainly responsible for controlling the whole instrument flow path, and the controlled object comprises hardware equipment for realizing sampling operation, such as a mechanical arm, a valve, a pump, a motor and the like. And compiling functions in the keil software according to the flow and the protocol of the detection system, and carrying out cleaning, sampling and other operations when receiving the instruction of the upper computer MCGS.

The detection system collects current response signals of the biosensing electrode mainly through the Prussian blue biosensing electrode, finishes the calibration of the sample and returns concentration information. And compiling functions in the keil software according to the flow and the protocol of the detection system, and detecting, closing the stirring motor and the like when receiving the instruction of the upper computer MCGS.

And the upper computer MCGS is used for controlling the whole process of the detection of the microbial fermentation online concentration analyzer, displaying a data curve and feedback information and storing the data curve and the feedback information. The configuration software has flexible script commands and can be developed to communicate with the lower computer through a self-defined communication protocol.

The MCGS upper computer is communicated with the STM32 main control system and the detection system through RS485, and in order to ensure the accuracy and the confidentiality of data transmission, the system adopts a user-defined communication protocol with CRC check. The CRC is called Cyclic Redundancy Check, which means Cyclic Redundancy Check, and is a commonly used data checking method for removing signal fluctuation and interference.

The communication protocol format of an upper computer and a lower computer in the microbial fermentation online concentration analyzer system is as follows: address bits + function codes + data length + data bits + check bits. Except for CRC check code, data bits occupy 2 bytes, and other bits all occupy 1 byte, and are expressed by 16-ary system. The specific communication instruction of the analyzer is divided into three parts, namely an upper computer, a main control system and a detection system, wherein the address bit of the upper computer is represented as 01, the address bit of the main control system is represented as 02, the address bit of the detection system is represented as 03, a specific instruction receiving module is judged according to the address bit, and different operations are executed according to different function codes.

The software program flow of the communication between the upper computer and the lower computer comprises the following steps:

(1) receiving an instruction from a serial port;

(2) judging whether the address code is the local address, if so, carrying out the next step, and if not, directly ending;

(3) judging whether the CRC is correct or not, if so, carrying out the next step, and if not, directly ending;

(4) reading a function code from the received instruction;

(5) performing task processing;

(6) and sending a corresponding response instruction. The transmission of one instruction ends here.

The invention has the beneficial effects that: the online microbial fermentation concentration analyzer realizes real-time task allocation and cooperative control of an STM32 main control system and a detection system through accurate and stable communication of an upper computer and a lower computer, can solve the problem of online detection of substrate and product concentration in the fermentation process, and greatly improves the overall efficiency of the fermentation process.

Drawings

FIG. 1 is a general functional block diagram of an online concentration analyzer system for microbial fermentation according to the present invention

FIG. 2 is a flow chart of the software program of the present invention

FIG. 3 is a flow chart of the upper computer communication instruction of the present invention

Detailed Description

The communication setting of the upper computer and the lower computer and the specific instruction flow of the whole system are explained in detail below.

Step 1: and the upper computer is in communication setting and comprises data sending and data receiving.

Data transmission in the MCGS is realized by serial port setting and library function calling: calculating the value of CRC check code in advance for the required instruction, and using | according to the sequence that CRCLow precedes CRCHigh follows! The WriteSerial () library function sends the frame byte by byte to Serial2 (485 port of MCGS) Buffer Serial2 Buffer. The specific protocol is as follows: | A Write external (2, 2)' Address bits! Write Material (2, 1)' function code! Write Material (2, 0)' data bits! Write Material (2, 0)' data bits! writeMaterial (2, CRCLOw)' check bits high byte! writeMaterial (2, CRCHigh)' check the bit low byte.

Data reception in the MCGS is realized by serial port setting, strategy and calling library functions: countInBuffer! GetSerialReadBufferSize (2) TempStr ═ Str0 ═ I ═ 1 While I < ═ CountInBufferTempNumber! ReadSerial (2) Str 0! When the data length of the serial buffer is not zero, namely the data is received by the serial buffer, the serial buffer enters an interrupt, each bit of data received is taken out by using a character string processing function, and framing and splicing are carried out. And taking out data from the corresponding position according to the communication protocol.

Step 2: and (5) communication design and function compiling in the lower computer. The three subprograms of mcheck.c, mport.c and protocol.c and the corresponding h-header files are mainly designed to realize communication by defining a protocol.

Port configuration and bottom layer transceiving are realized in the mport file; macro in mport.h header file defines RS _ TX _ EN as PGout (8), and configures IO port PG8 as output mode; EN _ USART2_ RX is defined as 1, and the lower computer is set to the reception state by default. And a serial port 2 interrupt service function USART2_ IRQHandler, an interface initialization function mp _ init and a serial port data sending function mp _ send _ data are realized in mport.c. An interrupt service function USART2_ IRQHandler in the mport.c uses USART _ GetITStatus (USART2, USART _ IT _ RXNE) to judge whether the serial port 2 is not empty; if the serial port data is read by using USART _ ReceivedData (USART2) in non-empty, the data received by the register USART2- > DR; judging whether m _ ctrl _ dev.frameok is equal to 0 or not, if yes, receiving is not finished, and storing data in a USART2- > DR serial port 2 data register byte by using an array m _ ctrl _ dev.rxbuf [ m _ ctrl _ dev.rxlen ]; and if the LENGTH M _ ctrl _ dev.rxlen of the receiving FRAME is greater than the maximum FRAME LENGTH M _ MAX _ FRAME _ LENGTH-1, the receiving data is wrong, and the receiving is restarted.

Configuring a GPIO and a clock in an interface initialization function mp _ init: enable GPIOA clock, USART2 clock, GPIOA clock; multiplexing GPIOA2 and GPIOA3 as USART2 serial port mapping; configuring GPIOA2 and GPIOA3 pins, wherein the mode is a multiplexing function, the speed is 100MHz, the output type is push-pull multiplexing output, pull-up and initialization; configuring GPIOG8 for 485 mode control, wherein the mode is output function, speed is 100MHz, the output type is push-pull multiplexing output, pull-up and initialization; configuring a serial port: initializing USART2, setting the baud rate to 9600, the word length of 8bits, the stop bit of 1 bit, no parity bit, no hardware data flow control, the serial port mode to be the receiving and sending mode, initializing, enabling the serial port 2, clearing the flag bit of the serial port 2 for completing sending, and starting the serial port 2 to receive interrupt and idle interrupt; configuring a serial port 2, requesting an interrupt to preempt a priority 3, configuring a sub-priority 3, enabling the interrupt request, and initializing an NVIC (embedded vector interrupt register); RS485_ TX _ EN is 0 and starts the reception mode by default.

The serial data transmitting function mp _ send _ data sets a 485 port as a transmitting mode RS485_ TX _ EN to be 1, a USART _ SendData transmitting function is used for writing values into a serial data register in sequence until the data length is equal to the set value, the USART _ GetFlagtStatus is used for judging whether a transmitting completion FLAG bit USART _ FLAG _ TC is 1 or not in the transmitting process, and the 485 port is set as an accepting mode RS485_ TX _ EN to be 0 after one frame of data is transmitted.

(2) The CRC16 check algorithm is implemented in mcheck.c. The upper byte table CRC16HiTable and the lower byte table CRC16LoTable are defined. Using mc _ check _ crc16 check value calculation function, index, check value calculation result check16, preset register low eight bits crc _ low, preset register high eight bits crc _ high are defined. For each byte in the frame to be checked, XOR is carried out between the eighth bit of the preset register and the byte to be calculated to obtain an index; searching corresponding data in the high-order byte table by using the index position, and carrying out exclusive OR on the corresponding data and the high-order eight bits of the preset register to update the low-order eight bits of the preset register according to the exclusive OR; and searching corresponding data in the low-order byte table by using the index position, and updating the high eight bits of the preset register. The result of the CRC16 check is a preset register obtained after all bytes are processed.

(3) The protocol implements the specific definition of the communication protocol. Macro definitions and structures are used in protocol. The definition returns an error enumeration type m _ result, MR _ OK ═ 0 communication is normal, MR _ FRAME _ FORMAT _ ERR ═ 1 FRAME FORMAT error, MR _ FRAME _ CHECK _ ERR ═ 2 CHECK value error, and MR _ MEMORY _ ERR ═ 3 MEMORY error.

Defining a structure type m _ frame _ typedef of a ModBus frame format, address bits, function codes, datalength address length, data bits and chkval check values. Defining a type m _ protocol _ dev _ typedef of a ModBus protocol manager structure, receiving a cache region by rxbuf, receiving the length of data by rxlen, and marking the frame data receiving completion of a frame. Defining m _ ctrl _ dev of a ModBus controller m _ protocol _ dev _ typedef type, parsing a frame data function mb _ unpack _ frame (m _ frame _ typedef fx), a packed send function mb _ packed _ frame (m _ frame _ typedef fx), a ModBus initialization function mb _ init (void), and a ModBus release function mb _ destroy (void).

protocol.c implements the function defined in the header file. mb _ unpack _ frame unpacking function: judging the length of the received frame, and clearing the rxlen and frameok marks of the received data length when the length of the received frame exceeds the range so as to facilitate the next normal reception and return a frame format error; for a frame with correct length, calculating a check value calchkval by using an mc _ check _ crc16 check value calculation function, taking out the check value rxchkval attached to the received frame, clearing the rxlen and frameok marks of the received data length so as to receive the data for the next time, judging whether the calchkval and the rxchkval are the same, checking whether the data in an m _ ctrl _ dev.rxbuf [ ] array is normally stored in an m _ frame _ typedef type structure fx memory space, and sequentially storing bytes with different meanings such as start bits, address bits, function codes and the like in different variables in the structure.

mb _ packetsend _ frame packing transmission function: initializing a sendbuffer and a packed frame length, giving different variables in a memory space of a structure fx of an m _ frame _ typedef type to a sendbuffer array sendbuffer [ ], calculating a corresponding check value calchkval by using mc _ check _ crc16(), converting the calchkval into a 16-system form, and giving a high byte to a corresponding position in the sendbuffer [ ] after the high byte is in a first low byte. And transmitting the filled one frame data by using an mp _ send _ data frame transmitting function.

mb _ init () initializes the ModBus protocol manager function and initializes the members in the m _ ctrl _ dev structure, including m _ ctrl _ dev. And clearing the m _ ctrl _ dev structure by the mb _ destroy function, and releasing the memory.

And step 3: the specific communication instruction of the analyzer is divided into three parts, namely an upper computer, a main control system and a detection system, wherein the address bit of the upper computer is represented as 01, the address bit of the main control system is 02, and the address bit of the detection system is 03. The communication control flow of the whole system is as follows.

(1) The method comprises the steps that firstly, an upper computer sends a reset and cleaning instruction 0201020000 FD FC to an STM32 main control system, and after cleaning is finished, an end instruction 0101020000B 9 FC is returned to the upper computer to carry out next step indication.

(2) And the upper computer receives the instruction and then sends an instruction 0301020000C 03C of a detection zero AD to the detection system, and the AD value of the buffer solution with the concentration of zero is collected and defined as ADV 0.

(3) The detection system returns to the upper computer to send an instruction 010702 xx xx xx + CRC with an ADV0 value, the upper computer analyzes and stores the data, then the upper computer sends a calibration instruction 0203020000 FC 44 to the main control system, the standard solution is injected into the detection pool, and after the calibration for the first time is finished, the upper computer sends an acquisition AD instruction 0302020000C 078 to the detection system.

(4) The detection system returns a first calibration value 010802 xx xx xx + CRC, which is defined as ADV1, the upper computer analyzes and stores the data, and then the upper computer requests to turn off the stirring motor 0303020000C 184.

(5) After the stirring motor is successfully closed, the upper computer sends a cleaning and scaling instruction 0204020000 FD 30 to the main control system, standard liquid is injected again for calibration, and the upper computer receives a second scaling finishing instruction and sends an acquisition AD instruction 0302020000C 078.

(6) The detection system returns a second scaled value 010802 xx xx + CRC, we define ADV2, and the upper computer then requests that the agitator motor 0303020000C 184 be turned off.

(7) Analyzing by an upper computer: since the concentration value and the AD response value have a linear relationship in a certain range, a corresponding functional relationship between the concentration value and the AD response value can be obtained by using the AD value ADV0 corresponding to the zero concentration and the standard solution concentration ADV1 corresponding to the zero concentration. And the step of acquiring the AD value for the second time is to repeat the last operation, carry out a second test on the standard solution to obtain the AD value ADV2, then calculate a second concentration value through a functional relation formula according to the AD value acquired for the second time, and indicate that the calibration is passed if the deviation of the concentration values of the two times is less than 2%.

(8) If the calibration is successful, the concentration detection of the sample can be carried out, the upper computer sends 0206020000 FC 88 to the main control system for cleaning and sampling, and after the sampling is finished, the upper computer sends 0302020000C 078 to collect the AD value of the liquid to be detected. And calibrating the obtained function relation, and adding the AD of the liquid to be detected to obtain the concentration of the liquid to be detected from the relation. And finally, the upper computer sends a cleaning and finishing command 0205020000 FC CC to finish the detection process.

(9) And (4) if the second calibration is failed, namely the concentration difference of the two times is larger than 2%, re-collecting the data for calibration, and returning to the step (1) to send a reset instruction 0201020000 FD FC by the upper computer.

9页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种大肠杆菌快速测试盒

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!