Author Topic: Modbus can't write twice  (Read 577 times)

crestxa

  • Newbie
  • *
  • Posts: 15
    • View Profile
Modbus can't write twice
« on: June 02, 2015, 09:00:53 am »
I use  trial version of nrcomm to test
begin
  HQ_RegBase:=$00A8;      //
  HQ_RegVal:=StrToInt(e420mAMax1.Text)*10;
  HQ_RegAddr:=StrToInt(eAddress.Text);
  nrModbus1.ASCII := grpMode.ItemIndex > 0;
  // write register value by using modbus function 6       //
  nrModbus1.WriteRegister(HQ_RegBase, HQ_RegVal, HQ_RegAddr);
  HQ_RegBase:=$00C8;      // 4-20mA
  HQ_RegVal:=StrToInt(e420mAMin1.Text)*10;
  sleep(100);
  nrModbus1.WriteRegister(HQ_RegBase, HQ_RegVal, HQ_RegAddr);
end;
this procedure can't run twice,
if there is one  nrModbus1.WriteRegister(HQ_RegBase, HQ_RegVal, HQ_RegAddr);  modify nrModbus1 timeout to 100,can be do any time.but when there are two writeregister ,whatever nrModbus1 timeout ,can't do twice,
if i reopen nrComm1,it can writeregister again ,but not twice.It's seem nrModbus1 want some date back,
if I want some writeregister in one  procedure ,How can i do?
thanks!

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: Modbus can't write twice
« Reply #1 on: August 06, 2015, 10:22:22 am »
Hello

I'm sorry if my reply is too late.

We modified Modbus demo project and following handlers on label double click:

Code: [Select]
procedure TForm6.Label5DblClick(Sender: TObject);
begin
  nrModbus1.ASCII := grpMode.ItemIndex > 0;
  nrModbus1.WriteRegisters(50, [$0], 23);
  nrModbus1.WriteRegisters(50, [$0], 22);
  nrModbus1.WriteRegisters(50, [$0], 21);
end;

procedure TForm6.Label6DblClick(Sender: TObject);
begin
  nrModbus1.ASCII := grpMode.ItemIndex > 0;
  nrModbus1.WriteRegisters(50, [15], 23);
  nrModbus1.WriteRegisters(50, [15], 33);
  nrModbus1.WriteRegisters(50, [15], 21);
end;

We use three modbus devices with addresses: 21, 22, 23
Note that 33 does not exist.

All works fine.

nrModbus1.WriteRegisters(50, [15], 23);  // -  sends data correctly.
nrModbus1.WriteRegisters(50, [15], 33);  // timeout error because there is no 33 device
nrModbus1.WriteRegisters(50, [15], 21);  // -  sends data correctly.

We can repeat this routines any times without any problems.
All works correctly.

Please note that WriteRegisters() method place Modbus write request into internal queue and you do not need and Sleep() calls between write operations.

Roman Novgorodov
DeepSoftware llc
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.