yesful 发表于 2010-11-1 11:44:42

使用modbus往单片机写数据错误Access vilation at address 00469791 in module 'MT

delphi,我使用modbus往单片机写数据,出现错误:Access vilation at address 00469791 in module 'MT_FS.exe',read of address 00000000.我查了一下,网上说这是因为程序试图存取未被指定使用的存储区,但我不知道哪里存储区未被指定,该怎么解决?请大侠们指点!(代码如下)

procedure TMainForm.btnWriteAddClick(Sender: TObject);
varstr:string;
   i : integer;
   obj : PAsync;
begin
   i := 0;
   if (edAdd.text ='')and (not CheckBox1.checked) then
          showmessage('请输入装置地址')
   else
   begin
      ifcheckBox1.checked then   //广播地址
          Address := '00'
      else
      Address := edAdd.text;
      if edAddress.Text = '' then
      showmessage('请输入地址!')
      else
      begin
      str :=Address+'10'+'00'+'02'+'00'+'01'+'02'+'00'+edAddress.text;//差校验数值
      str := str+ ModBusCRC(HexStrToStr(str));//发送的字符串(包含地址,功能码,数据,CRC)
      InitAsync(obj);
         try
         ComPort.WriteStrAsync(hexstrToStr(str),obj);
         SendMemo.Text := SendMemo.text+ str+' ';
         i := i+1;
         if (i>30000) then
         begin
         ComPort.AbortAllAsync ;
         showmessage('通信失败,请重新发送!');
          end;
         ComPort.WaitForAsync(obj);
         sleep(100);//发送命令后等待100MS,保证数据的完整性;
         ComPort.ReadStr(Str, 20);//读取接收缓存区20个字节数;
         comport.ClearBuffer(true,true);//清除发送区和接收区
         finally
         DoneAsync(obj);
         end;
         RXMemo.text :=RXMemo.text + StrToHexstr(str);
         if(not CRCCheck(str)) then
            showmessage('接收数据错误!')
         else
            showmessage('接收数据成功!');
         end;
      end;
end;
页: [1]
查看完整版本: 使用modbus往单片机写数据错误Access vilation at address 00469791 in module 'MT