|
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.WriteTotalTimeoutMultiplier :=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(hcommfile,DataPtr^,DataSize,nsent,nil ); DataSize := DataSize - abs(nsent); end; dcb.Parity:=SPACEPARITY;//2; SetCommState(hCommFile,dcb); send str if length(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(datasize); 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; 在Win98+Delphi6下调试通过. |
文章作者:DBoy | |
文章来源:暂无 | |
作者邮箱:webmaster@dboy520.51.net | |
作者网站:http://www.delphiboy.com |