⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ioboardtestunit.~pas

📁 在Windows 2000或者XP系统下的ISA接口卡测试程序的完整代码
💻 ~PAS
📖 第 1 页 / 共 2 页
字号:
  if Sender = EditOut1b then HexConvertBinDec(EditOut1b,EditOut1a,EditOut1c,ctByte) else
  if Sender = EditOut2b then HexConvertBinDec(EditOut2b,EditOut2a,EditOut2c,ctByte) else
  if Sender = EditOut3b then HexConvertBinDec(EditOut3b,EditOut3a,EditOut3c,ctByte) else
  if Sender = EditOut4b then HexConvertBinDec(EditOut4b,EditOut4a,EditOut4c,ctByte) else
  if Sender = EditOut5b then HexConvertBinDec(EditOut5b,EditOut5a,EditOut5c,ctWord) else
  if Sender = EditOut6b then HexConvertBinDec(EditOut6b,EditOut6a,EditOut6c,ctByte) else
  if Sender = EditOut7b then HexConvertBinDec(EditOut7b,EditOut7a,EditOut7c,ctByte);
 end;
end;

procedure TForm1.DecConvertBinHex(DecEdit,BinEdit,HexEdit: TEdit; ConvertType: TConvertType);
begin
 case ConvertType of
  ctByte: begin
           if Length(DecEdit.Text) >= 1 then begin
            BinEdit.Text := ByteToBin(StrToInt(DecEdit.Text));
            HexEdit.Text := ByteToHex(StrToInt(DecEdit.Text));
           end else begin
            BinEdit.Text := '00000000';
            HexEdit.Text := '00';
           end;
          end;
  ctWord: begin
           if Length(DecEdit.Text) >= 1 then begin
            BinEdit.Text := WordToBin(StrToInt(DecEdit.Text));
            HexEdit.Text := WordToHex(StrToInt(DecEdit.Text));
           end else begin
            BinEdit.Text := '0000000000000000';
            HexEdit.Text := '0000';
           end;
          end;
 end;
end;

procedure TForm1.EditOut1cChange(Sender: TObject);
begin
 if CodeEditPos = cepDec then begin
  if Sender = EditOut1c then DecConvertBinHex(EditOut1c,EditOut1a,EditOut1b,ctByte);
  if Sender = EditOut2c then DecConvertBinHex(EditOut2c,EditOut2a,EditOut2b,ctByte);
  if Sender = EditOut3c then DecConvertBinHex(EditOut3c,EditOut3a,EditOut3b,ctByte);
  if Sender = EditOut4c then DecConvertBinHex(EditOut4c,EditOut4a,EditOut4b,ctByte);
  if Sender = EditOut5c then DecConvertBinHex(EditOut5c,EditOut5a,EditOut5b,ctWord);
  if Sender = EditOut6c then DecConvertBinHex(EditOut6c,EditOut6a,EditOut6b,ctByte);
  if Sender = EditOut7c then DecConvertBinHex(EditOut7c,EditOut7a,EditOut7b,ctByte);
 end;
end;

procedure TForm1.ResetTestCode;
begin
 ByteCounter := 0;
 WordCounter := 0;
 MoveByte := 1;
 MoveWord := 1;
 PointAddCount := 0;
 ByteMoveToLeft := true;
 WordMoveToLeft := true;
 ATBool := false;
 WriteTestCodeToPorts(0,0);
end;

procedure TForm1.BitBtnResetClick(Sender: TObject);
begin
 ResetTestCode;
end;

function TForm1.GetRandomWord(RandomType: TRandomType): word;
begin
 Randomize;
 case RandomType of
  rtByte: result := Random($ff);
  rtWord: result := Random($ffff);
  rtLongword: result := Random($ffffffff);
 else result := Random($ff);
 end;
end;

procedure TForm1.SpinEdit1Change(Sender: TObject);
begin
 Timer1.Interval := SpinEdit1.Value;
end;

procedure TForm1.WriteTestCodeToPorts(ByteValue: byte; WordValue: word);
var
ByteIn : byte;
WordIn : word;
begin
 if CheckBoxGroup1.Checked then begin
  WriteByteToPort(IOBaseAddr,ByteValue);
  if CodeEditPos = cepBin then EditOut1a.Text := ByteToBin(ByteValue) else
  if CodeEditPos = cepHex then EditOut1b.Text := ByteToHex(ByteValue) else
  if CodeEditPos = cepDec then EditOut1c.Text := IntToStr(ByteValue);
  ByteIn := ReadByteFromPort(IOBaseAddr);
  EditIn1a.Text := ByteToBin(ByteIn);
  EditIn1b.Text := ByteToHex(ByteIn);
  EditIn1c.Text := IntToStr(ByteIn);
 end;

 if CheckBoxGroup2.Checked then begin
  WriteByteToPort(IOBaseAddr + 1,ByteValue);
  if CodeEditPos = cepBin then EditOut2a.Text := ByteToBin(ByteValue) else
  if CodeEditPos = cepHex then EditOut2b.Text := ByteToHex(ByteValue) else
  if CodeEditPos = cepDec then EditOut2c.Text := IntToStr(ByteValue);
  ByteIn := ReadByteFromPort(IOBaseAddr + 1);
  EditIn2a.Text := ByteToBin(ByteIn);
  EditIn2b.Text := ByteToHex(ByteIn);
  EditIn2c.Text := IntToStr(ByteIn);
 end;

 if CheckBoxGroup3.Checked then begin
  WriteByteToPort(IOBaseAddr + 2,ByteValue);
  if CodeEditPos = cepBin then EditOut3a.Text := ByteToBin(ByteValue) else
  if CodeEditPos = cepHex then EditOut3b.Text := ByteToHex(ByteValue) else
  if CodeEditPos = cepDec then EditOut3c.Text := IntToStr(ByteValue);
  ByteIn := ReadByteFromPort(IOBaseAddr + 2);
  EditIn3a.Text := ByteToBin(ByteIn);
  EditIn3b.Text := ByteToHex(ByteIn);
  EditIn3c.Text := IntToStr(ByteIn);
 end;

 if CheckBoxGroup4.Checked then begin
  WriteByteToPort(IOBaseAddr + 3,ByteValue);
  if CodeEditPos = cepBin then EditOut4a.Text := ByteToBin(ByteValue) else
  if CodeEditPos = cepHex then EditOut4b.Text := ByteToHex(ByteValue) else
  if CodeEditPos = cepDec then EditOut4c.Text := IntToStr(ByteValue);
  ByteIn := ReadByteFromPort(IOBaseAddr + 3);
  EditIn4a.Text := ByteToBin(ByteIn);
  EditIn4b.Text := ByteToHex(ByteIn);
  EditIn4c.Text := IntToStr(ByteIn);
 end;

 if CheckBoxGroup5.Checked then begin
  WriteWordToPort(IOBaseAddr + 4,WordValue);
  if CodeEditPos = cepBin then EditOut5a.Text := WordToBin(WordValue) else
  if CodeEditPos = cepHex then EditOut5b.Text := WordToHex(WordValue) else
  if CodeEditPos = cepDec then EditOut5c.Text := IntToStr(WordValue);
  WordIn := ReadWordFromPort(IOBaseAddr + 4);
  EditIn5a.Text := WordToBin(WordIn);
  EditIn5b.Text := WordToHex(WordIn);
  EditIn5c.Text := IntToStr(WordIn);
 end;

 if CheckBoxGroup6.Checked then begin
  WriteByteToPort(IOBaseAddr + 6,ByteValue);
  if CodeEditPos = cepBin then EditOut6a.Text := ByteToBin(ByteValue) else
  if CodeEditPos = cepHex then EditOut6b.Text := ByteToHex(ByteValue) else
  if CodeEditPos = cepDec then EditOut6c.Text := IntToStr(ByteValue);
  ByteIn := ReadByteFromPort(IOBaseAddr + 6);
  EditIn6a.Text := ByteToBin(ByteIn);
  EditIn6b.Text := ByteToHex(ByteIn);
  EditIn6c.Text := IntToStr(ByteIn);
 end;

 if CheckBoxGroup7.Checked then begin
  WriteByteToPort(IOBaseAddr + 7,ByteValue);
  if CodeEditPos = cepBin then EditOut7a.Text := ByteToBin(ByteValue) else
  if CodeEditPos = cepHex then EditOut7b.Text := ByteToHex(ByteValue) else
  if CodeEditPos = cepDec then EditOut7c.Text := IntToStr(ByteValue);
  ByteIn := ReadByteFromPort(IOBaseAddr + 7);
  EditIn7a.Text := ByteToBin(ByteIn);
  EditIn7b.Text := ByteToHex(ByteIn);
  EditIn7c.Text := IntToStr(ByteIn);
 end;
end;

procedure TForm1.AutoTest;
begin
 case AutoTestMode of
  atmOff : Timer1.Enabled := false;
  atmCounter : begin
                inc(ByteCounter);
                inc(WordCounter);
                WriteTestCodeToPorts(ByteCounter,WordCounter);
               end;
  atmRandom  : WriteTestCodeToPorts(GetRandomWord(rtByte),GetRandomWord(rtWord));
  atmScanMove: begin
                if ByteMoveToLeft then begin
                 if MoveByte < $80 then MoveByte := MoveByte shl 1 else begin
                  MoveByte := MoveByte shr 1;
                  ByteMoveToLeft := false;
                 end;
                end else begin
                 if MoveByte > $01 then MoveByte := MoveByte shr 1 else begin
                  MoveByte := MoveByte shl 1;
                  ByteMoveToLeft := true;
                 end;
                end;
                if WordMoveToLeft then begin
                 if MoveWord < $8000 then MoveWord := MoveWord shl 1 else begin
                  MoveWord := MoveWord shr 1;
                  WordMoveToLeft := false;
                 end;
                end else begin
                 if MoveWord > $0001 then MoveWord := MoveWord shr 1 else begin
                  MoveWord := MoveWord shl 1;
                  WordMoveToLeft := true;
                 end;
                end;
                WriteTestCodeToPorts(MoveByte,MoveWord);
               end;
atmCycleMove : begin
                if MoveByte < $80 then MoveByte := MoveByte shl 1
                                  else MoveByte := $01;
                if MoveWord < $8000 then MoveWord := MoveWord shl 1
                                    else MoveWord := $0001;
                WriteTestCodeToPorts(MoveByte,MoveWord);
               end;
atmPointMove : begin
                if MToLeft then begin
                 MoveByte := MoveByte shl 1;
                 MoveWord := MoveWord shl 1;
                end else begin
                 MoveByte := MoveByte shr 1;
                 MoveWord := MoveWord shr 1;
                end;
                if MoveMap[PointAddCount + 1] <> '0' then begin
                 if MToLeft then begin
                  inc(MoveByte);
                  inc(MoveWord);
                 end else begin
                  inc(MoveByte,$80);
                  inc(MoveWord,$8000);
                 end;
                end;
                if PointAddCount >= (MoveMapLen - 1) then PointAddCount := 0
                                                     else inc(PointAddCount);
                WriteTestCodeToPorts(MoveByte,MoveWord);
               end;
  atmBit1    : begin
                if ATBool then WriteTestCodeToPorts(CByteBit1,CWordBit1)
                          else WriteTestCodeToPorts(not CByteBit1,not CWordBit1);
                ATBool := not ATBool;
               end;
  atmBit2    : begin
                if ATBool then WriteTestCodeToPorts(CByteBit2,CWordBit2)
                          else WriteTestCodeToPorts(not CByteBit2,not CWordBit2);
                ATBool := not ATBool;
               end;
  atmBit3    : begin
                if ATBool then WriteTestCodeToPorts(CByteBit3,CWordBit3)
                          else WriteTestCodeToPorts(not CByteBit3,not CWordBit3);
                ATBool := not ATBool;
               end;
  atmBit4    : begin
                if ATBool then WriteTestCodeToPorts(CByteBit4,CWordBit4)
                          else WriteTestCodeToPorts(not CByteBit4,not CWordBit4);
                ATBool := not ATBool;
               end;
 end;
 if AutoTestMode <> atmOff then begin
  inc(TestCount);
  EditCount.Text := FillNumber0(IntToStr(TestCount),10);
 end;
end;

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
 AutoTestMode := atmCounter;
 Timer1.Enabled := true;
end;

procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
 AutoTestMode := atmRandom;
 Timer1.Enabled := true;
end;

procedure TForm1.SpeedButton3Click(Sender: TObject);
begin
 MoveByte := 1;
 MoveWord := 1;
 AutoTestMode := atmScanMove;
 Timer1.Enabled := true;
end;

procedure TForm1.SpeedButton4Click(Sender: TObject);
begin
 MoveByte := 1;
 MoveWord := 1;
 AutoTestMode := atmCycleMove;
 Timer1.Enabled := true;
end;

procedure TForm1.SpeedButton5Click(Sender: TObject);
begin
 MoveByte := 0;
 MoveWord := 0;
 AutoTestMode := atmPointMove;
 Timer1.Enabled := true;
end;

procedure TForm1.SpeedButton6Click(Sender: TObject);
begin
 AutoTestMode := atmBit1;
 Timer1.Enabled := true;
end;

procedure TForm1.SpeedButton7Click(Sender: TObject);
begin
 AutoTestMode := atmBit2;
 Timer1.Enabled := true;
end;

procedure TForm1.SpeedButton8Click(Sender: TObject);
begin
 AutoTestMode := atmBit3;
 Timer1.Enabled := true;
end;

procedure TForm1.SpeedButton9Click(Sender: TObject);
begin
 AutoTestMode := atmBit4;
 Timer1.Enabled := true;
end;

procedure TForm1.SpeedButton10Click(Sender: TObject);
begin
 AutoTestMode := atmOff;
 Timer1.Enabled := false;
end;

procedure TForm1.EditIOBaseChange(Sender: TObject);
begin
 IOBaseAddr := HexToWord(EditIOBase.Text);
end;

procedure TForm1.EditMoveMapChange(Sender: TObject);
begin
 MoveMapLen := Length(EditMoveMap.Text);
 if MoveMapLen <= 0 then begin
  MoveMapLen := 3;
  MoveMap := '110';
 end else MoveMap := EditMoveMap.Text;
end;

procedure TForm1.SpeedButton11Click(Sender: TObject);
begin
 MToLeft := true;
end;

procedure TForm1.SpeedButton12Click(Sender: TObject);
begin
 MToLeft := false;
end;

procedure TForm1.BitBtnOut1Click(Sender: TObject);
begin
 if Sender = BitBtnOut1 then WriteByteToPort(IOBaseAddr,HexToByte(EditOut1b.Text)) else
 if Sender = BitBtnOut2 then WriteByteToPort(IOBaseAddr + 1,HexToByte(EditOut2b.Text)) else
 if Sender = BitBtnOut3 then WriteByteToPort(IOBaseAddr + 2,HexToByte(EditOut3b.Text)) else
 if Sender = BitBtnOut4 then WriteByteToPort(IOBaseAddr + 3,HexToByte(EditOut4b.Text)) else
 if Sender = BitBtnOut5 then WriteWordToPort(IOBaseAddr + 4,HexToWord(EditOut5b.Text)) else
 if Sender = BitBtnOut6 then WriteByteToPort(IOBaseAddr + 6,HexToByte(EditOut6b.Text)) else
 if Sender = BitBtnOut7 then WriteByteToPort(IOBaseAddr + 7,HexToByte(EditOut7b.Text));
end;

procedure TForm1.BitBtnIn1Click(Sender: TObject);
var
ReadByteValue: byte;
ReadWordValue: word;
begin
 if Sender = BitBtnIn1 then begin
  ReadByteValue := ReadByteFromPort(IOBaseAddr);
  EditIn1a.Text := ByteToBin(ReadByteValue);
  EditIn1b.Text := ByteToHex(ReadByteValue);
  EditIn1c.Text := intToStr(ReadByteValue);
 end else
 if Sender = BitBtnIn2 then begin
  ReadByteValue := ReadByteFromPort(IOBaseAddr + 1);
  EditIn2a.Text := ByteToBin(ReadByteValue);
  EditIn2b.Text := ByteToHex(ReadByteValue);
  EditIn2c.Text := IntToStr(ReadByteValue);
 end else
 if Sender = BitBtnIn3 then begin
  ReadByteValue := ReadByteFromPort(IOBaseAddr + 2);
  EditIn3a.Text := ByteToBin(ReadByteValue);
  EditIn3b.Text := ByteToHex(ReadByteValue);
  EditIn3c.Text := IntToStr(ReadByteValue);
 end else
 if Sender = BitBtnIn4 then begin
  ReadByteValue := ReadByteFromPort(IOBaseAddr + 3);
  EditIn4a.Text := ByteToBin(ReadByteValue);
  EditIn4b.Text := ByteToHex(ReadByteValue);
  EditIn4c.Text := IntToStr(ReadByteValue);
 end else
 if Sender = BitBtnIn5 then begin
 // WriteByteToPort(IOBaseAddr + $01,1); // SetMZPBoardNo
 // WriteByteToPort(IOBaseAddr + $00,$0a); // SetMZPBoardIndex
 // ReadWordValue := ReadWordFromPort(IOBaseAddr + 4); // GetMZPBoardWord
 // WriteByteToPort(IOBaseAddr + $00,$00); // SetMZPBoardIndex
  ReadWordValue := ReadWordFromPort(IOBaseAddr + 4);
  EditIn5a.Text := WordToBin(ReadWordValue);
  EditIn5b.Text := WordToHex(ReadWordValue);
  EditIn5c.Text := IntToStr(ReadWordValue);
 end else
 if Sender = BitBtnIn6 then begin
  ReadByteValue := ReadByteFromPort(IOBaseAddr + 6);
  EditIn6a.Text := ByteToBin(ReadByteValue);
  EditIn6b.Text := ByteToHex(ReadByteValue);
  EditIn6c.Text := IntToStr(ReadByteValue);
 end else
 if Sender = BitBtnIn7 then begin
  ReadByteValue := ReadByteFromPort(IOBaseAddr + 7);
  EditIn7a.Text := ByteToBin(ReadByteValue);
  EditIn7b.Text := ByteToHex(ReadByteValue);
  EditIn7c.Text := IntToStr(ReadByteValue);
 end;
end;


end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -