Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Реферат англ.docx
Скачиваний:
3
Добавлен:
01.07.2025
Размер:
224.08 Кб
Скачать

3.3 Structure of the program module for processing the data of electricity meters

The software module being developed should perform the basic functions of reading and processing the meter's energy data. In this regard, a functional model is designed using the UML diagram of use cases (Use Case diagram).

Figure 3.4 shows a diagram of the use cases for the software module being developed. Here is shown one actor: the user of the software product.

Figure 3.4 - Diagram of usage options for the account management module

The user, when working with the program module, can read and view the electricity meter readings, select the connection port settings and save the data to a file. Also, when parameterizing the electricity meter, the user can:

- set the date and time on the device;

- assign or remove the password if necessary;

- enter the identification number of the counter.

3.4 Sequence of execution of the request of the electric power meter data processing module

The diagram of the processing sequence of the request for the data processing module of the electricity meter is shown in Figure 3.5.

Figure 3.5 - The diagram of the query processing sequence

From the figure you can see what sequence of actions you need to take to read the data from the electricity meter. The most important object that will set the necessary commands in the application is the user. Consider the sequence of sending a packet of bytes of data over a serial link to the COM port. The user selects the desired tab of the user application and presses the «Read» button. The program generates the required number of requests, represented as separate packets of data bytes. Next, all the generated data byte packets are sent to the converter, and then the converter sends the converted data packets to the electricity meter for reading the readings. The counter checks all packets for correctness (without loss of data bits in a separate send packet) of transmitted data bytes using the cyclic «CRC» code and generates reply packets of data bytes. The reverse process of transmitting a packet of data bytes from the electricity meter to the end user passes through the same chain.

3.5 Software Implementation

Here is a software implementation of the power meter data processing module. To develop this diploma project, the integrated development environment of Eclipse MARS.1 was used. The software module for processing the energy meter data will allow you to interact with the meter itself via the RS-485 serial port converter by sending and receiving the appropriate number of data byte packets containing information about the parameters that the user wants to receive. To obtain constants, the «sendRequestContstants» class was developed, to which one of the parameters specified in Appendix A is transmitted. The class opens the COM port selected by the user, sets the communication channel parameters, that is, sets the basic parameters of the «UART» protocol. Then it generates packets of sent data. Sets the mask and the list of events that will read the data to the port buffer. Here is the main part of the code of the described class:

serialPort = new SerialPort («COM5»);

serialPort.openPort ();

serialPort.setParams (SerialPort.BAUDRATE_9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,

SerialPort.PARITY_NONE);

serialPort.setEventsMask (SerialPort.MASK_RXCHAR);

serialPort.writeByte (address); // address

serialPort.writeByte (function); // function

serialPort.writeByte (paramCode); // parameter's code

serialPort.writeByte (smeshenie); // smeshenie

serialPort.writeByte (tarif); // tarif

serialPort.writeByte (utochnenie); // utochnenie

serialPort.writeBytes (crcRequest); // CRC

serialPort.addEventListener (new EventListener ());

We pass an instance of the EventListener class to the port where the data reading events will be processed. For the subsequent reading of data packets sent by the device, it is tedious to establish an artificial delay in the program:

try {

Thread.sleep(2400);

} catch (InterruptedException e) {

e.printStackTrace();

}

This artificial delay is necessary, because After the program sends packets of data bytes, the device needs some time to process the received packets and generate a response message. In the most complex queries, the processing time of the counter can be up to 2.3 seconds. Here is the class code of the listener, which will be triggered by the appearance of data in the COM port:

private static class EventListener implements SerialPortEventListener {

public void serialEvent(SerialPortEvent event) {

if (event.isRXCHAR() && event.getEventValue() > 0) {

try {

byte[] rByte = serialPort.readBytes(event.getEventValue());

data[amountBytes++] = rByte[0];

} catch (SerialPortException ex) {

ex.printStackTrace();

}

}

}

}

The class reads one byte each and writes each to the global variable «data» until the data stops coming to the port. In the future, the variable «data» will be processed in accordance with the specified parameter code in Appendix A. Then, information that the user understands will be displayed on the monitor screen.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]