Forum.Deepsoftware.Com

DeepSoftware Products => nrComm Lib VCL (32bit / 64bit) => nrComm Lib => RS232 (serial) port => Topic started by: MTZOVARAS on October 31, 2024, 05:15:49 am

Title: RS485
Post by: MTZOVARAS on October 31, 2024, 05:15:49 am
Hi,

i have one COM port in RS485 mode with 2 devices on this port.
One is MODBUS with ID6 so the dataprocessor of the port is nrModbus1
For the other device with ID1 i have a different nrDataProcessor

How to manage the two different dataprocessors ?


Thank you,
Title: Re: RS485
Post by: Roman Novgorodov on October 31, 2024, 09:24:42 am
Hello

You need to use ONE instance of nrModbus component. It allows to change ADDRESS for request different modbus slaves. You can read various modbus slaves, see following code:


nrModbus1.WriteRegister($1234, 11, 6);  // write value 11 into REGISTER 0x1234 for modbus slave  6
nrModbus1.WriteRegister($1234, 11, 7);  // write value 11 into REGISTER 0x1234 for modbus slave  7



Roman Novgorodov

Title: Re: RS485
Post by: MTZOVARAS on November 01, 2024, 07:35:48 am
Sorry for the misunderstanding !
It was my fault !

The second device is not modbus.
It is a device where i send an ASCII command and replies with ASCII line.
I have a nrDataProcessor for the second device and an nrModbus for the first.

Do i have to activate once the nrModbus and once the nrDataProcessor and vice versa
or
is there a way to have the two of them activated  ?
Title: Re: RS485
Post by: Roman Novgorodov on November 01, 2024, 08:06:11 am
Hello

It is not good idea to use one serial line with two devices with two different data transfer protocols.
Of course, You can try to use something like following:


nrComm1.DataProcessor := nrDataProcessor1;
nrDataProcessor1.DataProcessor := nrModbus1;


But there are no guaranties to correct work, it depends on data transfer logic.

Instead that you can switch between necessary protocols at runtime:


// switch to custom ASCII protocol
nrModbus1.Active := false;
nrComm1.DataProcessor := nrDataProcessor1;
nrDataProcessor1.Active : = true;

// switch back to modbus
nrDataProcessor1.Active : = false;
nrComm1.DataProcessor := nrModbus1;
nrModbus1.Active := true;


Roman Novgorodov
DeepSoftware llc