Imports System.IO.Ports
Imports System.Drawing.Drawing2D
Public Class principale
Dim bussola As Image = New Bitmap("bussola.png") ' bmp in ram dal file originale, deve esistere nella cartelle dell'eseguibile
Dim destinazione As Integer
Dim avanzamento As Integer
Dim direzione As Integer
Dim cX As Integer = bussola.Width \ 2
Dim cY As Integer = bussola.Height \ 2
Dim dX As Integer = bussola.Width
Dim dY As Integer = bussola.Height
Dim vel As Integer = 2 ' velocità, valori supportati 1, 2, 3, 5, 6, 9, 10 (divisibili per 90)
Private Sub principale_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.CenterToParent()
btnconnetti.Enabled = False
btnChiudi.Enabled = False
cmbbaund.SelectedItem = "9600"
media_pleyer.Timer5.Start()
End Sub
Private Sub btnscanport_Click(sender As Object, e As EventArgs) Handles btnscanport.Click
cmbPorte.Items.Clear()
Dim myPort As Array
Dim i As Integer
myPort = IO.Ports.SerialPort.GetPortNames
cmbPorte.Items.AddRange(myPort)
i = cmbPorte.Items.Count
i = i - i
Try
cmbPorte.SelectedIndex = i
Catch ex As Exception
Dim result As DialogResult
result = MessageBox.Show("com port non trovata", "Attenzione !!!", MessageBoxButtons.OK)
cmbPorte.Text = ""
cmbPorte.Items.Clear()
Call principale_Load(Me, e)
End Try
btnconnetti.Enabled = True
cmbPorte.DroppedDown = True
End Sub
Private Sub btnconnetti_Click(sender As Object, e As EventArgs) Handles btnconnetti.Click
If cmbPorte.Text <> "" Then
Try
btnconnetti.Enabled = False
SerialPort1.BaudRate = cmbbaund.SelectedItem
SerialPort1.PortName = cmbPorte.SelectedItem
SerialPort1.Open()
btnChiudi.Enabled = True
Timer2.Start()
lblConnessione.Text = "Connesso"
lblConnessione.ForeColor = Color.Green
Timerpanelincrease.Enabled = True
Catch ex As Exception
MsgBox("errore:" & ex.Message, MsgBoxStyle.Critical)
End Try
End If
End Sub
Private Sub btnChiudi_Click(sender As Object, e As EventArgs) Handles btnChiudi.Click
btnChiudi.Enabled = False
SerialPort1.Close()
btnconnetti.Enabled = True
Timer1.Stop()
Timer2.Stop()
lblConnessione.Text = "Disconnesso"
lblConnessione.ForeColor = Color.Red
Timerpanelincrease.Enabled = True
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If SerialPort1.BytesToRead > 0 Then
Try
Dim i As Single = SerialPort1.ReadExisting
Console.WriteLine($"DATO: [{i}] ({i.ToString})")
media_pleyer.lb_volume.Text = i.ToString + "%"
media_pleyer.Volume_control1.value = i.ToString
lb_volume.Text = i.ToString + "%"
Volume_control1.value = i.ToString
media_pleyer.Timer3.Start()
media_pleyer.AxWindowsMediaPlayer1.settings.volume = media_pleyer.Volume_control1.value
AxWindowsMediaPlayer1.settings.volume = media_pleyer.Volume_control1.value
Catch ex As Exception
End Try
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
media_pleyer.Show()
Me.Hide()
lb_title.Text = ""
AxWindowsMediaPlayer1.Ctlcontrols.stop()
AxWindowsMediaPlayer1.URL = ""
End Sub
Private Sub Timerpanelincrease_Tick(sender As Object, e As EventArgs) Handles Timerpanelincrease.Tick
If Panel3.Height > 0 Then
Panel3.Height -= 5
Else
Timerpanelincrease.Enabled = False
End If
End Sub
Private Sub timerpanelreduce_Tick(sender As Object, e As EventArgs) Handles timerpanelreduce.Tick
If Panel3.Height < 80 Then
Panel3.Height += 5
Else
timerpanelreduce.Enabled = False
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If Panel3.Height > 0 Then
Timerpanelincrease.Enabled = True
Else
timerpanelreduce.Enabled = True
End If
End Sub
Private Sub Btn_105_Click(sender As Object, e As EventArgs) Handles Btn_105.Click
AxWindowsMediaPlayer1.URL = "https://icy.unitedradio.it/Radio105.mp3"
lb_title.Text = "Radio 105"
End Sub
Private Sub Btn_gamma_Click(sender As Object, e As EventArgs) Handles Btn_gamma.Click
AxWindowsMediaPlayer1.URL = "https://rn2.fluidstream.eu/gammaradio.aac"
lb_title.Text = "Gamma Radio"
End Sub
Private Sub Btn_r101_Click(sender As Object, e As EventArgs) Handles Btn_r101.Click
AxWindowsMediaPlayer1.URL = "http://icecast.unitedradio.it/r101"
lb_title.Text = "R101"
End Sub
Private Sub Btn_radioitalia_Click(sender As Object, e As EventArgs) Handles Btn_radioitalia.Click
AxWindowsMediaPlayer1.URL = "https://radioitaliasmi.akamaized.net/hls/live/2093120/RISMI/stream01/streamPlaylist.m3u8"
lb_title.Text = "Radio Italia Solo Musica Italiana"
End Sub
Private Sub Btn_kisskiss_Click(sender As Object, e As EventArgs) Handles Btn_kisskiss.Click
AxWindowsMediaPlayer1.URL = "http://ice07.fluidstream.net:8080/KissKiss.mp3"
lb_title.Text = "Radio Kiss Kiss"
End Sub
Private Sub Btn_Rds_Click(sender As Object, e As EventArgs) Handles Btn_Rds.Click
AxWindowsMediaPlayer1.URL = "http://stream1.rds.it:8000/rds64k"
lb_title.Text = "RDS"
End Sub
Dim x As Integer
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
If x = 0 Then
PictureBox1.BackgroundImage = My.Resources.power_off
SerialPort1.Write("A")
x = 1
Else
PictureBox1.BackgroundImage = My.Resources.power_on
SerialPort1.Write("O")
x = 0
End If
End Sub
Private Sub Pcboxbussola_Paint(sender As Object, e As PaintEventArgs) Handles Pcboxbussola.Paint
e.Graphics.TranslateTransform(cX + Pcboxbussola.Width / 2 - cX, cY + Pcboxbussola.Height / 2 - cY) ' posizione centro
e.Graphics.RotateTransform(avanzamento) ' rotazione in gradi
e.Graphics.DrawImage(bussola, -cX, -cY, dX, dY) ' dimensione 100%
End Sub
Function RiceviDati() As String
Dim Ricevuti As String
Try
Ricevuti = SerialPort1.ReadLine
If Ricevuti = Nothing Then
Return "E;null" ' ritorna con la E
Else
Return Ricevuti
End If
Catch ex As Exception
Return "E;" & ex.Message ' ritorna con la E
End Try
End Function
Private Sub SerialPort1_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
Dim str As String = RiceviDati()
str = str.Replace(vbCrLf, "\n")
ListBox1.Items.Add(DateTime.Now.ToLongTimeString & " - str = " & str)
ListBox1.TopIndex = ListBox1.Items.Count - 1
ListBox1.HorizontalScrollbar = True
If str = "" Then Return
' Tolgo l'eventuale "\r"
str = Replace(str, "\r", "")
' Elaboro la stringa
Dim valoriDivisi() As String = str.Split(";")
If valoriDivisi(0) = "E" Then
lblgradi.Text = "errore"
' in valoriDivisi(1) ' il tipo d'errore da mostrare dove vuoi
Else
' Il primo dato è riferito ai gradi della bussola
valoriDivisi(0) = valoriDivisi(0).Replace(".", ",") ' se ci fosse il punto decimale viene sostituito con la virgola decimale
avanzamento = CInt(valoriDivisi(0))
lblgradi.Text = avanzamento.ToString("000°")
Pcboxbussola.Invalidate()
' Il dato in: valoriDivisi(1), è riferito al volume e è una stringa
media_pleyer.lb_volume.Text = valoriDivisi(1) + "%"
media_pleyer.Volume_control1.value = valoriDivisi(1)
lb_volume.Text = valoriDivisi(1) + "%"
Volume_control1.value = valoriDivisi(1)
media_pleyer.Timer3.Start()
media_pleyer.AxWindowsMediaPlayer1.settings.volume = media_pleyer.Volume_control1.value
AxWindowsMediaPlayer1.settings.volume = media_pleyer.Volume_control1.value
video.Wmp1.settings.volume = video.Volume_control1.value
End If
End Sub
End Class