COM (ComponentObjectModel) component technology is a specification for constructing binary compatible software, through which components can be built to transfer data to each other, and its server-client structure is very suitable for the development of industrial software applications. Because the industrial control software not only includes the hmi (human-machine interface) program on the PC, but also includes the program for data exchange with various data acquisition cards based on ISA or PCI bus, the hardware level requirements of these programs are relatively high. Moreover, the development is difficult, and the HMI program is independent of each other, so the industrial control software can be divided into two parts, that is, the HMI program is used as a client-side program, and the program for data exchange with the hardware is used as a server-side program. Based on this idea, this paper applies the server-client structure to the configuration software of the fieldbus control system, focusing on the functions and implementation of the client and server. First, the composition of the fieldbus control system is introduced.
1 system composition
The fieldbus control system is mainly composed of PC, ISA or PCI bus smart adapter, intelligent measurement and control module, configuration software, HMI software, COM server, user software and so on.
The transmission of all information in the fieldbus system is two-way. The COM server is between the smart adapter and the host software, and is responsible for the data transmission. The host computer software is equivalent to the client-side application software. It uses the interface provided by the COM server to operate the adapter, initialize the adapter, and write and read data to specific units.
Since the memory cannot be accessed directly in Windows protected mode, it is necessary to write a VxD driver to convert the physical address into a linear address, and then COM can call the VxD function like a DLL to complete the operation of the ISA or PCI bus smart adapter.
The bottom-down data transmission from the measurement and control module to the upper computer software completes the user's monitoring of the measurement and control module; while the upper layer software sends the data to the adapter through the COM, and then the adapter sends it to the measurement and control module to realize the user's working parameters of the measurement and control module. The management of the settings and working status. Figure 1 shows the block diagram of the system software structure.
2 configuration software features
The fieldbus control system configuration software is a set of software based on Windows98 and Windows2000 platform (or higher) for rapid construction and generation of the host computer monitoring system. It provides data acquisition, data processing, remote control, and alarm. Complete solution for practical engineering problems such as processing and report output. It uses the interface provided by the COM server to exchange data with the adapter, which is a program on the COM client side.
3COM component technology
A component is a piece of software that performs a certain function, can be used by other programs, and is easy to replace. In order for each person to write components that are portable, a standard must be established to ensure compatibility and interchangeability. COM is such a standard that, following COM rules, it is possible to build components that can exchange data with each other.
In the fieldbus control system, the COM component server is responsible for the data transmission between the host computer software and the smart adapter such as the configuration software. Because the adapter is connected to the measurement and control module through the CAN field bus, the operation of the adapter is the monitoring and control of the module. .
The interfaces provided by the COM server include functions such as adapter initialization, module checking, sending data to the module, and reading module data. The following focuses on the data transmission and reception mode and how to write these four representative functions.
3.1 adapter initialization function
Other operations can only be performed after the adapter has been successfully initialized. Since the adapter cannot be directly accessed in the Windows protected mode, the COM program needs to call the VxD program to convert the corresponding physical address into a linear address pointer lpBaseAddress, so that the operation of the adapter is converted into an operation on the array with the pointer as the first address. Write the upper node number and the communication baud rate between the adapter and the module and the command word 0xC6 (indicating the adapter initialization) specified by the adapter program to the 0x3F0, 0x3F1, and 0x3F8 units of this array, wait for tens of ms, if the adapter Receiving the above data and reacting appropriately, it will clear the 0x3F8 unit, which means that the initialization of the adapter is successful; if the unit is not zero, the initialization fails.
3.2 data transmission format
Once the adapter is successfully initialized, it can exchange data with it. Let's briefly explain the format of sending data and receiving data.
The linear address pointer lpBaseAddress obtained by the adapter initialization stores the host node number, the module node number, the reserved word, the length of the transmitted or received byte, and the command word of the module operation. lpBaseAddress[6]~lpBaseAddress[256] stores the data to be sent; the received data is stored from the lpBaseAddress[0x106] unit, lpBaseAddress[0x3F8] stores the command word of the operation adapter, and the adapter processes the content according to the unit. If it is 0xC6 , the adapter and the CAN controller on the module are initialized; if it is 0xC7, the number in the array is sent to the E2PROM on the module. After receiving the data, the module processes the data according to the command word of lpBaseAddress[5]; if it is 0xB0, Then, according to the received data, the working state of the module is configured; if it is 0xA5, the measured value at this time is sent to the adapter and read by the COM program.
3.3 module check function
After the adapter is successfully initialized, it is also necessary to check whether the adapter is connected to the following measurement and control module, or whether there is a module to be configured by the configuration software, that is, to perform a module check operation. The command word of the module check is 0xAD, and the upper node number, module node number, reserved word, transmission data length and module check command word 0xAD are written to the 1-5 units of the array, and 0xC7 is written to the 0x3F8 unit (indicating to the adapter) Write data), after waiting for several tens of ms, if the 0x3F8 unit is cleared and the 0x100 unit is set to 0xAA, it means that the module exists and can communicate; otherwise, it indicates that the module does not exist or there is a problem on the hardware.
3.4 write adapter data function
Once you have identified which communicable modules are in your network, you can send data to them and configure them. In order to send data to the adapter, a total of 4 functions, SendData([in]BYTESendBuf[256]), SendFinish([in]BOOLbFinish), FinishQuery([out]BOOL*bFinish), and ReceiveResult([out]BOOL*) were written. bSendFinish). SendData is responsible for putting the data that a module needs to send into an array of two dimensional arrays (Room[64][256]) in the form of an array. The data of each module is treated as a row. After sending data to the adapter, it is necessary to wait for a period of time to judge whether the module receives success. Therefore, SendFinish starts the auxiliary thread to send data and wait for the result. This phase does not occupy the time of the COM main program, so that the client can return immediately after calling the interface function. Perform other operations. FinishQuery queries if the data transmission is over. ReceiveResult pops up a non-modal dialog that shows which modules receive data and which do not.
3.5 read adapter data function
In addition to sending data to the adapter, you can also read the data from the module from the adapter. The command word for reading data is 0xA5. The function that implements this task is GetPV([in]BYTEbDesNode,[out]floatvalue[8]), the first parameter is the module node number, and the second parameter is the returned array of measured values.
Here, COM is a local server written in ATL, and the thread of a COM object is an inter-suite thread. The interface defines six functions, and the COM program flow chart is shown in Figure 2. #p#分页头#e#
The function declaration of the COM object interface and the procedure for initializing the adapter are as follows:
COM interface definition:
interfaceINCardWork: IDispatch
{
[id(1), helpstring("Adapter initialization function, return value is successful")]
HRESULTNcardInit([in]BYTE
bSrcNode,[in]BYTEbIntrAdd,[in]BYTEbRate,[in]longbSegmantAdd,[out]BOOL*flag);
[id(2), helpstring("Assign the array passed by the client to Room[][]")]
HRESULTSendData[in]BYTESendBuf[256]);
[id(3), helpstring("Start multithreading")]
HRESULTSendFinish([in]BOOLbFinish);
[id(4), helpstring("The return value of this function indicates whether the data has been sent to the lower computer, and it can be displayed which modules are not configured. Usually, the query is sent with FinishQuery([out]BOOL*bFinish) before this function. Whether it is finished")]
HRESULTReceiveResult([out]BOOL*bSendFinish);
[id(5)], helpstring("The return value of this function indicates whether the data has been sent to the lower machine, "true" means the transmission is completed")]
HRESULTFinishQuery([out]BOOL*bFinish);
[id(6), helpstring("Network check, used to detect if the node exists before sending data")]
HRESULTNetCheck[in]BYTEsour,[in]BYTEdes,[in]BYTEtype,[out]BOOL*flag);
[id(7), helpstring("Read module's measured value")]
HRESULTGetPV([iv]BYTEbDesNode,[out]floatvalue[256]);
}
Adapter initialization function:
#include
#include"winioctl.h"
/ / Contain other header files
......
STDMETHODIMPCNCardWork::NcardInit(BYTEbSrcNode, BYTEbIntrAdd, BYTEbRate, longbSegmentAdd, BOOL*flag)
{
NcardCtrlcardctrl; / / NcardCtrl class function call VxD function
exbSrcNode=bSrcNode;//Assign the host computer node
exbRate=bRate;//The communication baud rate of the lower computer and the adapter
BOOLtransfersign; / / initialization success flag
DWORDdwSegmentaddress=bSegmentAdd;//Adapter segment address
HANDLEhDevice=NULL; / / point to a linear pointer to the handle
LpBaseAddress=(PBYTE)cardctrl.MapLinearAddress(dwSegmentaddress,0x400,hDevice);
/ / Call the VxD function to get a linear address pointer to the physical address of the ISA bus
Cardctrl, UnMapLinearAddress(lpBaseAddress, hDevice);
/ / Close VxD
/ / Call the adapter initialization function
_outp (0x310, 0x01); / / open the mailbox lock
lpBaseAddress[0x3F0]=bSrcNodeNumber;//upper computer node number
lpBaseAddress[0x3F1]=bRate;//baud rate
lpBaseAddress[0x3F8]=0xC6;//Adapter initialization command word
DrvDelay (20, false); / / delay 20ms
............//Other operations after initialization
_outp (0x310, 00); / / close the mailbox lock
returnS_OK;
}
4 virtual device driver
VxD is an abbreviation of Virtual Device Driver (VirtualDeviceDriver), and the middle x represents a device. It has unlimited access to all hardware devices, freely detects operating system data structures (such as descriptors and page tables), and accesses any memory location.
In this paper, VxD converts the physical address corresponding to the ISA bus into a segment linear address, which is used by the application. The VxD development tool is VtoolsD, and the function used for conversion is MapPhysToLinear. The following is part of the program code:
/ / Define the structure
typedefstruct_MapDevRequest
{
PVOIDmdr_PhysicalAddress; DWORDmdr_SizeInBytes;
PVOIDmdr_LinearAddress; WORDmdr_Status;
}MAPDEVREQUEST,*PMAPDEVREQUEST;
#include
/ / Contain other header files
............
PARAMSpDIOCParams
{
PMAPDEVREQUESTpRea; / / their own defined structure
Switch(pDIOCParams->dioc_IOCtlCode)
{
caseDIOC_OPEN:
caseDIOC_CLOSEHANDLE:break;
caseMDR_SERVICE_MAP:
pReq=*(PMAPDEVREQUEST*)pDIOCParams->dioc_InBuf;
pReq->mdr_LinearAddress=MapPhysToLinear
(pReq->mdr_PhysicalAddress, pReq->mdr_SizeInBytes,0);
If(pReq->mdr_LinearAddress==NULL)
pReq->mdr_Status=MDR_STATUS_ERROR;
Else
pReq->mdr_Status=MDR_STATUS_SUCCESS;
Break;
caseMDR_SERVICE_UNMAP:break;
Default:
returnERROR_INVALID_FUNCTION;
}
returnDEVIOCTL_NOERROR;
}
The use of COM component technology in the fieldbus control system not only makes the function of the data transfer part independent of the client program, but also makes it difficult to develop, and it can be directly called by any program that supports binary code such as Excel spreadsheet. The code is easier to maintain when the server and client modes are used in the system. Even if you want to upgrade the server-side program, as long as the interface is unchanged, its client program does not need to be modified at all, and a lot of follow-up work is alleviated. Like the server side, the client side only needs to care about the interface of the server, regardless of how it implements data exchange. That is to say, the function of one end of the COM server or client changes, as long as the interface remains unchanged, the other end can work without modification. The technology described in this paper has been successfully applied in practical projects such as a water injection station in Shengli Oilfield.
- [Worldwide Compatibility]With a worldwide 100-240V AC input, it's a truly global charger and perfect for international traveling. Compatible with iOS, Android, & Windows smart phones as well as tablets, speakers, cameras, and other 5V USB devices
-
With 9 years experience in the filed, Shenzhen WAWEIS Technology Co., Ltd is one of the best power supply device manufacturer in China. Our world-class production plant passed ISO9001:2008 & ISO14001:2004 certifications and is equipped with the state-of-art technology and machines. The main products we make are power adapters, which can be used in laptop, LCD display, LED lights, CCTV camera(12v series), Speaker(24v series), Balance car(42v series). All our products comply with European environmental standard as well as CCC,RoHS ,CE , FCC.
Ungrouped,High Quality Ungrouped,Ungrouped Details, CN
Shenzhen Waweis Technology Co., Ltd. , https://www.szwaweischarger.com