Check if RS232 (serial port) is connected

xiaoxiao2021-03-06  42

There are 4 foots in RS232 to respond to the signals to CTS, DSR, RING, and RLSD. When not connected to the device, the electricity of the foot is low, the signal is returned to OFF, and many devices use this. The four feet are communicated with the computer, so check if the foot voltage will know if there is a device on the COM existing MS_CTS_ON, MS_DSR_ON, MS_RING_ON, MS_RLSD_ONPROCEDURE TFORM1.BUTTON1CLICK (Sender: Tobject); VARCC: TCOMMCONFIG; hcomm: thandle; com: String; Ls: dword; begincom: = 'COM2'; hcomm: = createfile (Pchar (COM), generic_read or generic_write, 0, nil, open_existing, 0, 0); if getcommmodemstatus (hcomm, ls) Thenbeginif (LS and MS_CTS_ON) = MS_CTS_ON THENBEGINBUTTON1.CAPTION: = 'CTSON'END; END; CloseHandle (HCOMM); END; (author anykey) end.2. Check the value obtained by Handle Procedure TFORM1.BUTTON1CLICK (Sender: Tobject); VARCC: Tcommconfig; hcomm: THandle; Com: String; lS: dword; beginCom: = 'COM2'; hComm: = CreateFile (Pchar (Com), Generic_read or Generic_write, 0, nil, open_existing, 0,0); if (hComm = invalid_Handle_value) thenbeginshowmessage ( 'Communication port error); end; closehandle (hcomm); end; (author anykey)

转载请注明原文地址:https://www.9cbs.com/read-56724.html

New Post(0)