|
|
|
Based on VC + + for bottle machine computer control system of serial communication by big tree
|
|
|
Based on VC + + for bottle machine computer control system of serial communication by BIG TREE
|
|
Article Posted: 07/30/2010 |
Article Views: 51 |
Articles Written: 1033 - MORE ARTICLES FROM THIS AUTHOR |
Word Count: 1119 |
Article Votes: 0 |
|
Based on VC + + for bottle machine computer control system of serial communication |
|
|
|
Business,Business News,Business Opportunities
|
|
Introduction Bottle machine computer control system's basic function is to control the various machine bottle machine movement, to work in accordance with set procedures. In order to achieve the host and the next bit plane between the control operations and data management, through the serial port connection with data acquisition and control functions of the lower position, and then by the operator through the operation of PC management software to operate the command passed to the lower machine to complete the kind of control and management, therefore, serial Communicate Technology is the bottle machine computer control system development one of the key technologies. VC environment in the bottle machine computer control system, the PC host computer's communication program, its serial communication programming method there are three: Using VC + + provides MSComm control to realize serial communication, based on a a serial communication C + + classes, based on serial communications API. For simple serial port, the first two are relatively easy to achieve, is also more convenient to use, simple control. However, for the more complex serial port, it is not flexible enough. The serial programming method based API is a powerful, controls more freedom and flexibility, you can write effective and powerful communication process. On the lower machine, because the storage capacity is limited, if you want to store large amounts of data will produce loss phenomenon, the data stored in PC database, you can make up for this issue. Because VC + + offers a variety of database access technologies such as ODBC, O LED B, ADO, etc., which are based on OLEDB, ADO technology to access interface, it inherits the advantages of the technique OLEDB, OLEDB interface and made package, and defines the ADO object, it can be simplified program development, and technology-based ADO applications can be accessed through a consistent interface to a variety of data, but also conducive to the migration and expansion program. Analysis based on the above considerations, the author focuses on the VC + +, how to use the API functions and ADO database programming technology to achieve real-time data acquisition, while real-time data saved to the database, thus completing the bottle machine computer control system between the host and the lower computer and display data in real-time operation of specific methods. Serial communication function using WindowsAPI In the Windows environment, the serial port is part of system resources, when the data from the CPU through the serial port to send out, the byte data is converted to serial bit; in receiving data, the serial bit further will be converted to byte data. Application to use the serial port to communicate, we must make use of resources to the operating system before the application (open serial port), but also set the serial communication address, baud rate, parity, data bits and stop bits and other related configuration, communication Upon completion, it must release the resources (close serial port). Open the serial port Serial communication procedure to call CreatFile () function since the function's return value is a handle. Can then use the other port operations. Once the port is open, you can automatically assign a send / receive buffer, of course, can also transfer SetComm () function to change the send / receive buffer size. 1.2 serial configuration Serial port to open is successful. Then the serial port should be initialized to configure the serial port communication parameters such as baud rate, data bits, stop bits, parity bit and so on. Modify these parameters using the device control block DCB (DeviceControlBlock). DCB is a complex structure of the data, nearly 30 members; However, a 3-line serial communication is, DCB structure of most of the parameters can not, just set such as baud rate, data bits, stop bit, parity bit, and several other key parameters can be normal work. Windows also provide GetCommState () function to obtain the serial interface of the current configuration, it can be used SetCommState () to re-configure the serial interface of the various parameters. 1.3 serial read / write operations Win32API through the program can use the ReadFile () function to read data from the serial port, or use the WriteFile () function to write data to the serial port. If the serial interface communication error (such as the occurrence of terminal error, parity error, etc.), I / O operation will be terminated. At this point, if the procedure is necessary to further the implementation of the serial interface I / O operations, you must call ClearCommError () function to restore the serial interface. ClearCommError () function has two functions: First, clear the error condition; the second is to identify the serial interface communication status. In addition, the serial interface, the system providing a group of communication events and the corresponding handler. Windows system can be monitored in the process occurred in the serial interface of this group of events, therefore, the application does not check port in the state where you can know when certain conditions occur. Using these events, the application will not need to receive bytes and continuous detection of the port, thus saving CPU time. Close serial port The program finished, back when Windows environment, typically the serial port should be closed to other uses. Can use the function C10seHandle (HandlehObject) to stop all serial input and output, parameter hObject is the CreateFile function returns, the mark serial communication handle. 2 VC + + in the database using ADO Initialize OLE / COM library environment Create a standard MFCAppWizard (exe) application, but also in the application class InitInstance function initialize the OLE / COM libraries (because ADO library is a COMDLL library), its code is as follows: The introduction of ADO library Before using ADO, you must project stdafx. h file # import directly into sign to lead AADO library files, so the compiler can be built correctly. The code is as follows: 2.3 for database operation using smart pointers ADO library contains three smart pointers: _ConnectionPtr, _CommandPtr, _RecordsetPtr. One _ConnectionPtr often used to open and close a database connection. For the purpose of library connections, can first create an instance of the pointer, and then Open to open a database connection. Below to connect to the database db. mdb example to illustrate: _ConnectionPtr ConnectPtr; ConnectPtr. CreateInstance ("ADODB.Connection ");// create an instance of the pointer ConnectPtr-> Open ("P I am China Manufacturers writer, reports some information about metal lunch boxes , sink mat.
Related Articles -
metal lunch boxes, sink mat,
|
Rate This Article |
|
|
|
Do you Agree or Disagree? Have a Comment? POST IT!
Reader Opinions |
|
|
|
|
|
|
|
|
Author Login |
|
|
Advertiser Login
ADVERTISE HERE NOW!
Limited Time $60 Offer!
90 Days-1.5 Million Views
|
|
TIM FAY
After 60-plus years of living, I am just trying to pass down some of the information that I have lea...more
|
|
|
|
|
LAURA JEEVES
At LeadGenerators, we specialise in content-led Online Marketing Strategies for our clients in the t...more
|
|
|
|
|
ADRIAN JOELE
I have been involved in nutrition and weight management for over 12 years and I like to share my kn...more
|
|
|
|
|
GENE MYERS
Author of four books and two screenplays; frequent magazine contributor. I have four other books "in...more
|
|
|
|
|
DONNIE LEWIS
I'm an avid consumer of a smoothie a day living, herbs, vitamins and daily dose of exercise. I'm 60...more
|
|
|
|
|
ALEX BELSEY
I am the editor of QUAY Magazine, a B2B publication based in the South West of the UK. I am also the...more
|
|
|
|
|
SUSAN FRIESEN
Located in the lower mainland of B.C., Susan Friesen is a visionary brand strategist, entrepreneur, ...more
|
|
|
|
|
STEPHEN BYE
Steve Bye is currently a fiction writer, who published his first novel, ‘Looking Forward Through the...more
|
|
|
|
|
STEVE BURGESS
Steve Burgess is a freelance technology writer, a practicing computer forensics specialist as the pr...more
|
|
|
|