• Welcome to Forum.Deepsoftware.Com. Please login or sign up.
 

Modbus can't write twice

Started by crestxa, June 02, 2015, 06:00:53 am

Previous topic - Next topic

crestxa

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

Hello

I'm sorry if my reply is too late.

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

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.