﻿#VB
'rem Modified Apr/11/2023 by CNC4PC

Dim  Set_Point as string, Set_Point_Screen as string, delay_thc as string, Histeresys as string, Histeresys_Screen, Divider, Anti_dive as string
Dim  Readvalue as ushort, Auto_Set_Point_Button as string, Test_Mode_Button, Divider_Screen, Firmware,Analog_Smoothing,Analog_Smoothing_Screen, vOut as string


'*****************************  Set_poin_send *****************************

if AS3.Getbuttonstate(21001) = True then

if exec.GetModbusregister(201,Readvalue) then

AS3.Setfield(Readvalue, 20004)
end if
else
Set_Point_Screen = AS3.Getfield(20004)
if Set_Point_Screen <> " " then
exec.SetModbusregister(213, Set_Point_Screen)
end if
end if

'*****************************  Histeresys send *****************************
Histeresys_Screen = AS3.Getfield(20007)
if Histeresys_Screen <> " " then
exec.SetModbusregister(211, Histeresys_Screen)
end if

'*****************************  Auto_Set_Point_Button *****************************
if AS3.Getbuttonstate(21001) = false then
       exec.SetModbusregister(212, 0)
else
       exec.SetModbusregister(212, 1)
end if

'*****************************  Test_Mode_Button *****************************
if AS3.Getbuttonstate(128) = true then
 if AS3.Getbuttonstate(21002) = true then
    AS3.Switchbutton(false, 21002)
    end if
end if


if AS3.Getbuttonstate(21002) then

  exec.SetModbusregister(214, 1)
  if AS3.Getbutton(21003) then
     AS3.SetLED(true, 500)
     exec.SetModbusregister(216, 1)
  else
     exec.SetModbusregister(216, 0)
     AS3.SetLED(false, 500)
  end if
   
   if AS3.Getbutton(21004) then
      AS3.SetLED(true, 501)
      exec.SetModbusregister(215, 1)
  else
      exec.SetModbusregister(215, 0)
      AS3.SetLED(false, 501)
   end if
   
else
    exec.SetModbusregister(214, 0)
   exec.SetModbusregister(215, 0)
   exec.SetModbusregister(216, 0)
   AS3.SetLED(false, 500)
   AS3.SetLED(false, 501)
end if

'*****************************  Delay_time_send  *****************************
  

if AS3.Getbuttonstate(535) = True then
     exec.SetModbusregister(210, 0)
else
     delay_thc = AS3.Getfield(234)
	 if delay_thc <> " " then
     exec.SetModbusregister(210, delay_thc*10)
	 end if
end if

'*****************************  Arc voltage recived *****************************

if exec.GetModbusregister(200,Readvalue) then
  if Readvalue < 505 then
  AS3.Setfield(Readvalue, 20005)
  else
  Readvalue = 0
  AS3.Setfield(Readvalue, 20005)
  end if
end if

'*****************************  Firmware recived *****************************

if exec.GetModbusregister(202,Readvalue) then
    if Readvalue < 1 then
	   Firmware = "" 
	   AS3.Setfieldtext(Firmware, 20000)
	   else
	    Firmware = "FF6-V" & Readvalue
	   AS3.Setfieldtext(Firmware, 20000)
	end if	
end if

'*****************************  Divider send *****************************
Divider_Screen = AS3.Getfield(20008)
if Divider_Screen <> " " then
exec.SetModbusregister(217, Divider_Screen)
end if

'*****************************  Analog_Smoothing send *****************************
Analog_Smoothing_Screen = AS3.Getfield(20009)
if Analog_Smoothing_Screen <> " " then
exec.SetModbusregister(218, Analog_Smoothing_Screen)
end if

'*****************************  Anti_dive send *****************************
Anti_dive = AS3.Getfield(20011)
if Anti_dive <> " " then
exec.SetModbusregister(219, Anti_dive)
end if