'Loek Veeger Augustus 2019; Websdr sound control 'It requires VSPE to create a splitter with real COMport 10 (to the FT950) and a virtual COMport 15. 'This little program is looking for the data coming from the FT950 on COMport 15 (virtual). 'It looks for TX0 and TX2 commands (recieving /transmitting) passing by, to control sound. 'TX0 is recieving and sets sound on 100% volume. TX2 means transmitting, and sets the sound on 0%, mute. 'it uses nircmd as additional App 'Update 8 12-2019: If I also start Ucxlog, this program asks continuously info from the set by sending IF and FA commands. These are blocked. 'The UcxLog program is set to port 16, and I simply send a IF string to the program via port 16, and the freq is set in UCxLog Imports System.IO.Ports Module Module1 Dim mySerialPortCOM15 As New SerialPort Dim mySerialPortCOM16 As New SerialPort Dim mySerialPortCOM17 As New SerialPort Sub Main() Console.WriteLine("Main program xxx started ") CommPortsSetup() Console.WriteLine("Ports setup") OpenPorts() Console.WriteLine("Ports opened") TransferMessages() CloseMySerialPorts() End Sub Private Sub CommPortsSetup() With mySerialPortCOM15 .PortName = "COM15" .BaudRate = 38400 .DataBits = 8 .Parity = Parity.None .StopBits = StopBits.One .Handshake = Handshake.None .RtsEnable = True .DtrEnable = False End With 'Console.WriteLine("Port 15 is setup ") With mySerialPortCOM16 .PortName = "COM16" .BaudRate = 38400 .DataBits = 8 .Parity = Parity.None .StopBits = StopBits.One .Handshake = Handshake.None .RtsEnable = True .DtrEnable = False End With 'With mySerialPortCOM17 '.PortName = "COM17" '.BaudRate = 38400 '.DataBits = 8 '.Parity = Parity.None '.StopBits = StopBits.One '.Handshake = Handshake.None '.RtsEnable = True '.DtrEnable = False 'End With End Sub Private Sub OpenPorts() Try mySerialPortCOM15.Open() Catch ex As Exception MsgBox(ex.Message) End Try Try mySerialPortCOM16.Open() Catch ex As Exception MsgBox(ex.Message) End Try 'Try 'mySerialPortCOM17.Open() 'Catch ex As Exception 'MsgBox(ex.Message) 'End Try End Sub Private Sub CloseMySerialPorts() mySerialPortCOM15.Close() mySerialPortCOM16.Close() 'mySerialPortCOM17.Close() End Sub Private Declare Function timeGetTime Lib "winmm.dll" () As Integer Public lngStartTime As Long Public Sub Delay(msdelay As Long) lngStartTime = timeGetTime() Do Until (timeGetTime() - lngStartTime) > msdelay Loop End Sub Private Sub TransferMessages() Console.WriteLine("TransferMessages messages started") Dim Get15 As String = "" Dim Get16 As String = "" Dim FirstTwoChar As String = "" Dim LastEightChar As String = "" Dim Freq As String = "" Dim StopLoop As String = "" Dim previousTX As String = "TX2" Dim Counter As Integer = 100 Do Until StopLoop = "Stop" 'in principe loopt de loop nu oneindig, want de FT950 geeft nooit een Stop Counter = Counter - 1 'countertje om eens in de 100 keer de freq naar UCX te sturen, das zat Get15 = mySerialPortCOM15.ReadTo(";") 'Console.WriteLine("Get15 = " & Get15) If Get15 = "TX0" Then If previousTX = "TX2" Then 'check whether this is not the second, etc time that we have to do this without use Delay(350) vol.SetVol(100) 'Console.WriteLine("Volume op 100 gezet") previousTX = "TX0" End If Console.WriteLine("TX0; ontvangen") End If If Get15 = "TX2" Then If previousTX = "TX0" Then vol.SetVol(0) 'Console.WriteLine("Volume op 0 gezet") previousTX = "TX2" End If Console.WriteLine("TX2; zenden") End If If Get15 = "" Then Get15 = "0000000000" 'de string moet groot genoeg zijn om de eerste twee en laatste acht karakters te kunnen nemen End If If Get15.Length > 10 Then ' dit om te voorkomen dat er strings gelezen worden die groter zijn dan 10 karakters (commando plus 8 voor frequentie) Get15 = Get15.Substring(0, 10) End If 'Console.WriteLine("situatie voor de eventuele crash" & FirstTwoChar & Get15.Length & Get15) Try If Get15.Length > 1 Then 'om te voorkomen dat er een string kleiner dan 2 langkomt en de stringmanipulatie frustreert, crash FirstTwoChar = Get15.Substring(0, 2) End If Catch ex As Exception MsgBox(ex.Message) End Try If FirstTwoChar = "FA" Then 'als eerste 2 karakters FA zijn, dan is de rest de vfoA freq. die moet dan even onthouden worden in FREQ 'Console.WriteLine(FirstTwoChar) If Get15.Length > 2 Then 'deze if voorkomt dat er alleen het commando FA is en dat get.length - 8 negatief wordt --> exception LastEightChar = Get15.Substring(Get15.Length - 8) 'dit betekent: een argument meegegeven betekent dat de substring begint bij het argument tot het eind. End If Freq = LastEightChar Console.WriteLine("Frequency = " & Freq) End If 'Get16 = mySerialPortCOM16.ReadTo(";") 'Console.WriteLine(Get16) 'If Get16 = "IF" Then If Counter = 0 Then Try mySerialPortCOM16.Write("IF" & "000" & Freq & "+0000" & "00" & "7" & "00000" & ";") Catch ex As Exception MsgBox(ex.Message) End Try 'System.Console.WriteLine("IF" & "000" & Freq & "+0000" & "00" & "7" & "00000" & ";") Counter = 100 End If Loop End Sub Public Class Sound 'nircmd is een minicmd line met heel veel sterke functies, aan te roepen 'met een argument wat de actie aangeeft Dim nircmd As String Const MAXVOL As Integer = 65535 Public Sub New(ByVal nircmd_location As String) nircmd = nircmd_location End Sub Public Sub SetVol(ByVal level As Integer) Dim p As New ProcessStartInfo p.FileName = nircmd p.Arguments = "setsysvolume " & (MAXVOL * (level / 100)).ToString 'p.Arguments = "SetVolume " & """" & "CATSync Full" & """" & " " & (level).ToString Process.Start(p) End Sub End Class Dim vol As New Sound("C:\Nircmd\nircmd.exe") End Module