-
Notifications
You must be signed in to change notification settings - Fork 3
/
CIcom710.cls
executable file
·240 lines (192 loc) · 6.03 KB
/
CIcom710.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "CIcom710"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'
' Project..........Icom Control Panel
' File Name........CICOM710.CLS
' File Version.....4/3/01
' Contents.........Interface class for controlling an ICOM 710...
'
' Copyright (c) 2001 - All Rights Reserved
' Victor Poor, W5SMM
' 1208 East River Drive, #302
' Melbourne, FL 32901
'
' PTC II control's by Tom Lafleur, KA6IQA
'
Option Explicit
Public Enum Emission
rmNBDP
rmUSB
rmLSB
rmCW
rmAM
End Enum
Private sRadio As String
Private sBaud As String
Private bPTC As Boolean
Private PTCcmd As Boolean
Private sp As MSComm
Private Function RadioCommand(sCommand As String) As Boolean
Dim sBuffer As String
Dim sHex As String
Dim sCheckSum As String
Dim lCheckSum As Long
Dim lIndex As Long
Dim lSeconds As Long
RadioCommand = False
If Not sp.PortOpen Then Exit Function
If PTCcmd Then ' Check if we need raw output to PTC II
sBuffer = sCommand
sp.Output = sCommand
Else
lCheckSum = 0
sBuffer = "$PICOA,90," & sRadio & "," & sCommand
For lIndex = 2 To Len(sBuffer)
lCheckSum = lCheckSum Xor Asc(Mid(sBuffer, lIndex, 1))
Next lIndex
sCheckSum = "*" & Right("0" & Hex$(lCheckSum), 2)
If bPTC Then ' If PTC II connected
sBuffer = sBuffer & sCheckSum & vbCrLf
' We need to convert Radio Commands to a HEX sequence
' sRet will hold the Command string in HEX
sHex = ""
For lIndex = 1 To Len(sBuffer)
sHex = sHex & Right("0" & Hex(Asc(Mid(sBuffer, lIndex, 1))), 2)
Next lIndex
' Commands sequence needed to pass via the PTC II radio port
' PTC Format is set dump mode, then special header, then command in hex.
' A max of 256 bytes can be sent. (512 hex char)
' Special header is: (CTL5) #TX: hex data cr
' PTC return a max of 40 bytes in this mode
sBuffer = Chr(5) & "#TX:" & sHex & vbCr
sp.Output = sBuffer ' Output Header and Radio Command String
Else
' If connected via NMEA port
sBuffer = sBuffer & sCheckSum & vbCrLf
sp.Output = sBuffer
End If
End If
lSeconds = (Second(Time) + 2) Mod 60
Do
If sp.InBufferCount >= Len(sBuffer) Then
RadioCommand = True
Exit Do
End If
DoEvents
If Second(Time) = lSeconds Then
Exit Function
End If
Loop
sBuffer = sp.Input ' Empty Input buffer
End Function
Public Sub OpenPort(spPort As MSComm, lPort As Long)
Set sp = spPort
On Error Resume Next
sp.PortOpen = False
sp.CommPort = lPort + 1
If bPTC Then
' Will need to change baud to sBaud if bPTC is true
' May need to hunt for correct baud rate on PTC II over a range
sp.Settings = sBaud & ",N,8,1"
sp.PortOpen = True ' Open the I/O Port
' We want to wake up modem from it Autobaud mode, Set the Radio Baud rate
' We may want to look for a "CMD" return from PTC II to see ifts awake
PTCcmd = True ' Tell output routine that we want raw output to PTC
RadioCommand vbCr ' Wake up Modem with a CR
RadioCommand "TRX TY Icom 4800 3" & vbCr ' Tell PTC II we are talking to an ICOM at 4800 baud
RadioCommand "TRX DU 1" & vbCr ' Enable DUMP mode in PTC II
PTCcmd = False
Else
sp.Settings = "4800,N,8,1" ' NMEA standard for ICOM Direct connection
sp.PortOpen = True
End If
End Sub
Public Function OpenRadio() As Boolean
If RadioCommand("REMOTE,ON") = False Then
OpenRadio = False
Exit Function
Else
OpenRadio = True
End If
RadioCommand "AGC,ON"
RadioCommand "TXP,3"
RadioCommand "DIM,OFF"
End Function
Public Function CloseRadio() As Boolean
If RadioCommand("AFG,0") Then
RadioCommand "RFG,9"
RadioCommand "REMOTE,OFF"
CloseRadio = True
Else
CloseRadio = False
End If
On Error Resume Next
sp.PortOpen = False
End Function
Public Sub Mode(emMode As Emission)
Select Case emMode
Case rmNBDP
RadioCommand "MODE,AFS"
Case rmUSB
RadioCommand "MODE,USB"
Case rmLSB
RadioCommand "MODE,LSB"
Case rmCW
RadioCommand "MODE,CW"
Case rmAM
RadioCommand "MODE,AM"
End Select
End Sub
Public Sub AudioGain(lLevel As Long)
RadioCommand "AFG," & CStr(lLevel)
End Sub
Public Sub RFGain(lLevel As Long)
RadioCommand "RFG," & CStr(Int(lLevel / 11))
End Sub
Public Sub SetReceiver(dQRG As Double)
RadioCommand "RXF," & Format(dQRG / 1000#, "#0.000000")
End Sub
Public Sub SetTransmitter(dQRG As Double)
RadioCommand "TXF," & Format(dQRG / 1000#, "#0.000000")
End Sub
Public Sub PanelLight(bDim As Boolean)
If bDim Then
RadioCommand "DIM,ON"
Else
RadioCommand "DIM,OFF"
End If
End Sub
Public Sub NoiseBlank(bNB As Boolean)
If bNB Then
RadioCommand "NB,ON"
Else
RadioCommand "NB,OFF"
End If
End Sub
Public Sub Squelch(bSquelch As Boolean)
If bSquelch Then
RadioCommand "SQLC,ON"
Else
RadioCommand "SQLC,OFF"
End If
End Sub
Property Let RadioType(sRadioType As String)
sRadio = sRadioType
End Property
Property Let PTCBaud(sPTCbaud As String)
sBaud = sPTCbaud
End Property
Property Let PTC(bPTCflag As Boolean)
bPTC = bPTCflag
End Property