' =====================================================================
'     Name: PLC_Emulator_07.txt                  Date:  14 October 2020
'    Autor: Leonardo DE PALO Ph.D.
'    Scope: Emulating PLC sending serial data for DigiScrew testing.
'    Plate: 1530 TXB.
'   Lenght: 9 - 12 - 13 - 14 - 15 - 16 - 17 - 18 - 19 - 22 - 26
' Hardware: USB to Serial RS232 adapter
' =====================================================================
Load Toc.wav
Option Speed 9

v1 = 12
COM Open v1 9600
s1 = COM_Status
Print s1 + ": " + v1 + "   VALID: " + COM_PortNames

Button 1 Text "18 FOREVER"
Button 2 Text "9"
Button 3 Text "12"
Button 4 Text "13"
Button 5 Text "14"
Button 6 Text "15"
Button 7 Text "16"
Button 8 Text "17"
Button 9 Text "18"
Button 10 Text "19"
Button 11 Text "22"
Button 12 Text "26"

Button 14 Text "START"
Button 15 Text "STOP"
Button 16 Text "CLOSE ALL"

Button 1 Color Yellow
Button 2 Color YellowGreen
Button 3 Color YellowGreen
Button 4 Color YellowGreen
Button 5 Color YellowGreen
Button 6 Color YellowGreen
Button 7 Color YellowGreen
Button 8 Color YellowGreen
Button 9 Color LawnGreen
Button 10 Color YellowGreen
Button 11 Color YellowGreen
Button 12 Color YellowGreen

Button 14 Color Green
Button 15 Color Red
Button 16 Color Black

'Load Theremino_HAL\Theremino_HAL.exe
'Load ..\Theremino_Terminal_RX\Theremino_Terminal.exe
'Load ..\Theremino_Terminal_TX\Theremino_Terminal.exe
'Load ..\Theremino_HAL\Theremino_SlotViewer.exe
'Load ..\Theremino_HAL\Theremino_SignalScope.exe

' ------------------------------------- Remember last totals
Load Vars

'Controls OpenTextBox

Stop                                            '

Label CLOSE ALL
	Load CloseApps
Return

Label EventStop
	Save Vars
End                                             '


Label 18 FOREVER
	s2 = ""
	For v1 = 1 To 9e99
		s1 = "18M4CW" + CRLF
		COM WriteString s1
		For v2 = 1 To 1e99
			s2 = s2 + COM_Received
			Select s2
				Case "AK"
					s2 = ""
				Case "OK"
					s2 = ""
					v7 = v7 + 1
					Exit
				Case "NO"
					s2 = ""
					Load "sirena.wav"
					Wait Seconds 2
					v8 = v8 + 1
					v7 = v7 + 1
					Exit
			EndSelect
		Next
		Print " Test num: " + v7 + " Errors: " + v8
		Wait Seconds 0.1
	Next
Return

Label 9
	s1 = "9M4CW" + CRLF
	Wait Seconds 0.02
	COM WriteString s1
	Print s1
Return

Label 12
	s1 = "12M4CW" + CRLF
	Wait Seconds 0.02
	COM WriteString s1
	Print s1
Return

Label 13
	s1 = "13M4CW" + CRLF
	Wait Seconds 0.02
	COM WriteString s1
	Print s1
Return

Label 14
	s1 = "14M4CW" + CRLF
	Wait Seconds 0.02
	COM WriteString s1
	Print s1
Return

Label 15
	s1 = "15M4CW" + CRLF
	Wait Seconds 0.02
	COM WriteString s1
	Print s1
Return

Label 16
	s1 = "16M4CW" + CRLF
	Wait Seconds 0.02
	COM WriteString s1
	Print s1
Return

Label 17
	s1 = "17M4CW" + CRLF
	Wait Seconds 0.02
	COM WriteString s1
	Print s1
Return

Label 18
	s1 = "18M4CW" + CRLF
	Wait Seconds 0.02
	COM WriteString s1
	Print s1
Return

Label 19
	s1 = "19M4CW" + CRLF
	Wait Seconds 0.02
	COM WriteString s1
	Print s1
Return

Label 22
	s1 = "22M4CW" + CRLF
	Wait Seconds 0.02
	COM WriteString s1
	Print s1
Return

Label 26
	s1 = "26M4CW" + CRLF
	Wait Seconds 0.02
	COM WriteString s1
	Print s1
Return

Label START
	Slot(14) = 1000		'show start signal
	s1 = "START" + CRLF
	Wait Seconds 0.02
	COM WriteString s1
	Print s1
	Slot(14) = 0		'show stop signal
Return

Label 20M4CW
	Slot(14) = 1000		'show start signal
	s1 = "20M4CW" + CRLF
	Wait Seconds 0.02
	COM WriteString s1
	Print s1
	Slot(14) = 0		'show stop signal
Return

Label 2M4CCW			'show start signal
	Slot(14) = 1000
	s1 = "2M4CCW" + CRLF
	'Wait Seconds 0.02
	COM WriteString s1
	Print s1
	Slot(14) = 0		'show stop signal
Return

Label STOP		     	'show start signal
	Slot(14) = 1000 + CRLF
	'Wait Seconds 0.02
	s1 = "STOP" + CRLF
	COM WriteString s1
	Print s1
	Slot(14) = 0		'show stop signal
Return


'WATCH COM_Status
