[ Pobierz całość w formacie PDF ]
.Enabled := FALSE;CloseHandle(hCommDev);Application.Terminate();end;idNo: Exit;end;end;//--------------------------------------------------------------------procedure TForm1.OpenCommClick(Sender: TObject);beginif (CheckBox1.Checked = TRUE) thenlpFileName := 'COM2';hCommDev:= CreateFile(lpFileName, GENERIC_READ or GENERIC_WRITE, 0,NIL, OPEN_EXISTING, 0, 0);if (hCommDev INVALID_HANDLE_VALUE) thenbeginSetupComm(hCommDev, cbInQueue, cbOutQueue);dcb.DCBlength := sizeof(dcb);GetCommState(hCommDev, dcb);if (CheckBox2.Checked = TRUE) thendcb.BaudRate:=CBR_1200;//-przyk³adowe ustawienia znaczników steruj¹cych DCB-dcb.Flags := dcb_fParity;dcb.Parity := ODDPARITY;dcb.StopBits := ONESTOPBIT;dcb.ByteSize := 7;SetCommState(hCommDev, dcb);GetCommMask(hCommDev, fdwEvtMask);SetCommMask(hCommDev, EV_TXEMPTY);endelsecase hCommDev ofIE_BADID:beginApplication.MessageBox('Niew³aœciwa nazwa portu lub'+' jest on aktywny', 'Uwaga !',MB_OK);lpFileName:='';end;end;end;//--------------------------------------------------------------------function Write_Comm(hCommDev: THANDLE;nNumberOfBytesToWrite: DWORD): Integer;varNumberOfBytesWritten : DWORD;beginWriteFile(hCommDev, Buffer_O, nNumberOfBytesToWrite,NumberOfBytesWritten, NIL);if (WaitCommEvent(hCommDev, fdwEvtMask, NIL) = TRUE) thenWrite_Comm := 1elseWrite_Comm := 0;end;//--------------------------------------------------------------------function Read_Comm(hCommDev: THANDLE;Buf_Size: DWORD): Integer;varnNumberOfBytesToRead: DWORD;beginClearCommError(hCommDev, Errors, @Stat);if (Stat.cbInQue > 0) thenbeginif (Stat.cbInQue > Buf_Size) thennNumberOfBytesToRead := Buf_SizeelsenNumberOfBytesToRead := Stat.cbInQue;ReadFile(hCommDev, Buffer_I, nNumberOfBytesToRead,Number_Bytes_Read, NIL);Read_Comm := 1;endelsebeginNumber_Bytes_Read := 0;Read_Comm := 0;end;end;//--------------------------------------------------------------------function RS_Send: Integer;beginRepeatFlushFileBuffers(hCommDev);Until (Write_Comm(hCommDev, StrLen(Buffer_O)) 0);Inc(intVar); // zliczanie kolejnych pomiarówForm1.Memo1.Lines.Add(AnsiString(IntToStr(intVar)));Form1.Memo1.Lines.Add('');Result := 0;end;//--------------------------------------------------------------------function RS_Receive: Integer;beginif (Read_Comm(hCommDev, SizeOf(Buffer_I)) > 0) thenbeginForm1.Memo2.Lines.Add(AnsiString(Buffer_I));// Beep();endelsebeginForm1.Memo2.Lines.Add('x0');Beep();Form1.Memo2.Lines.Add('');end;Result:=0;end;//--------------------------------------------------------------------procedure TForm1.StartClick(Sender: TObject);beginif (hCommDev > 0) thenbeginOpenComm.Enabled := FALSE;Timer1.Enabled:=TRUE;Label1.Caption := 'Pomiar';endelseApplication.MessageBox('Niew³aœciwa nazwa portu lub jest on'+' aktywny ', 'Uwaga !',MB_OK);end;//--------------------------------------------------------------------procedure TForm1.FormCreate(Sender: TObject);beginTimer1.enabled := FALSE;Timer1.Interval := 1000;TrackBar1.Position := 1000;TrackBar1.Max := 2000;TrackBar1.Min := 1;TrackBar1.Frequency := 100;OpenComm.Enabled := TRUE;intVar := 0;end;//--------------------------------------------------------------------procedure TForm1.SuspendClick(Sender: TObject);beginTimer1.Enabled := FALSE;Label1.Caption := 'Wstrzymanie';end;//--------------------------------------------------------------------procedure TForm1.ResumeClick(Sender: TObject);beginTimer1.Enabled := TRUE;Label1.Caption := 'Pomiar';end;//--------------------------------------------------------------------procedure TForm1.TimerOnTimer(Sender: TObject);beginStrCopy(Buffer_O, query);RS_Send;RS_Receive;end;//--------------------------------------------------------------------procedure TForm1.SpeedButton1Click(Sender: TObject);beginForm1.Memo2.SelectAll;Form1.Memo2.CopyToClipboard;end;//--------------------------------------------------------------------procedure TForm1.SpeedButton2Click(Sender: TObject);beginForm1.Memo1.SelectAll;Form1.Memo1
[ Pobierz całość w formacie PDF ]