Page 2 of 4

Re: PIC AS MODBUS SLAVE

Posted: Thu Jan 12, 2017 11:37 am
by Benj
Hello,

I'm afraid the Modbus slave component will only work with Flowcode v7. If you already have a v6 license then you get a significant discount on the price of the v7 license.

Re: PIC AS MODBUS SLAVE

Posted: Tue Feb 14, 2017 11:47 pm
by SILVESTROS9
Hello to all!
I made some tests of code that I post below, and works fine as modbus slave. With a modbus master emulator I send characters one by one to an LCD 4X20 , using modbus command 6 (Write Single Register). The problem is , when I try to send a string of characters , 20 or more , there is a delay (about 1 sec. per character) to display. That is not practical especially if I want to use whole capacity of LCD (80 characters). The modbus command to send a long string of characters is 16 (Write Multiple Registers).When I use modbus command 16 to send a string with the modbus master emulator I receive an error. I noticed that at FLOWCODE7 modbus slave component there is no a parameter for multiple registers . Would you like to inform me how many characters can I send as string , and how can I do that, to use whole area of LCD . Thanks.

Re: PIC AS MODBUS SLAVE

Posted: Wed Feb 15, 2017 12:59 pm
by Benj
Hello,

Right I have now added support for the WriteMultipleRegisters command. Previously it was not supported in the slave code.

The command should now support up to 20 registers to be set in a single transaction.

Let me know how you get on.
ModbusSlave.fcpx
(89.97 KiB) Downloaded 464 times

Re: PIC AS MODBUS SLAVE

Posted: Wed Feb 15, 2017 5:04 pm
by SILVESTROS9
Many thanks Benj,
I made a copy of ModbusSlave.fcpx to components directory of FLOWCODE7, but there is no WriteMultipleRegisters command in the ModbusSlave component. Is there something wrong with the update ? How can I check that, and what modifications must be done in ModBus_Slave_LCD_4-DEMO.fcfx to work with WriteMultipleRegisters command from the modbus master?

Re: PIC AS MODBUS SLAVE

Posted: Wed Feb 15, 2017 6:22 pm
by Benj
Hello,

The WriteMultipleRegisters command is now supported as part of the CheckForIncoming macro. So hopefully no modifications are required for your program other then to re-compile and program.

Re: PIC AS MODBUS SLAVE

Posted: Wed Feb 15, 2017 10:23 pm
by SILVESTROS9
Thanks Benj ,
I'll make some tests to confirm .

Re: PIC AS MODBUS SLAVE

Posted: Mon Feb 27, 2017 7:42 pm
by SILVESTROS9
Hello to all!
After last modification of the code to support Modbus command 16 (WriteMultipleRegisters), I made some tests with an LCD 4x20 as slave. I send 2 requests to the slave for 2 and 20 characters. As master I use a PLC TM221C24R (SCHNEIDER) and a master emulator ComTestPro .The results are below:
1. Test with PLC
Send 2 characters( 2,3 ) at Slave 01 with start address 07
DATA OUT [hex]
[01] [10] [00 07] [00 02] [04] [00 32] [00 33] [53 93]
DATA IN [hex]
[01] [10] [00 09] [00 02] [91 CA]
No data on lcd . PLC shows communication error. Maybe there is a response error . As it seems at DATA IN, start address is wrong [00 09], so the CRC is no valid.

Send a string of 20 characters at Slave 01 with start address 07
DATA OUT [hex]
[01] [10] [00 07] [00 14] [ 20 ch. data......... ] [3C 86]
DATA IN [hex]
[01] [10] [00 1B] [00 14] [80 01].
No data on LCD. PLC shows communication error . The same problem with start address at DATA IN ( [00 14] instead of [00 07] ) .

2. Test with master emulator ComTestPro
At that case, with the same requests as with PLC above , the LCD shows some characters , but the emulator panel shows no valid response error , and the DATA IN, DATA OUT are the same as at test with PLC .
I think that there is a problem with response data, maybe at code for modbus command 16. Is there a way to solve this?
Below I post the latest code.
Thanks!

Re: PIC AS MODBUS SLAVE

Posted: Tue Feb 28, 2017 6:36 am
by EtsDriver
Is the slave answering right ?

Re: PIC AS MODBUS SLAVE

Posted: Tue Feb 28, 2017 1:48 pm
by Steve001
Hi

as ets driver stated is the slave answering correctly ?

I would test first with your emulator and get it working with that as PLC's are notorious for having problems with MODBUS interfaces and not being able to communicate with the required number of devices on the loop or the distance or both !

steve

Re: PIC AS MODBUS SLAVE

Posted: Tue Feb 28, 2017 4:16 pm
by EtsDriver
Hi!

Sorry, did not notice you had allready shown that the response is wrong!

It seems that the modbus slave is answering in wrong format to the master...

I built your system in eblocs friendly way to my desk and tested out with RS485 using modbus poll program:

I write 0x0032 to register 40007 and 0x0033 to register 40008 and my display shows number 23 on the first line.

The sent data is:
01 | 10 | 00 06 | 00 02 | 04 | 0032 | 0033 | 925F

SlaveID | Function | Start address | registers to write | databytes to follow| data1 | data2 | CRC |
(address given in plc base1 7 = 6)

Response is the 01 10 00 08 00 02 C0 0A, and the data changes on the display of mine, but modbus poll shows that it gets response error.

Response to this should be 01 10 00 06 00 02 A1 C9

Re: PIC AS MODBUS SLAVE

Posted: Tue Feb 28, 2017 7:47 pm
by SILVESTROS9
Thanks to all for your help!
As I stated in my previous post, my target is to use the code to send some messages from a PLC to a number of LCD's . When I use an emulator there is no problem for displaying the characters, although there is a response error. That is only for communication test and checking data , but in reality, a PLC use more accurate diagnostics for communication protocols. So far I can't send any data from the PLC to LCD with modbus protocol. I think that the problem is at code , because when I use the same PLC to send characters to a MODBUS LCD 4X20 ( SC2004MBS-SILICON CRAFT ) , that LCD works well. I noticed that the PLC after sending the message to LCD, wait some seconds, make some diagnostics to serial line data and after that, enable the communication. This waiting time there is no at master emulator. Also , checking all the response data, I noticed that the wrong START ADDRESS is the sum of correct START ADDRESS and QUANTITY OF REGISTERS . I will continue the tests with different pairs PLC-LCD.

Re: PIC AS MODBUS SLAVE

Posted: Tue Feb 28, 2017 7:58 pm
by EtsDriver
What kind of diagnostics the plc runs on serial line? Does it do modbus diagnostic command to your DIY modbus display or does it use some kind of REPORT-SLAVE-ID (command 17) as diagnostics??

Re: PIC AS MODBUS SLAVE

Posted: Tue Feb 28, 2017 10:13 pm
by SILVESTROS9
I have a hardware guide only for that PLC . Maybe the PLC use some kind of diagnostic command, maybe not. I suppose that, observing the relatively long time to enable communication at serial line. However, I think that the problem is not at PLC that works well with any modbus display.

Re: PIC AS MODBUS SLAVE

Posted: Tue Feb 28, 2017 11:45 pm
by EtsDriver
Oh it could be the timeout when no correct answer is received, on some systems those are very long... Hope Matrix gets the response fixed asap so you can get it working correctly!

Re: PIC AS MODBUS SLAVE

Posted: Thu Mar 02, 2017 4:49 pm
by Benj
Hello,

Many thanks for letting us know of the problem. I have found and hopefully fixed the problem in the attached component.
ModbusSlave.fcpx
(89.99 KiB) Downloaded 348 times
Let me know how you get on.

Re: PIC AS MODBUS SLAVE

Posted: Fri Mar 03, 2017 12:18 pm
by SILVESTROS9
Thanks Benj for your help.
Now the response code is correct, but I have no data on LCD when send a modbus command from the PLC. I continue the tests to find the reason.

Re: PIC AS MODBUS SLAVE

Posted: Tue Mar 14, 2017 1:14 am
by SILVESTROS9
Hello to all and thanks in advance for any help!
I made some tests about to send characters from a PLC to an LCD 4X20. When I set Quantity (is the the total number of characters that I want to sent) up to 20 , I have the correct characters at LCD ,when the FirstObj is the start address for the string. But when I set Quantity more than 20 , I have no data at LCD . The communication is ok, because there is no error, but the busy output is on at execute window. Generally, I can display only 20 characters, while I try to send more than 20. What do you think about that , the problem is about timing , or parameter modification of pic code /plc code ?

Re: PIC AS MODBUS SLAVE

Posted: Tue Mar 14, 2017 11:03 am
by Benj
Hello,

In your Flowcode Modbus Slave program what is the Receive Buffer Size property set to? This sets how much data can be received in a single message and therefore how much memory to reserve. The default is 20 bytes.
MbSlave.jpg
MbSlave.jpg (11.17 KiB) Viewed 22643 times

Re: PIC AS MODBUS SLAVE

Posted: Tue Mar 14, 2017 4:59 pm
by SILVESTROS9
Thanks Benj ,
The Receive Buffer Size it was 20 , I set to 80 . I try to send 10 charachters per row with FirstObj = 0 and Quantity=80 from PLC. No data at display . no comm. errors , the busy is on . When I try to send data with master emulator there is no problem. The strange is that there is no communication error to help me to found the reason ,at the help-error diagnostics of PLC. Is it wrong timing parameter and for what code ? When I connect the PLC with a modbus LCD that I have ( SC200MBS 4X20 ) that LCD works fine.

Re: PIC AS MODBUS SLAVE

Posted: Fri Mar 17, 2017 1:32 am
by SILVESTROS9
Hello Benj,
in your previous post you write :

" Right I have now added support for the WriteMultipleRegisters command. Previously it was not supported in the slave code.

The command should now support up to 20 registers to be set in a single transaction. "

So far , I can display up to 20 characters on LCD , while I send more than 20 and up to 80. I have response error when I send more than 20. Is that about the limit of 20 registers that support the WriteMultipleRegisters command ? If yes , is it possible to extend that limit? If that is not possible what modification can I make to FC7 code to display up to 80 characters in one transaction? Is it possible to receive and display in 4 packets of 20 , because I can't sent more than 1 request from PLC?
Thanks in advance for your help and support.

Re: PIC AS MODBUS SLAVE

Posted: Fri Mar 17, 2017 11:42 am
by Benj
Hello,

I believe I have found and fixed the issue. The data was being read out the comms circular buffer into a local buffer which was fixed at 40 bytes or 20 registers. This variable is now dynamically sized based on your max receive buffer property setting. Ideally I would like to keep the data inside the existing circular buffer but then I can't ensure that no further communications bytes will be received while processing the command so for now I am using a new unique RAM buffer.

I have also fixed a problem where the simulation version of the CheckForIncoming had fallen behind the embedded version in terms of what was supported.
ModbusSlave.fcpx
(91.47 KiB) Downloaded 282 times
Let me know how you get on.

Re: PIC AS MODBUS SLAVE

Posted: Fri Mar 24, 2017 3:54 pm
by SILVESTROS9
Thanks Benj for your help.
Below I post the code that so far works fine. I continue the tests adding some I/O at the PIC that can be controlled from the master, and make some modifications to hardware .

Re: PIC AS MODBUS SLAVE

Posted: Mon Mar 27, 2017 12:37 am
by SILVESTROS9
Hello Benj,
Before add some I/O to PIC , I was checked with help of a master emulator (Simply Modbus Master) some modbus command that I will use . I noticed that some commands as 01 (Read Coil States ) , 02 (Read Input States) , 04(Read Analog Input) and 05(Set Coil State) shows response code error as it seems at the snap that I post. The error at response code is the same at all commands. Would you like to check if that is error at my code as slave , or at FLOWCODE7 ?

Re: PIC AS MODBUS SLAVE

Posted: Mon Mar 27, 2017 3:57 am
by EtsDriver
Have you set up the register counts for coils and analog?
FC 7 is smart and the code will answer "Illegal data adress" if it has no corresponding registers set up on components properties for that function code.
4x registers are Holding registers.

Re: PIC AS MODBUS SLAVE

Posted: Mon Mar 27, 2017 3:42 pm
by SILVESTROS9
Thanks EtsDriver, I forgot to setup component properties. After that, I have no errors in command's responses. Now I'll continue to make some tests with I/O .