1、判断授权码时否过期
sub short Ecu_month_day(short year,short month)
select case(month)
case 1
return 31
break
case 2
if (((year % 4) == 0)and(year % 100 <> 0)) or ((year % 400) == 0) then
return 28
else
return 29
end if
break
case 3
return 31
break
case 4
return 30
break
case 5
return 31
break
case 6
return 30
break
case 7
return 31
break
case 8
return 31
break
case 9
return 30
break
case 10
return 31
break
case 11
return 30
break
case 12
return 31
break
case else
break
end select
end sub
macro_command main()
short year,month,day
short oyear,omonth,oday
short lincesce_cir,NowLincesce_cir
short page,licence_tim
short mday
bool done,en_sw
//GetData(NowLincesce_cir, "Local HMI", "licence_CR", 1)
GetData(lincesce_cir, "Local HMI", "licence_CR", 1)
GetData(year, "Local HMI", LW, 9022, 1) //年
GetData(month, "Local HMI", LW, 9021, 1) //月
GetData(day, "Local HMI", LW, 9020, 1) //日
//获取授权时间
GetData(oyear, "Local HMI", "licence_year", 1)
GetData(omonth, "Local HMI", "licence_month", 1)
GetData(oday, "Local HMI", "licence_day", 1)
if(lincesce_cir == 0)then
//无设备编码
en_sw = 0
page = 124
SetData(page, "Local HMI", "SW_window", 1)
else if(lincesce_cir == 1)then
//无效授权
en_sw = 0
page = 121
SetData(page, "Local HMI", "SW_window", 1)
else if(lincesce_cir == 2)then
//获取当前系统时间
if(oyear > year) or ( (oyear == year)and ((omonth > month) or((omonth ==month)and(oday >= day))))then
mday = oday - day
while(year < oyear)
while(month < 12)
mday = mday + Ecu_month_day(year, month)
month = month + 1
wend
mday = mday + Ecu_month_day(year, month)
month = 1
year = year + 1
wend
while(month < omonth)
mday = mday + Ecu_month_day(year, month)
month = month + 1
wend
else
mday = oday - day
while(oyear < year)
while(omonth < 12)
mday = mday - Ecu_month_day(year, month)
omonth = omonth + 1
wend
mday = mday - Ecu_month_day(year, month)
omonth = 1
oyear = oyear + 1
wend
while(omonth <= month)
mday = mday - Ecu_month_day(year, month)
omonth = omonth + 1
wend
end if
if(mday < 1)then
//lincesce_cir = 1
page = 122 //授权过期
SetData(page, "Local HMI", "SW_window", 1)
en_sw = 0
else if((mday >= 1)and(mday < 30))then
//GetData(licence_tim, "Local HMI", "dislicence_time", 1)
GetData(page, "Local HMI", LW, 9050, 1)
if(page <> 123)then
//if(licence_tim > 10)then
page = 123 //授权将过期
SetData(page, "Local HMI", "SW_window", 1)
end if
en_sw = 1
else if(mday>=30)then
en_sw = 1
end if
else if(lincesce_cir == 8)then
en_sw = 1
end if
SetData(en_sw, "Siemens S7-200 SMART PPI", "licence_en_M", 1)
SetData(en_sw, "Local HMI","licence_en", 1)
SetData(mday, "Local HMI","licence_mod_day", 1)
//if(NowLincesce_cir <> lincesce_cir)then
// SetData(lincesce_cir, "Local HMI", "licence_CR", 1)
//end if
end macro_command
2、设置识别码
macro_command main()
char device[8]
char j_device[16]
short len
short licence_cri,page,new_licence_cr
bool done
GetData(device[0], "Local HMI", "key_device", 8)
GetData(licence_cri, "Local HMI", "licence_CR", 1)
len = StringLength(device[0])
if((len == 8)and(licence_cri == 0))then
done = 0
SetData(done, "Local HMI", "Execl_CreaDervice", 1)
SetData(device[0], "Local HMI", "licence_dervice", 8)
new_licence_cr = 1
SetData(new_licence_cr, "Local HMI", "licence_CR", 1)
page = 121
SetData(page, "Local HMI", "SW_window", 1)
else
end if
end macro_command
3、输入新的授权码
sub short Ecu_month_day(short year,short month)
select case(month)
case 1
return 31
break
case 2
if (((year % 4) == 0)and(year % 100 <> 0)) or ((year % 400) == 0) then
return 28
else
return 29
end if
break
case 3
return 31
break
case 4
return 30
break
case 5
return 31
break
case 6
return 30
break
case 7
return 31
break
case 8
return 31
break
case 9
return 30
break
case 10
return 31
break
case 11
return 30
break
case 12
return 31
break
case else
break
end select
end sub
sub bool Excule_data(short year,short month,short day)
bool ok
select case(month)
case 1
ok = (day >= 1) and (day <= 31)
break
case 2
if (((year % 4) == 0)and(year % 100 <> 0)) or ((year % 400) == 0) then
ok = (day >= 1) and (day <= 28)
else
ok = (day >= 1) and (day <= 29)
end if
break
case 3
ok = (day >= 1) and (day <= 31)
break
case 4
ok = (day >= 1) and (day < 31)
break
case 5
ok = (day >= 1) and (day <= 31)
break
case 6
ok = (day >= 1) and (day < 31)
break
case 7
ok = (day >= 1) and (day <= 31)
break
case 8
ok = (day >= 1) and (day <= 31)
break
case 9
ok = (day >= 1) and (day < 31)
break
case 10
ok = (day >= 1) and (day <= 31)
break
case 11
ok = (day >= 1) and (day < 31)
break
case 12
ok = (day >= 1) and (day <= 31)
break
case else
ok = 0
break
end select
ok = ok and ((year >= 2000) or (ok < 2999))
return ok
end sub
macro_command main()
//授权码格式
//授权时间4位年2位月2位日授权码8位校验码8位
//输入授权码,解析授权码
char jm[32] //输入授权码
char rs[32]
char js[8] //校验码
char hm[8] //授权码
char hp[8] //原码
short year,month,day
short hyear,hmonth,hday
short oyear,omonth,oday
short len
short page,year_j,month_j,licence_cir,new_licence_cr
short day_j
bool ok
ok = 0
SetData(ok, "Local HMI", "EXCULE_GetLicence", 1)
page = 0
GetData(licence_cir, "Local HMI", "licence_CR", 1)
GetData(jm[0], "Local HMI", "key_licence_code_1", 32)
GetData(js[0], "Local HMI", "licence_dervice", 8)
len = StringLength(jm[0])
if(licence_cir == 1)or(licence_cir == 2)then
if(len == 32)then
//还原授权码
ASCII2HEX(jm[0],hp[0],2 )
ASCII2HEX(jm[2],hp[1],2 )
ASCII2HEX(jm[4],hp[2],2 )
ASCII2HEX(jm[6],hp[3],2 )
ASCII2HEX(jm[8],hp[4],2 )
ASCII2HEX(jm[10],hp[5],2 )
ASCII2HEX(jm[12],hp[6],2 )
ASCII2HEX(jm[14],hp[7],2 )
ASCII2HEX(jm[30],hm[0],2 )
ASCII2HEX(jm[28],hm[1],2 )
ASCII2HEX(jm[26],hm[2],2 )
ASCII2HEX(jm[24],hm[3],2 )
ASCII2HEX(jm[22],hm[4],2 )
ASCII2HEX(jm[20],hm[5],2 )
ASCII2HEX(jm[18],hm[6],2 )
ASCII2HEX(jm[16],hm[7],2 )
hp[0] = hp[0] ^ js[0] ^ 0x66
hp[1] = hp[1] ^ js[0] ^ 0x99
hp[2] = hp[2] ^ js[0] ^ 0x66
hp[3] = hp[3] ^ js[0] ^ 0x99
hp[4] = hp[4] ^ js[0] ^ 0x66
hp[5] = hp[5] ^ js[0] ^ 0x99
hp[6] = hp[6] ^ js[0] ^ 0x66
hp[7] = hp[7] ^ js[0] ^ 0x99
ASCII2HEX(hp[4],hyear, 4)
ASCII2HEX(hp[2],hmonth, 2)
ASCII2HEX(hp[0],hday, 2)
SetData(hyear, "Local HMI", LW, 0, 1)
SetData(hmonth, "Local HMI", LW, 1, 1)
SetData(hday, "Local HMI", LW, 2, 1)
hm[0] = hm[0] ^ js[0] ^ 0x55
hm[1] = hm[1] ^ js[1] ^ 0xAA
hm[2] = hm[2] ^ js[2] ^ 0x55
hm[3] = hm[3] ^ js[3] ^ 0xAA
hm[4] = hm[4] ^ js[4] ^ 0x55
hm[5] = hm[5] ^ js[5] ^ 0xAA
hm[6] = hm[6] ^ js[6] ^ 0x55
hm[7] = hm[7] ^ js[7] ^ 0xAA
ASCII2HEX(hm[4],oyear, 4)
ASCII2HEX(hm[2],omonth, 2)
ASCII2HEX(hm[0],oday, 2)
SetData(oyear, "Local HMI", LW, 3, 1)
SetData(omonth, "Local HMI", LW,4, 1)
SetData(oday, "Local HMI", LW, 5, 1)
//获取系统时间
GetData(year, "Local HMI", LW, 9022, 1)
GetData(month, "Local HMI", LW, 9021, 1)
GetData(day, "Local HMI", LW, 9020, 1)
if(hyear == oyear)and(hmonth == omonth)and(hday == oday)and(Excule_data(hyear, hmonth, hday))then
//授权码正确
if(hyear > year) or ( (hyear == year)and ((hmonth > month) or((hmonth ==month)and(hday > day))))then
//授权有效
//改写控制
//写有效授权码
SetData(jm[0], "Local HMI", "licence_code_1", 32)
//写有效授权时间
SetData(hyear, "Local HMI", "licence_year", 1)
SetData(hmonth, "Local HMI", "licence_month", 1)
SetData(hday, "Local HMI", "licence_day", 1)
//如果授权时间大于1000天则不需要继续授权
day_j = hday - day
month_j = month
year_j = year
while(year_j < hyear)
while(month_j < 13)
day_j = day_j + Ecu_month_day(year,month)
month_j = month_j + 1
wend
month_j = 1
year_j = year_j + 1
wend
while(month_j < hmonth)
day_j = day_j + Ecu_month_day(year,month)
month_j = month_j + 1
wend
SetData(day_j, "Local HMI", LW, 10, 1)
if(day_j >= 999)then
//取得永久授权
new_licence_cr = 8
SetData(new_licence_cr, "Local HMI", "licence_CR", 1)
else
new_licence_cr = 2
SetData(new_licence_cr, "Local HMI", "licence_CR", 1)
end if
page = 21
else
page = 127 //授权码无效
end if
else
page = 126 //授权码错误
end if
else
page = 125 //授权码格式错误
end if
end if
SetData(page, "Local HMI", "SW_window", 1)
end macro_command