'╔═══════════════════════════════════════════════════════════╗
'║     Name: CAMbus_Commander_V07.txt       Date: 09 Apr2022 ║
'║   Author: Leonardo                                        ║
'║    Scope: Test CANbus commandsover serial port            ║
'╠═══════════════════════════════════════════════════════════╣
'║Hardware: RoboTell USB-CANbus Adapter                      ║
'╟───────────────────────────────────────────────────────────╢
'║    Note: Ethan version                         29/03/2022 ║
'╚═══════════════════════════════════════════════════════════╝
Load Joint_and_Robotell.jpg
Option Speed 9
ComPort = 17

' ╔════════════════════════════════════════════╗ █▀▀▄ █  █ ▀▀█▀▀ ▀▀█▀▀
' ║ BUTTONS                                    ║ █▀▀█ █  █   █     █
' ╚════════════════════════════════════════════╝ █▄▄█ █▄▄█   █     █
Button  1 Text Enable
Button Enable Text "ENABLE JOINT"
Button Enable Color Cyan5

Button  2 Text Disable
Button Disable Text "DISABLE JONT"
Button Disable Color Cyan5

Button  5 Text Rpm1000
Button Rpm1000 Text "1000 rpm"
Button Rpm1000 Color LightBlue

Button  6 Text Rpm2000
Button Rpm2000 Text "2000 rpm"
Button Rpm2000 Color LightBlue

Button  7 Text Rpm3000
Button Rpm3000 Text "3000 rpm"
Button Rpm3000 Color LightBlue

Button 8 Text MotorTurn1
Button MotorTurn1 Text "Motor turn 1"
Button MotorTurn1 Color Aquamarine

Button 10 Text CLOSE_ALL
Button CLOSE_ALL Text "CLOSE ALL"
Button CLOSE_ALL Color Red
'====================================
Button 17 Text E20-H8-1B-100
Button E20-H8-1B-100 Color Aqua

Button 18 Text "Joint1_0"
Button Joint1_0 Text "  0°"
Button Joint1_0 Color Aqua

Button 19 Text Joint1_45
Button Joint1_45 Text " 45°"
Button Joint1_45 Color Aqua

Button 20 Text Joint1_90
Button Joint1_90 Text " 90°"
Button Joint1_90 Color Aqua

Button 21 Text Joint1_135
Button Joint1_135 Text "135°"
Button Joint1_135 Color Aqua

Button 22 Text Joint1_180
Button Joint1_180 Text "180°"
Button Joint1_180 Color Aqua

Button 23 Text Joint1_225
Button Joint1_225 Text "225°"
Button Joint1_225 Color Aqua

Button 24 Text Joint1_270
Button Joint1_270 Text "270°"
Button Joint1_270 Color Aqua

Button 25 Text Joint1_315
Button Joint1_315 Text "315°"
Button Joint1_315 Color Aqua

Button 26 Text Joint1_360
Button Joint1_360 Text "360°"
Button Joint1_360 Color Aqua
'====================================
Button 33 Text E20-H8-1B-50
Button E20-H8-1B-50 Color Aquamarine

Button 34 Text "Joint2_0"
Button Joint2_0 Text "  0°"
Button Joint2_0 Color Aquamarine

Button 35 Text Joint2_45
Button Joint2_45 Text " 45°"
Button Joint2_45 Color Aquamarine

Button 36 Text Joint2_90
Button Joint2_90 Text " 90°"
Button Joint2_90 Color Aquamarine

Button 37 Text Joint2_135
Button Joint2_135 Text "135°"
Button Joint2_135 Color Aquamarine

Button 38 Text Joint2_180
Button Joint2_180 Text "180°"
Button Joint2_180 Color Aquamarine

Button 39 Text Joint2_225
Button Joint2_225 Text "225°"
Button Joint2_225 Color Aquamarine

Button 40 Text Joint2_270
Button Joint2_270 Text "270°"
Button Joint2_270 Color Aquamarine

Button 41 Text Joint2_315
Button Joint2_315 Text "315°"
Button Joint2_315 Color Aquamarine

Button 42 Text Joint2_360
Button Joint2_360 Text "360°"
Button Joint2_360 Color Aquamarine

' ╔════════════════════════════════════════════╗ █   █▀▀█ █▀▀█ █▀▀▄
' ║ LOAD APPS                                  ║ █   █  █ █▄▄█ █  █
' ╚════════════════════════════════════════════╝ █▄▄ █▄▄█ █  █ █▄▄█
'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

' ╔════════════════════════════════════════════╗  █▀▀▀ ▀▀█▀▀ █▀▀▀█ █▀▀▀█ ▀▀█▀▀
' ║  START FROM HERE                           ║  ▀▀▀█   █   █▀▀▀█ █▀█▀▀   █
' ╚════════════════════════════════════════════╝  ▄▄▄█   █   █   █ █  ▀▄   █
Load Vars
TestNumber = v1
TestErrors = v2

Controls OpenTextBox
Controls ClearTextBox
Beep "1000, 100"
TTS SelectVoice 1
TTS SetVolume 100
TTS SetSpeed -3

COM Open ComPort 115000
s1 = COM_Status
s1 = "Port status: "  + "COM" + ComPort + " IS " + s1 + CRLF
s1 = s1 + "Valid ports: " + COM_PortNames + CRLF + CRLF
Print s1

'TTS SelectVoice "ENG"
'If COM_Status = "OPENED"
'	TTS Speak "Robot ready and operational."
'Else
'	TTS Speak "Robot is NOT connected."
'EndIf
'Wait TTSready
Load Hide

Stop                                            '

' ╔════════════════════════════════════════════╗ █▀▀ █   █▀▀█ █▀▀▀ █▀▀▀
' ║ CLOSE ALL                                  ║ █   █   █  █ ▀▀▀█ █▀▀
' ╚════════════════════════════════════════════╝ █▄▄ █▄▄ █▄▄█ ▄▄▄█ █▄▄▄
Label CLOSE_ALL
	Load CloseApps "Theremino_Editor.exe"
	Load CloseApps
Return

' ╔════════════════════════════════════════════╗ █▀▀▀ ▀▀█▀▀ █▀▀█ █▀▀█
' ║ STOP EVENT (when pressing stop button)     ║ ▀▀▀█   █   █  █ █▄▄█
' ╚════════════════════════════════════════════╝ ▄▄▄█   █   █▄▄█ █
Label EventStop
	v1 = TestNumber
	v2 = TestErrors
	Save Vars
	Controls CloseTextBox
End                                             '

' ╔════════════════════════════════════════════╗ █   █ █▀▀█ █▀▀▀█
' ║ VARIABLE INITIALIZATIONS & ASSIGNEMENTS    ║ █   █ █▄▄█ █▄▄▄█
' ╚════════════════════════════════════════════╝  ▀▄▀  █  █ █  ▀▄
Variable Numeric ComPort
'Variable Numeric StopAll
Variable Numeric TestNumber
Variable Numeric TestErrors

' ╔════════════════════════════════════════════╗ █▀▀▀ █  █ █▀█
' ║  S U B R O U T I N E   A R E A             ║ ▀▀▀█ █  █ █▀▀█
' ╚════════════════════════════════════════════╝ ▄▄▄█ █▄▄█ █▄▄█
Label Enable
	s1 = "AA AA 00 00 00 00 00 80 00 00 00 01 00 00 06 00 00 00 87 55 55"
	TTS Speak "Robot enabled."
	SendCommand
Return

Label Disable
	s1 = "AA AA 00 00 00 00 00 86 00 00 00 00 00 00 06 00 00 00 8C 55 55"
	TTS Speak "Robot disabled."
	SendCommand
Return

Label Rpm1000
	s1 = "AA AA 00 00 00 00 00 86 00 00 03 E8 00 00 06 00 00 00 77 55 55"
	SendCommand
Return

Label Rpm2000
	s1 = "AA AA 00 00 00 00 00 86 00 00 07 D0 00 00 06 00 00 00 63 55 55"
	SendCommand
Return

Label Rpm3000
	s1 = "AA AA 00 00 00 00 00 86 00 00 0B B8 00 00 06 00 00 00 4F 55 55"
	SendCommand
Return

Label MotorTurn1
	s1 = "AA AA 00 00 00 00 00 81 00 00 FF FF 00 00 06 00 00 00 85 55 55"
	SendCommand
Return

Label Joint1_0
	s1 = "AA AA 00 00 00 00 00 81 00 00 00 00 00 00 06 00 00 00 87 55 55"
	SendCommand
Return

Label Joint1_45
	s1 = "AA AA 00 00 00 00 00 81 00 0C 7F F3 00 00 06 00 00 00 05 55 55"
	SendCommand
Return

Label Joint1_90
	s1 = "AA AA 00 00 00 00 00 81 00 18 FF E7 00 00 06 00 00 00 85 55 55"
	SendCommand
Return

Label Joint1_135
	s1 = "AA AA 00 00 00 00 00 81 00 25 7F DA 00 00 06 00 00 00 05 55 55"
	SendCommand
Return

Label Joint1_180
	s1 = "AA AA 00 00 00 00 00 81 00 31 FF CE 00 00 06 00 00 00 85 55 55"
	SendCommand
Return

Label Joint1_225
	s1 = "AA AA 00 00 00 00 00 81 00 3F 7F C1 00 00 06 00 00 00 06 55 55"
	SendCommand
Return

Label Joint1_270
	s1 = "AA AA 00 00 00 00 00 81 00 4A FF B5 00 00 06 00 00 00 85 55 55 "
	SendCommand
Return

Label Joint1_315
	s1 = "AA AA 00 00 00 00 00 81 00 57 7F A8 00 00 06 00 00 00 05 55 55"
	SendCommand
Return

Label Joint1_360
	s1 = "AA AA 00 00 00 00 00 81 00 63 FF 9C 00 00 06 00 00 00 85 55 55"
	SendCommand
Return

Label Joint2_0
	s1 = "AA AA 00 00 00 00 00 81 00 00 00 00 00 00 06 00 00 00 87 55 55"
	SendCommand
Return

Label Joint2_45
	s1 = "AA AA 00 00 00 00 00 81 00 0C 7F F3 00 00 06 00 00 00 05 55 55"
	SendCommand
Return

Label Joint2_90
	s1 = "AA AA 00 00 00 00 00 81 00 18 FF E7 00 00 06 00 00 00 85 55 55"
	SendCommand
Return

Label Joint2_135
	s1 = "AA AA 00 00 00 00 00 81 00 25 7F DA 00 00 06 00 00 00 05 55 55"
	SendCommand
Return

Label Joint2_180
	s1 = "AA AA 00 00 00 00 00 81 00 31 FF CE 00 00 06 00 00 00 85 55 55"
	SendCommand
Return

Label Joint2_225
	s1 = "AA AA 00 00 00 00 00 81 00 3F 7F C1 00 00 06 00 00 00 06 55 55"
	SendCommand
Return

Label Joint2_270
	s1 = "AA AA 00 00 00 00 00 81 00 4A FF B5 00 00 06 00 00 00 85 55 55 "
	SendCommand
Return

Label Joint2_315
	s1 = "AA AA 00 00 00 00 00 81 00 57 7F A8 00 00 06 00 00 00 05 55 55"
	SendCommand
Return

Label Joint2_360
	s1 = "AA AA 00 00 00 00 00 81 00 63 FF 9C 00 00 06 00 00 00 85 55 55"
	SendCommand
Return

' ╔════════════════════════════════════════════╗ █▀▀▀ █▀▀▀ █▀▄ █ █▀▀▄
' ║ S E N D                                    ║ ▀▀▀█ █▀▀▀ █  ▀█ █  █
' ╚════════════════════════════════════════════╝ ▄▄▄█ █▄▄▄ █   █ █▄▄█
Label SendCommand
	Slot(14) = 1000		'show start signal on SignalScope
	COM WriteStringHEX s1
	Print s1 + CRLF
	Slot(14) = 0		'show stop signal on SignalScope
	
Return


'WATCH COM_Status
