procedure updateString (KanbanID, subid: integer; kbstr: string); var commtimeouts: TCommTimeouts; dcb: Tdcb; hcommfile: Thandle; temp: array [0..10] of byte; s, s_edit: string; dataptr, input: pchar DataSize, NSENT, FDWEVTMASK: DWORD; I, J, K: INTEGER; Port: Integer; SendNum: Integer; Begin Port: = 2; Case Port of 1: S: = 'COM1'; 2: S: = 'COM2 '; 3: s: =' COM3 '; 4: s: =' Com4 '; end; hcommfile: = createfile (pchar (s), generic_read generic_write, 0, nil, open_existing, file_attribute_normal, 0); if (hcommfile = INVALID_HANDLE_VALUE) or (GetFileType (hCommFile) <> FILE_TYPE_CHAR) then exit; fillchar (dcb, sizeof (dcb), 0); // setup dcb struct dcb.DCBLength: = sizeof (dcb); dcb.Flags: = $ 00000003; dcb.BaudRate: = 2400; dcb.bytesize: = 8; dcb.Parity: = MARKPARITY; // 2; dcb.StopBits: = ONESTOPBIT; // 0; commtimeouts.ReadIntervalTimeout: = 1; // setup commtimeout commtimeouts.ReadTotalTimeoutMultiplier : = 1; CommTIMEOUTS.ReadtotalTimeoutConstant: = 1; CommTIMEOUTS.W riteTotalTimeoutMultiplier: = 0; commtimeouts.WriteTotalTimeoutConstant: = 0; SetCommTimeouts (hCommFile, commtimeouts); fdwEvtMask: = EV_TXEMPTY; setcommmask (hcommfile, fdwEvtMask); SetCommState (hCommFile, dcb); s: = chr (subid) chr (subid) chr (subid); // setup kanban id and subid DataSize: = Length (s); // Write Routine DataPtr: = Pchar (s); While DataSize> 0 Do Begin Writefile (Hchamfile, DataPtr ^, DataSize, NSent, NIL); DATASIZE: = DATASIZE - ABS (NSENT); END; DCB.PARITY: = SpaceParity; // 2; setcommstate (hcommfile, dcb); Send strbs (kbstr)> 10 THEN KBSTR: = Copy (KBSTR, 1, 10); DATASIZE: =
Length (kbstr); s_edit: = kbstr; While DataSize <10 Do Begin S_EDit: = S_EDit CHR ($ 20); inc; End; s: = CHR ($ EE) CHR ($ 00) CHR ($ 1 CHR ($ 01) chr (9) s_edit; DataSize: = Length (s); // Write Routine DataPtr: = PCHAR (S); // Sleep (20); while DataSize> 0 Do Begin Writefile (hcommfile , DataPtr ^, DataSize, nsent, nil); DataSize: = DataSize - abs (nsent); end; CloseHandle (hCommFile); end; under Win98 Delphi6 debugging author of the article: DBoy source: no author email:. Webmaster@dboy520.51.net author website: http://www.delphiboy.com