[ Dodano: 2016-09-03, 12:11 ]
krzysiekgrab pisze:Trzeba dodać na pulpiit dwa przyciski
On chce dwa przyciski fizyczne nie wirtualne na ekranie
Da się to zrobić ale przez macropump.
Sprawdzamy w nim czy pojawił się sygnał i wywołujemy komendą coode "M20" (to przykład)
Wywołanie musi odbyć się raz , czyli należy zrobić blokadę aby makro nie mogło zostać powtórnie wywołane dopóki się nie zakończy.
Krótko mówiąc jest to możliwe ale trzeba się trochę napisać.
Przykład :
'----------------------------------------------------------------------------------------------
'Wywołanie makr zmiany biegów
'----------------------------------------------------------------------------------------------
If Not GetOEMLED(800) Then
'Idle + Spindle off + VFD off
'----------------------------------------------
If Not GetOEMLED(804) And Not GetOEMLED(80) And GetOemDRO(DroRPM) = 0 Then
'Klawisz Neutralnego biegu
'----------------------------------------------
If GetIOIn_II(Bieg_N) Then 'Detekcja wciśniętego klawsza zmiany biegu
If Not Blok_Rep_N Then 'Zabezpieczenie aby klawisz tylko raz wywołał macro
Blok_Rep_N = true
If (Not GetIOIn_II(Bieg_I) And Not GetIOIn_II(Bieg_II) And Not GetIOIn_II(Bieg_III) And Not GetIOIn_II(Bieg_IV)) Then 'Zabezpieczenie przed wciśnieciem wiecej niż 1 klawisza 'Aktywacja blokady opisanej wyżej
If GetUserLed(Led_Bieg) = 0 Then 'Zabezpiecznie aby macro niemogło zostać wielokrotnie wywołane w jednym czasie
SetUserLed(Led_Bieg, 1) 'Aktywacja blokady opisanej wyżej
Code"M40" 'Wywołanie macra
End If
End If
End If
Else
Blok_Rep_N = false 'Jeśli klawisz zwolniony blokada zostaje zdjeta
End If
'Klawisz pierwszego biegu
'----------------------------------------------
If GetIOIn_II(Bieg_I) Then
If Not Blok_Rep_I Then
Blok_Rep_I = true
If (Not GetIOIn_II(Bieg_N) And Not GetIOIn_II(Bieg_II) And Not GetIOIn_II(Bieg_III) And Not GetIOIn_II(Bieg_IV)) Then
If GetUserLed(Led_Bieg) = 0 Then
SetUserLed(Led_Bieg, 1)
Code"M41"
End If
End If
End If
Else
Blok_Rep_I = false
End If
'Klawisz drugiego biegu
'----------------------------------------------
If GetIOIn_II(Bieg_II) Then
If Not Blok_Rep_II Then
Blok_Rep_II = true
If (Not GetIOIn_II(Bieg_I) And Not GetIOIn_II(Bieg_N) And Not GetIOIn_II(Bieg_III) And Not GetIOIn_II(Bieg_IV)) Then
If GetUserLed(Led_Bieg) = 0 Then
SetUserLed(Led_Bieg, 1)
Code"M42"
End If
End If
End If
Else
Blok_Rep_II = false
End If
'Klawisz trzeciego biegu
'----------------------------------------------
If GetIOIn_II(Bieg_III) Then
If Not Blok_Rep_III Then
Blok_Rep_III = true
If (Not GetIOIn_II(Bieg_I) And Not GetIOIn_II(Bieg_II) And Not GetIOIn_II(Bieg_N) And Not GetIOIn_II(Bieg_IV)) Then
If GetUserLed(Led_Bieg) = 0 Then
SetUserLed(Led_Bieg, 1)
Code"M43"
End If
End If
End If
Else
Blok_Rep_III = false
End If
'Klawisz czwartego biegu
'----------------------------------------------
If GetIOIn_II(Bieg_IV) Then
If Not Blok_Rep_IV Then
Blok_Rep_IV = true
If (Not GetIOIn_II(Bieg_I) And Not GetIOIn_II(Bieg_II) And Not GetIOIn_II(Bieg_III) And Not GetIOIn_II(Bieg_N)) Then
If GetUserLed(Led_Bieg) = 0 Then
SetUserLed(Led_Bieg, 1)
Code"M44"
End If
End If
End If
Else
Blok_Rep_IV = false
End If
End If
End If
A to jedno z wywoływanych makr
'---------------------------------------------------------------------------------------------------------------------------------
Public Declare Function GetTickCount Lib "kernel32.dll" () As Long
'---------------------------------------------------------------------------------------------------------------------------------
'Input
'-------------------------------
Const GoraLewaSw = 12
Const GoraPrawaSw = 11
Const DolLewaSw = 9
Const DolPrawaSw = 10
Const NeutralSw = 13
'Output
'-------------------------------
Const GoraLewaZaw = 4
Const GoraPrawaZaw = 5
Const DolLewaZaw = 6
Const DolPrawaZaw = 7
Const NeutOnZaw = 9
Const NeutOffZaw = 8
Const Lamp_N = 0
Const Lamp_I = 1
Const Lamp_II = 2
Const Lamp_III = 3
Const Lamp_IV = 4
'Stałe
'-------------------------------
Const delay = 10
Const DroRPM = 39
Const SpindlePulley = 56
Const Led_Bieg = 1100 'numer dro blokady macr M20-M24
Const timecheck = 8000 'Czas na pojawienie sie sygnału czujników
Const zwlokaStopWrze = 20000 'Czas na zatrzymanie wrzeciona
Const MinRpmSpin = 900 'Min obroty wrzeciona
'Zmienne
'-------------------------------
Dim curenttime As Long
Private ObrZap As Long
'----------------------------------------------------------------------------------------------------------------------------------
Sub Main
'----------------------------------------------------------------------------------------------------------------------------------
'Blokada aby ie można było wywołać makra z przycisku
'----------------------------------------------
SetUserLed(Led_Bieg, 1)
'Wrzeciono Stop
'----------------------------------------------
DeActivateSignal(output1)
DeActivateSignal(output2)
'Czekam na zerowe obroty
'----------------------------------------------
curenttime = GetTickCount
While Not GetOEMDro(DroRPM) = 0
If GetTickCount > zwlokaStopWrze + curenttime Then
If Not GetOEMLed(800) Then
DoOEMButton(1021)
End If
Sleep(150)
Message"M40 > Wrzeciono nadal pracuje"
Sleep(150)
Call EndEnd
End If
Wend
'Minimalne obroty wrzeciona
'----------------------------------------------
ObrZap = GetRPM()
SetOemDro(SpindlePulley, 10)
sleep(50)
'----------------------------------------------
SetSpinSpeed(MinRpmSpin/(GetOemDro(74)/100))
'Wyłaczenie biegu Neutralnego
'---------------------------------------------
Call SetCsmioOut(NeutOffZaw, true) 'OFF
Call SetCsmioOut(NeutOnZaw, false) 'ON
'Górny zabiera w lewo
'---------------------------------------------
Call SetCsmioOut(GoraPrawaZaw, false) 'OFF
Call SetCsmioOut(GoraLewaZaw, true) 'ON
Sleep(200)
ActivateSignal(output1)
Sleep(800)
DeActivateSignal(output1)
If Not (WaitForCsmioIn((GoraLewaSw), true, (timecheck))) Then
If Not GetOemLed(800) Then
DoOemButton(1021)
End If
Sleep(150)
Message"M40 > Brak sygnału górnego wybierak - lewa krancówka"
Sleep(150)
Call EndEnd
End If
'Załaczenie biegu Neutralnego
'---------------------------------------------
Call SetCsmioOut(NeutOffZaw, false) 'OFF
Call SetCsmioOut(NeutOnZaw, true) 'ON
'Przywrucenie poprzednich wywołanych obrotów
'---------------------------------------------
SetSpinSpeed(ObrZap)
Sleep(200)
ActivateSignal(output1)
Sleep(800)
DeActivateSignal(output1)
If Not (WaitForCsmioIn((NeutralSw), true, (timecheck))) Then
If Not GetOemLed(800) Then
DoOemButton(1021)
End If
Sleep(150)
Message"M40 > Brak sygnału górnego wybierak - środkowa krancówka"
Sleep(150)
Call EndEnd
End If
'Wywołanie odpowiedniego SP
'---------------------------------------------
SetOemDro(SpindlePulley, 10)
'Zapalenie odpowiedniej kontrolki na pulpicie
'---------------------------------------------
Call SetIOOut_II(Lamp_N, true) 'ON
Call SetIOOut_II(Lamp_I, false)
Call SetIOOut_II(Lamp_II, false)
Call SetIOOut_II(Lamp_III, false)
Call SetIOOut_II(Lamp_IV, false)
'Koniec makra i zgaszenie diody kontroli.
'----------------------------------------------
SetUserLed(Led_Bieg, 0)
End
'----------------------------------------------------------------------------------------------------------------------------------
End Sub
'----------------------------------------------------------------------------------------------------------------------------------
'Funkcją łaczoca dziłanie zwykłego "End i wyłaczenia diody kontroli trwania zmiany biegu,
Sub EndEnd
SetUserLed(Led_Bieg, 0)
Call SetIOOut_II(Lamp_N, false)
Call SetIOOut_II(Lamp_I, false)
Call SetIOOut_II(Lamp_II, false)
Call SetIOOut_II(Lamp_III, false)
Call SetIOOut_II(Lamp_IV, false)
End
End Sub
'---------------------------------------------------------------------------------------------------------------------------------
'CSMIO/IP-S/A in WaitFor
Public Function WaitForCsmioIn (c_in As Integer, state As Boolean, tout_ms As Long) As Boolean
Dim t_ms As Long
Dim in_save As Integer
in_save = c_in
t_ms = GetTickCount ' Get system time (miliseconds)
While true
' Check CSMIO input state
If(GetCsmioIn(c_in) = state) Then
WaitForCsmioIn = true
Sleep(delay)
Exit Function
End If
' Check for time out
If(GetTickCount - t_ms) > tout_ms Then
WaitForCsmioIn = false
Exit Function
End If
' restore input number
c_in = in_save
' Sleep to prevent excessive CPU load
sleep(20)
Wend
End Function
'---------------------------------------------------------------------------------------------------------------------------------
'CSMIO/IP-S/A in
Public Function GetCsmioIn (n As Integer) As Boolean
Dim reg As Integer
Dim tmp As Integer
tmp = n
If(tmp < 16) Then
reg = 90
Else
reg = 91
tmp = tmp - 16
End If
If(GetInBit(reg, tmp)) Then
GetCsmioIn = true
Else
GetCsmioIn = false
End If
Exit Function
End Function
'---------------------------------------------------------------------------------------------------------------------------------
'CSMIO/IP-S/A out
Public Sub SetCsmioOut (ByVal n As Integer, ByVal state As Boolean)
If(state) Then
SetOutBit(90, n)
Else
ResetOutBit(90, n)
End If
End Sub
'---------------------------------------------------------------------------------------------------------------------------------
'CSMIO-IO in
Public Function GetIOIn (n As Integer) As Boolean
If(GetInBit(100, n)) Then
GetIOIn = true
Else
GetIOIn = false
End If
Exit Function
End Function
'---------------------------------------------------------------------------------------------------------------------------------
'CSMIO-IO out
Public Sub SetIOOut (ByVal n As Integer, ByVal state As Boolean)
If(state) Then
SetOutBit(100, n)
Else
ResetOutBit(100, n)
End If
End Sub
'------------------------------------------------------------------------------------------------------------
'CSMIO-IO_II out
Public Sub SetIOOut_II (ByVal n As Integer, ByVal state As Boolean)
If(state) Then
SetOutBit(101, n)
Else
ResetOutBit(101, n)
End If
End Sub