How do I send setup data to Modbus device

Forum Home Forums Development and Integration How do I send setup data to Modbus device

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #16060
    詹森
    Participant

    Hello, 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?

    #16062
    詹森
    Participant

    SendCommand(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 much

    #16063
    詹森
    Participant

    https://github.com/njzsky/Public/blob/main/Command.png?raw=true

    In the figure, how do I implement the send command function in the script

    #16064
    詹森
    Participant

    CmdData 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

    #16069
    manjey73
    Participant

    Perhaps you need to use something like new CmdData(ххх ххх ххх) so that the Script compiler executes it correctly.

    Or use SetData or NewData

    • This reply was modified 4 weeks ago by manjey73.
    • This reply was modified 4 weeks ago by manjey73.
    #16072
    manjey73
    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)

    #16074
    詹森
    Participant

    Maybe 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

    #16076
    manjey73
    Participant

    It’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.

    • This reply was modified 4 weeks ago by manjey73.
    • This reply was modified 4 weeks ago by manjey73.
    #16079
    詹森
    Participant

    What 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.png

    SetData(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

    #16083
    manjey73
    Participant

    For 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.

    #16084
    manjey73
    Participant

    Show the Modbus settings for this command, an example of which you showed in the screenshot.

    #16086
    Mikhail
    Moderator

    Hello,
    Try Automatic Control Module for sending commands.

    #16087
    Mikhail
    Moderator

    Commands cannot be sent by a script. Commands can be sent by a module.

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.