AnsweredAssumed Answered

RS232 control with VB.Net through Visa-Com

Question asked by treyhaight on Jan 15, 2020

I have created an application that allows connection through Keysight Gateway (E5810B) to GPIB, RS232, USB & Ethernet. I have all working well but need some help figuring out how to change the baud rate, parity etc. for the serial port.


The following is an example of my working code to communicate to the GPIB and USB correctly.


Public Function SendCmd(IPAddress As String, PortName As String, portType As Int16, strCMD As String, useCR As Boolean, useLF As Boolean) As clsReturnData

Dim rc As Int16
Dim rm As New ResourceManager
Dim ioobj As New FormattedIO488
Dim idnStr As String = ""
Dim strAddress As String = ""
Dim strToSend As String = ""
SendCmd = New clsReturnData

Cursor.Current = Cursors.WaitCursor
'If sending to Ethernet port directly (not through a gateway), drop the port name portion...
If PortName <> "" Then 'Through a gateway...
strAddress = "TCPIP0::" + IPAddress + "::" + PortName + "::INSTR"
Else 'Ethernet directly...
strAddress = "TCPIP0::" + IPAddress + "::INSTR"
End If


'Open the resource manager...
ioobj.IO = CType(rm.Open(strAddress), Ivi.Visa.Interop.IMessage)


'Determine if the use wants termination characters or not...
If useCR = True Then strToSend = strCMD & Chr(13)
If useLF = True Then strToSend = strCMD & Chr(10)


'Send the desired command to the ioObject...
ioobj.WriteString(strToSend, True)


'Wait for the returned (read) data...
idnStr = ioobj.ReadString()


Catch ex1 As Exception
SendCmd.Code = -2
SendCmd.Message = ex1.Message






Catch ex As Exception
SendCmd.Code = -3
SendCmd.Message = ex.Message
End Try


End Try
If SendCmd.Code <> 0 Then
Cursor.Current = Cursors.Default
Exit Function
End If


SendCmd.Code = 0
SendCmd.Message = idnStr
Cursor.Current = Cursors.Default
Exit Function


Catch ex As Exception
Cursor.Current = Cursors.Default
SendCmd.Code = -4
SendCmd.Message = ex.Message
rc = ErrorCtrl(ex, System.Reflection.MethodInfo.GetCurrentMethod.Name)
End Try
End Function