Hello Guest it is April 26, 2024, 07:13:04 AM

Author Topic: Modbus control huanyang GT vfd  (Read 3911 times)

0 Members and 1 Guest are viewing this topic.

Re: Modbus control huanyang GT vfd
« Reply #40 on: November 07, 2021, 12:56:01 PM »
Hi,
the macro is not really a means of changing the speed, it would have to run multiple times a secoond to do that, the macro is so you
can step through it one instruction at a time until you can understand what it does. Have you tried single stepping?

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Modbus control huanyang GT vfd
« Reply #41 on: November 07, 2021, 01:01:22 PM »
Hi,
I can see one mistake:
the path is not modbus0/wrtvfdspeed it is:
modbus0/function2/wrtvfdspeed0

Change the path in the macro and single step through it.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Modbus control huanyang GT vfd
« Reply #42 on: November 07, 2021, 01:11:00 PM »
Hi,
this is a classic case where I did not consult the register diagnostic and thus had the wrong path......and the path must be EXACTLY character
for character correct.

When you single step through the code and the once the local 'registerHandle=mc.mcRegGetHandle(mInst,"modbus0/wrtvfdspeed")'
statement executes hover the cursor over 'registerHandle' and the editor should display the value.....does the number displayed look like a genuine
memory address? If it does then the chances are that the statement has executed correctly if not then it has not found the correct handle ie the
path is STILL not correct.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Modbus control huanyang GT vfd
« Reply #43 on: November 08, 2021, 02:04:47 PM »
Hi Joe,
  unfortunately the path does not include the 'function0', but i tried it anyways and still the same :(
Re: Modbus control huanyang GT vfd
« Reply #44 on: November 08, 2021, 06:23:59 PM »
Hi,
have you single stepped through the code?

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Modbus control huanyang GT vfd
« Reply #45 on: November 08, 2021, 06:28:20 PM »
Hi,
the whole point about putting the code in a macro IS NOT TO EFFECT THE SPEED.....it is a means for you put put the code
in a 'sandbox' so you can play with it until you understand it and get it to work, just throwing random corrections at the code will not do it.

Double check the Register Diagnostics, it shows that function2 Is included in the path.......what evidence do you use to support the contention that its
not part of the path?

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Modbus control huanyang GT vfd
« Reply #46 on: November 14, 2021, 01:38:24 PM »
Hi,
the whole point about putting the code in a macro IS NOT TO EFFECT THE SPEED.....it is a means for you put put the code
in a 'sandbox' so you can play with it until you understand it and get it to work, just throwing random corrections at the code will not do it.

Double check the Register Diagnostics, it shows that function2 Is included in the path.......what evidence do you use to support the contention that its
not part of the path?

Craig
If you check the tree, the path is modbus0/wrtvfd..... etc.  I got the code finally working with the help of James, massive thankyou! i will post the working version here
Code: [Select]
-----------------------------------------------------------------------------
--   Name: PMC Module
--Created: 03/27/2015
-----------------------------------------------------------------------------
-- This is auto-generated code from PmcEditor. Do not edit this file! Go
-- back to the ladder diagram source for changes in the logic

-- U_********* symbols correspond to user-defined names. There is such a symbol
-- for every internal relay, variable, timer, and so on in the ladder
-- program. I_********* symbols are internally generated.

local VFD_Spindle_controller = {}

local hReg, hSig, rc
local mInst = 0

-- Generated function for MachAPI.
local function Read_Register(path)
    hReg, rc = mc.mcRegGetHandle(mInst, path)
    if (rc == mc.MERROR_NOERROR) then
        local value, rc = mc.mcRegGetValue(hReg)
        if (rc == mc.MERROR_NOERROR) then
            return value
        end
    end
    return 0
end

-- Generated function for MachAPI.
local function Write_Register(path, value)
    hReg, rc = mc.mcRegGetHandle(mInst, path)
    if (rc == mc.MERROR_NOERROR) then
        rc = mc.mcRegSetValue(hReg, value)
        if (rc == mc.MERROR_NOERROR) then
            return
        end
    end
    return
end

-- Generated function for MachAPI.
local function Read_Signal(path)
    hSig = 0
    rc = mc.MERROR_NOERROR
    hSig, rc = mc.mcSignalGetHandle(mInst, path)
    if (rc == mc.MERROR_NOERROR) then
        local state = 0;
        state, rc = mc.mcSignalGetState(hSig)
        if (rc == mc.MERROR_NOERROR) then
            return state
        end
    end
    return 0
end

-- Generated function for MachAPI.
local function Write_Signal(path, v)
    hSig = 0
    rc = mc.MERROR_NOERROR
    hSig, rc = mc.mcSignalGetHandle(mInst, path)
    if (rc == mc.MERROR_NOERROR) then
        mc.mcSignalSetState(hSig, v)
    end
end

-- Generated function for signal read.
local function Read_U_b_FSpindle_CW()
    return Read_Signal(1142)
end

-- Generated function for signal read.
local function Read_U_b_FSpindle_CCW()
    return Read_Signal(1143)
end

-- Generated function for signal read.
local function Read_U_b_FSpindle_ON()
    return Read_Signal(1141)
end

-- Call this function to retrieve the PMC cycle time interval
-- that you specified in the PmcEditor.
function VFD_Spindle_controller.GetCycleInterval()
    return 10
end


-- Call this function once per PLC cycle. You are responsible for calling
-- it at the interval that you specified in the MCU configuration when you
-- generated this code. */
function VFD_Spindle_controller.PlcCycle()
    --mInst = mc.mcGetInstance()

    if     (Read_U_b_FSpindle_CCW() == 0 and Read_U_b_FSpindle_CW() == 1 and Read_U_b_FSpindle_ON() == 1) then
       Write_Register("modbus0/wrtvfdcmd0", 1)
    elseif (Read_U_b_FSpindle_CCW() == 1 and Read_U_b_FSpindle_CW() == 0 and Read_U_b_FSpindle_ON() == 1) then
       Write_Register("modbus0/wrtvfdcmd0", 2)
    else --if Read_U_b_FSpindle_ON() == 0) then
       Write_Register("modbus0/wrtvfdcmd0", 5)
    end

    local registerHandle=mc.mcRegGetHandle(mInst,"modbus0/wrtvfdspeed0")
local commandedSpeed=mc.mcSpindleGetCommandRPM(mInst)
-- mc.mcCntlSetLastError(mInst, tostring(commandedSpeed))
local registerValue=(commandedSpeed/12000)*10000
mc.mcRegSetValue(registerHandle,registerValue)
end

return VFD_Spindle_controller

The big problem was for some reason the register was not getting written. Maybe an internal mach problem
« Last Edit: November 14, 2021, 01:41:09 PM by barneskite28 »