Procedure TForm1.Read_Data1;///////順序讀取/////////////////////
Var R_Msg,Re_Add,ReData_Len,I,Col,Row,D8:Integer;
Re_Data:Array of LongInt;
Sen_Add:WideString;
str,Str1:String;
Str_Len:Integer;
begin
Re_Add :=StrToInt(Edit1.Text);//取出起始地址值
ReData_Len:=StrToInt(Edit2.Text);//取出數(shù)據(jù)長(zhǎng)度
IF(ComboBox1.Text='X')OR(ComboBox1.Text='Y') then //判定是為8進(jìn)制類(lèi)型設(shè)備X,y最大獲取范圍
begin
IF (ReData_Len+Re_Add)>128 then
ReData_Len:=128-Re_Add;
end;
FOR I:= 0 To ReData_Len-1 DO
begin
IF(ComboBox1.Text='X')OR(ComboBox1.Text='Y')Then //判定是為8進(jìn)制類(lèi)型設(shè)備X,y最大獲取范圍
D8:=DectoD8(Re_Add+I)
else
D8:=Re_Add+I;
IF I=0 THEN
Sen_Add:=ComboBox1.Text+IntToStr(D8)
else
Sen_Add:=Sen_Add+#10+ComboBox1.Text+IntToStr(D8);
end;
IF (Re_Add>=0)And(ReData_Len>0)then
Begin
SetLength(Re_Data,ReData_Len);
IF RadioButton4.Checked=True Then
R_Msg:=FX_Com.ReadDeviceRandom(Sen_Add,ReData_Len,Re_Data[0])
else
R_Msg:=FX_Usb.ReadDeviceRandom(Sen_Add,ReData_Len,Re_Data[0]);
end
ELSE
IF Re_Add<0 then
ShowMessage('起始地址有誤')
else
ShowMessage('長(zhǎng)度填寫(xiě)有誤碼');
IF R_Msg=0 Then
Stat_Bar.Panels.Items[7].Text:='接收成功'
else
Begin
Stat_Bar.Panels.Items[7].Text:='接收失敗錯(cuò)誤代碼:'+#13+IntTOstr(R_Msg);
Exit;
end;
FOR I:=0 TO High(Re_Data) DO
Begin
IF(ComboBox1.Text='X')OR(ComboBox1.Text='Y') then//判定是為8進(jìn)制類(lèi)型設(shè)備
begin
D8:=DectoD8(Re_Add+I);
Col:= (I+Re_ADD) MOD 8+1;
Row:= (I+Re_ADD) DIV 8+1;
end
ELSE
BEGIN
Col:= (I+Re_ADD) MOD 10+1;
Row:= (I+Re_ADD) DIV 10+1;
end;
IF Dec.Checked then
StringGrid1.Cells[Col,Row]:=IntToStr(Re_Data[I])
else
IF Hex.Checked then
StringGrid1.Cells[Col,Row]:=IntToHex(Re_Data[I],2)
else
IF Bin.Checked then
begin
str:=IntTostr(Re_Data[I]);
Str_Len:=Length(str);
str:=IntToBin(Re_Data[I],Str_Len*4);
Str1:='1';
Str_Len:=Pos(Str1,str);
Delete(Str,1,Str_Len-1);
IF str='0000' then
str:='0'
else
str:=str;
StringGrid1.Cells[Col,Row]:=str;
end;
StringGrid1.Font.Name:='宋體';
stringGrid1.Font.Size:=13;
Form1.Add_tpye;
end;
end;
我是用DELPHI寫(xiě),用的接口是USB,沒(méi)有問(wèn)題,測(cè)試過(guò)。