Delphi Learning Note 2 Dynamic library invocation and serial communication

Source: Internet
Author: User

Serial communication:

Spcomm Control Properties:

commname : Indicates the name of COM1,COM2 and other serial ports;

baudrate: Set baud rate 9600,4800, etc.



function Writecommdata (Pdatatowrite:pchar;dwsizeofdatatowrite:word): Boolean

Used to send a string to a write thread, send a successful return true, send failed to return FALSE, execute this function will immediately get the return value, the send operation followed by the line.

The function has two parameters, where Pdatatowrite is the string to send, and dwsizeofdatatowrite is the length of the send.

Event Onreceivedata:procedure (sender:tobject; Buffer:pointer; Bufferlength:word) of Object  

This event is triggered when the input cache has data, where the data received from the serial port can be processed. Buffer is the received data, Bufferlength is the received data length

Dynamic Library Invocation

 UnitCmups_hb600dll;InterfacetypeIcumpsHB600=Record     End; functionZt_ups_opendevice (pstrcom:p Ansichar;varM_nupshandle:pinteger;nfage:integer=0): Integer;stdcall;//turn on the device    functionZt_ups_closedevice (Nhandle:pinteger): Integer;stdcall;//turn off the device    functionZt_ups_getstatus (Nhandle:pinteger): Integer;stdcall;//Get Device statusImplementation  functionZt_ups_opendevice;External 'Zt_ups.dll'; functionZt_ups_closedevice;External 'Zt_ups.dll'; functionZt_ups_getstatus;External 'Zt_ups.dll';End.

The above is an example. Need to note:

first, call parameters with StdCall

Second, use the external statement to specify the path and name of the called DLL file

Third, pay attention to the transfer of parameters.

The Pansichar type corresponds to the C language of the char*
The Pinteger type corresponds to the C language of the int*
The integer type corresponds to the C-language int
var m_nupshandle:pinteger corresponds to the C language of the int*, here is the reference pass


Delphi Learning Note 2 Dynamic library invocation and serial communication

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.