Serial communication:
Spcomm Control Properties:
commname : Indicates the name of COM1,COM2 and other serial ports;
baudrate: Set baud rate 9600,4800, etc.
Startcomm
Stopcomm
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