par Paul Smart | Mis à jour le : 04/07/2016 | Commentaires : 24
Saviez-vous que vous pouviez transformer votre centrale d'acquisition de données Campbell Scientific en une esclave Modbus TCP/IP ? Savez-vous pourquoi c'est une bonne idée ? Les centrales de mesure de Campbell Scientific sont couramment utilisées comme des automates Modbus esclaves. Cela signifie que la centrale d'acquisition de données est configurée pour mettre en œuvre le protocole de communication Modbus et répondre aux requêtes Modbus d'un appareil Modbus client, comme un SCADA (supervisory control and data acquisition) du système. Transformer votre centrale de mesure en serveur Modbus TCP/IP est un excellent moyen pour permettre aux systèmes qui utilisent le protocole Modbus d'avoir accès à vos données de mesure en direct.
Pour mieux comprendre comment cela fonctionne, nous allons vous montrer un exemple d'exercice, afin de vous faire découvrir les concepts de base pour mettre en œuvre le protocole Modbus sur une centrale d'acquisition de données CR1000. Nous allons utiliser une centrale de mesure CR1000 connectée à un système SCADA. Vous pouvez relire notre précédente page sur les systèmes SCADA et le Modbus dans l'article du blog ''Introduction au Modbus".
Dans notre exemple, la CR1000 est programmée pour mesurer la tension de la batterie, la température du bornier, et une mesure analogique dans un programme simple comme indiqué ci-dessous :
'Programme pour une centrale de mesure CR1000 'Déclaration des variables Public Public PTemp, batt_volt, analog_meas 'Définition des tables de données DataTable (Table1,1,-1) DataInterval (0,10,Min,10) Minimum (1,batt_volt,FP2,0,False) Average (1,PTemp,FP2,False) Average (1,analog_meas,FP2,False) EndTable 'Programme principal BeginProg Scan (1,Sec,0,0) 'Mesure la température du bornier de la centrale de mesure PanelTemp (PTemp,250) 'Mesure la tension de la batterie Battery (batt_volt) 'Mesure une tension analogique VoltSe (analog_meas,1,mV5000,1,1,0,_60Hz,1.0,0) 'Appel de la table pour le stockage des données CallTable Table1 NextScan EndProg
Dans notre exemple, la centrale d'acquisition de mesures CR1000 est connectée à un système de supervision en utilisant une Interface Ethernet NL121. Par conséquent, nous avons besoin de programmer votre centrale d'acquisition de données pour recevoir les requêtes Modbus sur le port de communication approprié et de répondre en envoyant les données mesurées les plus récentes. Pour faire cela, nous avons besoin de l'instruction ModbusServer(), de déclarer un tableau de variables pour contenir nos données Modbus, puis mettre à jour ce tableau avec les mesures.
Ceci est réalisé en utilisant le code ci-dessous :
'Programme pour une centrale de mesure CR1000
'Déclaration des variables Public
Public PTemp, batt_volt, analog_meas
Public ModbusVariable(3)
Public DummyVar As Boolean
'Data Table Definition
DataTable (Table1,1,-1)
DataInterval (0,10,Min,10)
Minimum (1,batt_volt,FP2,0,False)
Average (1,PTemp,FP2,False)
Average (1,analog_meas,FP2,False)
EndTable
'Programme principal
BeginProg
'Configuration de la centrale de mesure en server Modbus
ModbusServer (502,115200,1,ModbusVariable,DummyVar,0)
Scan (1,Sec,0,0)
'Mesure la température du bornier de la CR1000
PanelTemp (PTemp,250)
'Mesure la tension de la batterie
Battery (batt_volt)
'Mesure une tension analogique
VoltSe (analog_meas,1,mV5000,1,1,0,_60Hz,1.0,0)
'Affectation des registres Modbus
ModbusVariable(1) = PTemp
ModbusVariable(2) = batt_volt
ModbusVariable(3) = analog_meas
'Appel de la table pour le stockage des données
CallTable Table1
NextScan
EndProg
Remarque : pour la compréhension du programme, les accents ont été rajoutés
dans les commentaires. Dans l'éditeur CRBasic, il n'est pas possible d'ajouter
des accents dans les commentaires.
Jetons un coup d'œil de plus près à l'instruction ModbusServer() que nous avons ajouté au programme. L'instruction a été ajoutée entre BeginProg et l'instruction Scan. L'instruction ModbusServer() est placée entre ces deux instructions, car elle ne doit s'exécuter qu'une fois au moment de la compilation plutôt que d'être exécutée pendant chaque échantillonnage ou scrutation (Scan).
L'instruction ModbusServer() contient les 6 paramètres suivants :
ModbusServer (COMPort,BaudRate,ModbusAddr,ModbusVariable,BooleanVar,ModbusOption)
Pour mémoire, dans notre programme, notre instruction avec les paramètres ressemble à ceci :
ModbusServer (502,115200,1,ModbusVariable,DummyVar,0)
Jetons un coup d'oeil de plus près à ces paramètres et ce qu'ils signifient :
Registres Modbus | Description des mesures | Unités |
1,2 |
Température du bornier du Datalogger |
Degrés Celsius |
3,4 |
Tension batterie du Datalogger |
Volts |
5,6 |
Mesure analogique |
Millivolts |
L'exemple ci-dessus décrit la façon dont vous pouvez accomplir une implémentation simple serveur Modbus TCP/IP par la programmation d'une centrale d'acquisition de données CR1000 dans CRBasic. Veuillez noter que l'éditeur de programme Short Cut a aussi la possibilité de générer le code ci-dessus. En tirant parti des concepts présentés ci-dessus, vous pouvez ajouter d'autres mesures à votre programme, ainsi que la carte Modbus de votre centrale de mesure. Le résultat est que votre système SCADA peut accéder aux données de mesure en direct pour recevoir les données d'une station météo, ou d'un système de mesure d'ouvrage d'art pour le génie civil.
Vous pouvez vous attendre à un autre article du blog à l'avenir avec plus de détails sur des sujets Modbus spécifiques, les pièges courants et les meilleures pratiques. Pendant ce temps, partager vos commentaires et vos questions sur le Modbus ci-dessous.
Commentaires
raichlebw | 10/05/2016 at 05:41 PM
Hi,
I've been trying to set up a Modbus TCP server on a CR1000 with no success so far. I'm testing the server with an Obvius Acquisuite 8810 Modbus TCP client, which has not yet established communition with the logger/server. We're pretty good with Modbus here, but not as good with network communication.
The questions...
1) With the ComPort parameter of ModbusServer set to 502, to which physical port should the NL121 be attached? I assume it's the RS-232 port. It's interestinng that, whichever of the 2 possible answers (RS-232, CS I/O) is the case, there will be Modbus TCP transmitted over a serial cable.
2) With the ComPort parameter of ModbusServer set to ComRS232, is the CR1000 a Modbus RTU server? This must be the case to avoid ambiguity with the TCP server, but I've seen no mention of RTU in any Campbell literature.
Thanks,
Brian
Paul Smart | 10/06/2016 at 03:23 PM
Hi Brian,
Are you using an NL201 rather than an NL121? An NL121 will only connect to the peripheral port of the datalogger, whereas an NL201 can connect to the RS-232 port or the CSI/O port of the datalogger.
If you are using an NL201, then you will need to configure the NL201 either in bridge mode or as a Modbus TCP gateway. If you configure it as a Modbus TCP gateway, then your datalogger will need to use the appropriate port (RS232 or CSI/O) and will function as an RTU. If the NL201 is set up in bridge mode you will connect it to the CSI/O port of the datalogger and use port 502 in the ModbusServer instruction. RTU vs Modbus TCP/IP is determined by the port selection in the ModbusServer instruction. Make sure baud rates and ports in the ModbusServer instruction match the settings of the NL201.
I would recommend taking a look at the settings for the NL201 using Device Configuration Utility.
Please refer to the helps in Device Configuration Utility for information on the options available. The helps explain all of this a lot better than I just did :)
I hope this helps,
-Paul
ariklee | 02/23/2018 at 04:25 PM
Hi Paul, couple questions making CR1000x function as Modbus server over Ethernet:
1. Is port 502 set by the Modbus client? Should I verify with the client that they are indeed using 502, or can that not be changed?
2. Your ModbusCoil parameter is a single value boolean, while in Campbell's Application Note on Modbus Server, they use an 8-value boolean array. I'm a bit confused on this. (In my application, the client should not be sending any commands 01, 02, 05, or 15. Does it matter then?)
3. Can you recommended any modbus client simulators for Windows 10 (besides Modbus Poll)?
Paul Smart | 02/28/2018 at 08:08 PM
Hi Ariklee,
Port 502 is the default port that is typically used. The datalogger can use other ports, but you will need to confirm with the client that it is a match to the port that the datalogger is using.
You can use the 8-value boolean array if you are expecting the client to set those coils in the datalogger. However, in my program I was not expecting this, so I simply used a single value. The only reason to do this was to avoid a warning when I compile the program. If you are not using these coils, then it does not matter.
I've spoken to some of our customers that use ModScan as an alternative to Modbus Poll, but have not used it myself.
-Paul
Geoprojektas | 03/11/2018 at 01:39 AM
Dear Paul,
Regarding ModBUS standard, measurements are stored in the Server device in four different tables:
Device address: Description:
1...10000 Coils outputs
10001...20000 Coils inputs
30001...40000 Input registers
40001...50000 Holding registers
Where will store the measurements ModbusRegisters() in your program?
On 40001-40006 registers?
Thanks,
Gintaris
Paul Smart | 03/12/2018 at 08:22 AM
Hi Gintaris,
Yes, that is correct. The measurements will also populate the Input Registers.
-Paul
Geoprojektas | 03/13/2018 at 09:25 AM
Thanks, Paul
SteveA | 07/24/2018 at 05:42 PM
Paul,
You mention at the end of the article that the modbus code can be generated using ShortCut. I've given it a first try, but haven't been able to see anyway to do that with ShortCut. Is there something obvious I'm missing?
-Steve
Anas Zaatreh | 01/27/2019 at 01:07 PM
Hi Paul,
Is it possible to configure CR1000x as Modbus TCP Client?
GaryTRoberts | 02/04/2019 at 09:17 AM
Anas,
Yes, the CR1000X can be set up as a Modbus TCP Clientr. Instead of using a ComXXX for the ComPort parameter for the ModBusClient() instruction, you would use the handle of the socket created with TCPOpen().
ctorregrosa | 04/15/2020 at 06:19 PM
Hello,
I have the CR300 and I tried the sample code for Modbus Server described in: https://help.campbellsci.com/crbasic/cr300/#Instructions/ and it works correctly.
The problem is that the instructions in the manual and the web do not correctly explain which registers are the registers to consult the Modbus Server.
The solution I found was to load the Modbus Client example and review the device query.
Finally, the code that worked for me for:
ModbusServer (ComRS232,19200,3, ModIn (), Port ())
and obtaining 2 parameters was:
03030000000445EB
03: Address
03: Function -> holding registers
00000004: two parameters
445EB: CRC
ModbusServer's response was:
03030800000000797A41B896C8
03: Address
03: Function -> holding registers
08: Msg Length -> 8 bytes
00000000: (Mid-Little Endian (CDAB)) -> 00000000 (IEEE 754): 0.0000 (voltage) no connected =)
797A41B8: (Mid-Little Endian (CDAB)) -> 41B8797A (IEEE 754): 23.0593 (temperature)
96C8: CRC
I hope this serves others with the same doubt.
Anas Zaatreh | 12/20/2020 at 07:23 AM
Hi Paul,
Is there any limition for the number of tags when using CR1000x as modbus client? i have 1600 tags to read from modbus rtu.
Robin D | 12/22/2020 at 01:57 PM
Thanks, Anas, for your question. Our knowledgeable folks here shared this response: 1600 tags won't hit a hard limit. Memory would be the only hard limit, but it's higher than 1600. The time it takes to transfer that many data values will limit how often data can be updated.
Haidar | 02/28/2023 at 05:24 PM
I am getting error reading register value.
I used cr1000 datalogger rs232 protocol using Arduino mega to fetch the data from datalogger. How can I resolve this issue?
Seth Berger | 02/28/2023 at 06:06 PM
Hi Haidar,
Modbus communication problems can result from a number of issues. If your modbus result code is incrementing upward, most commonly mistmatches in the baud rate or the data format (number data bits, stop bit, parity) are the cause of the error.
For troubleshooting assistance, I believe it would be helpful to gather more information such as the datalogger program. I would recommend that you either contact your local Campbell Scientific office or submit an e-mail support request through our website.
https://www.campbellsci.com/questions?qtype=2
Haidar | 03/06/2023 at 05:19 AM
@seth Berger
Do you have a program to fetch the mateorological data using Arduino mega with max 3232?
Haidar | 03/06/2023 at 05:01 PM
How to access cr1000 datalogger through Arduino mega or any microcontroller??
And How I can give password to the datalogger so that it identify and accept it and begins communication to fetch the mateorological data from Campbell scientific cr1000??
Seth Berger | 03/07/2023 at 12:21 AM
Hi Haidar,
We unfortunately do not have an example program for setting up Modbus communications with an Arduino max 3232 device. Since this is an application specific question that will require sharing your program and other information, I recommend you contact our technical support team directly. You can submit a web request by following the link below.
https://www.campbellsci.com/questions?qtype=2
Ahjoo Engineering | 09/27/2024 at 02:59 AM
Are Data Loggers also allowed to connect to multiple SCADA systems?
jballs | 09/27/2024 at 04:38 PM
Hello Ahjoo Engineering,
Yes, you can connect the data logger to multiple SCADA systems. You would need to use a ModbusServer() instrction for each SCADA connection in your data logger program.
Ahjoo Engineering | 10/02/2024 at 06:37 AM
Is it possible to connect multiple SCADA systems to a single data logger?
The function used within the data logger is 'ModbusSlave(502, 9600, 1, ModbusRegisters(), 0)'.
jballs | 10/02/2024 at 03:22 PM
Hello Ahjoo Engineering,
Yes, that is correct. Each connection will need to have its own ModbusSlave() instruction.
Ahjoo Engineering | 10/03/2024 at 11:43 PM
Thank you for your response. I have an additional question.
Should the program be designed to allow connections by port as shown below?
'Configure the datalogger as a Modbus Server
ModbusSlave (502,9600,1,ModbusRegisters(),0) '// For Siemens(Andritz) PLC
ModbusSlave (503,9600,1,ModbusRegisters(),0) '// For Warnning System
Is it impossible to implement a configuration where multiple SCADAs can connect via Port 502?
jballs | 10/04/2024 at 02:57 PM
Hello Ahjoo Engineering,
Yes, you can have multiple Modbus connections on the same port (502). You would want to set up the Modbus address to be unique for each connection.
I would suggest that you call support at the Campbell Scientific office closest to you for additional programming questions that can be answered quicker for you.
Please log in or register to comment.