Forum Home › Forums › Development and Integration › How do I send setup data to Modbus device
- This topic has 12 replies, 3 voices, and was last updated 4 weeks ago by
Mikhail.
-
AuthorPosts
-
January 20, 2025 at 1:57 pm #16060
詹森
ParticipantHello, I would like to ask, how to achieve in the script, to write data to the Modbus device, for example: set the Modbus device to issue and write a value, the use of function code is 0x10/0x06 I would like to ask how to achieve this?
January 20, 2025 at 2:14 pm #16062詹森
ParticipantSendCommand(cmd, EnableAll);
I tried to use this method, but it can’t be used directly in the script. Is there any way to call it directly, send the data to the Server, and the Server sends the data to the Modbus device? Thank you very muchJanuary 20, 2025 at 2:22 pm #16063詹森
Participanthttps://github.com/njzsky/Public/blob/main/Command.png?raw=true
In the figure, how do I implement the send command function in the script
January 21, 2025 at 1:57 am #16064詹森
ParticipantCmdData byte[] Command data transmitted to Server
I tried to use this variable, I assigned it a value, and the result indicated that it is read-only, this I can’t find how to implement sending values directly from the script to the Modubs device, what to do? I need help. Thank you!
error CS0200: Property or indexer ‘CalcEngine. CmdData’ cannot be assigned to — it is read only
January 21, 2025 at 6:05 am #16069manjey73
ParticipantJanuary 21, 2025 at 6:16 am #16072manjey73
Participant// Recording the date in the EKF PLC (Haiwell) is an example public byte[] WriteDt() { DateTime dt = DateTime.Now; var year = BitConverter.GetBytes((ushort)dt.Year); byte[] cmdData = new byte[14] {0, 0, // Регистр года 0, (byte)dt.Month, 0, (byte)dt.Day, 0, (byte)dt.Hour, 0, (byte)dt.Minute, 0, (byte)dt.Second, 0, 1}; // команда на запись в PLC cmdData[0] = year[1]; cmdData[1] = year[0]; return cmdData; }
If you need to return bytes, you can look at this example. A multiple command is created in the Modbus Device (entry code 16 – 0x10)
January 21, 2025 at 7:24 am #16074詹森
ParticipantMaybe I wasn’t clear, so let me redescribe it
I now need to set the data to the service. I assigned a value to CmdData in the script code, but I got an error
Now I can’t find a way to write data to the service in the script (to send the data to the communication bus)
You are talking about the code of the package, what I need is how to write the data of the script to the service
January 21, 2025 at 7:49 am #16076manjey73
ParticipantIt’s not entirely clear what you want. Describe what kind of Modbus device and what exactly needs to be sent to it? Take screenshots for understanding.
By returning byte[] from the output formula, you are sending CmdData to the device, that is, replacing it with the one you need.
January 21, 2025 at 11:38 am #16079詹森
ParticipantWhat I’m trying to do now is
For example, channel1 is the channel ID of the real device. I can directly set the command in the View on the Web, and the command value is automatically written to the service
The operation is shown as follows (after clicking On/Off, the value can be written to the service) :https://raw.githubusercontent.com/njzsky/Public/refs/heads/main/Command2.pngSetData(channel1, 1, 1); // If I write this in the script, I just write 1 in channel1, not in the service
Now I need to use the script code in Configuration Darabase — Secondary Table –Scripts to implement that the data written to channel1 can be written to the service
Thanks & Regards
January 21, 2025 at 12:21 pm #16083manjey73
ParticipantFor a channel to be written to the device, it must be Input/Output or Output
And yet, scripts cannot access writing to the device without your participation or without the participation of the auto-control Module.
January 21, 2025 at 12:23 pm #16084manjey73
ParticipantShow the Modbus settings for this command, an example of which you showed in the screenshot.
January 21, 2025 at 2:36 pm #16086Mikhail
ModeratorHello,
Try Automatic Control Module for sending commands.January 21, 2025 at 2:36 pm #16087Mikhail
ModeratorCommands cannot be sent by a script. Commands can be sent by a module.
-
AuthorPosts
- You must be logged in to reply to this topic.