0

I am configuring the DCP module for PROFINET devices and using Lua for that. My hard-coded piece of code looks like:

function dcp:setname()
    local pkt = CreateFromPath("ethernet/profinet/dcp/dcp_block_nameofstation")
    pkt.src.from_string(tc.Mac)
    pkt.dst.from_string("00:a0:45:38:20:ec")
    pkt.get_layer("profinet").frameid.from_string("0xfefd")
    local d = pkt.get_layer("dcp")
    local xid = tostring(rand()) 
    d.service_id.from_string("4")
    d.xid.from_string(xid)

    d.service_type.from_string("0")

    d.get_layer("dcp_block_nameofstation").Option.from_string("2")
    d.get_layer("dcp_block_nameofstation").SubOption.from_string("2")

    d.get_layer("dcp_block_nameofstation").BlockInfo .from_string("1")
    d.get_layer("dcp_block_nameofstation").NameOfStation.from_string("test-device")
end

I need to pass the 'test-device' as an argument and it is a string. How do I do that?

1 Answer 1

1

Add an argument to the function definition:

function dcp:setname(nameOfStation)

And use it:

d.get_layer("dcp_block_nameofstation").NameOfStation.from_string(nameOfStation)

Then, wenn calling the function, pass a value:

myDcp:setname("test-device")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.