Abstract: Based on Winsock technology and network communication principles, this paper uses VC ++ programming technology to obtain real-time temperature running graphics on the client through network data transmission, remote monitoring of the temperature running status of the artificial climate room is implemented to meet the real-time automation requirements of low cost and high efficiency.
1 Introduction
With the continuous development of network technology, the network has had a profound impact on society. As a result, a new network-based monitoring and management framework emerged. Remote monitoring of network-based devices has become a hot topic in the field of computer network applications. The Socket technology is used to achieve connections and data exchange between networks, and remote monitoring of devices.
2 features and Implementation of the remote monitoring system of the artificial climate room
2.1 Communication Interface ----- socket Creation
What we need to achieve in this article is remote monitoring of a small artificial climate room, in a remote or within the same LAN, you do not have to visit the site to observe the current temperature conditions and operating temperature curves of the artificial climate chamber. Because the remote site only needs to query and observe, therefore, you only need to handle the communication and data transmission between the on-site monitoring computer and the remote client. In this way, the CPU processing time of the on-site computer is not used, which can save resources for more on-site processing work.
The connection to a remote server can be divided into the following processes:
(1) The service process is always started before the customer process. The service process first creates a socket.
(2) bind the local address to the created socket to mark the socket on the network.
(3) Place the socket in listening mode and prepare to accept connection requests.
(4) The client creates a SOCKET and calls the SOCKET function. The method is the same as above.
(5) The customer initiates a connection request to the server.
(6) When the request arrives, the accept () function of the blocked service process, as described in (3), generates a new socket to establish a connection with the client and return a receiving signal to the client.
(7) once the client socket receives a signal from the server, it indicates that the connection between the client and the server is ready and data can be transmitted.
(8) Close the socket. Once the task is completed, you must turn off the resources occupied by the released socket.
The code for creating a connection between the server and client is described as follows:
Server:
Void CServerView: OnStart ()
{Started = TRUE;
M_Start.EnableWindow (! Started );
Try
{G_sListen.Create (6802, SOCK_DGRAM, NULL );
G_sListen.Bind (6802, m_IP); //, 6802 indicates the port number, and m_IP indicates the Server IP address.
G_sListen.Listen ();
(CServerDoc *) GetDocument ()-> g_pchatListen = new CChatLsnSock (
(CAnyServerDoc *) GetDocument ());
CChatLsnSock * g_pchatListen = (CAnyServerDoc *) GetDocument ()-> g_pchatListen;
G_pchatListen-> Create (9999, SOCK_STREAM); // Create a socket for listening to a chat room
G_pchatListen-> Listen ();
GetDlgItem (IDC_RESPONSE)-> SetWindowText ("start to serve the client! ");
}
The running interface 1 after the server is enabled is shown in.
Client:
Void CClientView: OnClientStart ()
{M_sockRecv.Create (6801, SOCK_DGRAM, m_ClientIP); // 6801 indicates the port number and m_ClientIP indicates the Client IP address.
M_sockRecv.Bind (6801, m_ClientIP );
M_timer1 = SetTimer (1,1000, NULL );
M_timer2 = SetTimer (2,250, NULL );
GetLocalTime (& SysTime );
M_StartTime = policime;
M_WavePlay.SetStartTime (SysTime. wYear, SysTime. wMonth, SysTime. wDay, SysTime. wHour, SysTime. wMinute, Iime. wSecond); // plot the initial time of the curve.
This-> m_currentpolicime.setfocus ();
}
Figure 1: enable the Service running interface on the server
2.2 network data transmission and monitoring implementation
In network-based remote control and measurement applications, the binary format is generally the main cluster type for data transmission. In the remote monitoring system of the human climate room, both parties need to transmit less data streams, generally, the lower computer is an embedded system such as a microcontroller. The data processing capability is slow, and the communication parties do not have to maintain close contact. Therefore, most of them adopt the UDP protocol, which is based on the point-to-point method, the data reliability of communication between the two parties can be ensured by defining the data representation format. In addition, the data transmitted over the network is re-painted and displayed on the client in the form of a curve, and a self-developed ActiveX control is used to display the received data, the delay in data transmission is very short and negligible.
When the device is running, the status of the server is always enabled. The temperature measuring component transmits the measured temperature value to the control microcomputer, transmits the measured temperature value to the remote client through the network, and remotely connects the device by entering the IP address of the server, enter the specified username and password to connect to the instance and implement remote monitoring.
After the connection is established, the client can receive the temperature value sent and display it in a curve:
Void CClientView: OnDataReceive ()
{
Extern CListBox * pmyListBox;
Char szTempRecv [20];
CString szIP (m_IP); // obtain the IP address of the server.
UINT uPort = 6802; // indicates the port
Int iTempRecv = m_sockRecv.ReceiveFrom (szRecv, 10, szIP, uPort, 0 );
SzRecv [iRecv] =;
M_szRecv = szTempRecv;
M_listBox.AddString (LPCTSTR) m_szRecv );
Int nCount = m_listBox.GetCount ();
If (nCount> 0)
M_listBox.SetCurSel (nCount-1 );
GetLocalTime (& SystemTime );
M_NowTime = SystemTime;
CString strpolicime;
Strpolicime. format (_ T ("% d-% d: % d"), SystemTime. wYear, SystemTime. wMonth, SystemTime. wDay, SystemTime. wHour, SystemTime. wMinute, SystemTime. wSecond );
UpdateData (FALSE );
CurABSTime = (m_NowTime-m_StartTime). GetTotalSeconds ();
M_WavePlay.SetPoint2 (CurABSTime, atoi (m_szRecv); // use a self-made ActiveX Control to draw a temperature curve
The running interface 2 is displayed on the remote logon page.
3: Conclusion
In practical applications, the program also provides chat, remote screen viewing, and file upload and download functions to facilitate remote communication. In addition, the password and user name verification method are used for connection, which makes monitoring more powerful and prevents unauthorized users from logging on and tampering with data. In this paper, the artificial climate room is a project used for biological cultivation in cooperation with Shaoguan medical equipment factory. It has been put into use and is monitored by local area network.
Figure 2 Current temperature operation in the server's artificial climate room