-
1
- #1
I searched for ages trying to find a way to set the PC
serial port to 10400 baud (the standard for IS0 9141
vehicle diagnostics) so I could monitor bus activity.
It's easy but you need inpout32.dll (get this from the web).
Basically what it's doing is setting the UART clock divisor manually. To do this you need to open the port and set the
MSbit of the LCR register, then write the Lo and Hi bytes
of the divisor word to the port address and port address + 1.
Then restore the LCR register.
The baud rates available are generally the fastest (115200)
divided by the divisor. In my case I wanted 10400 and a divisor
of 11 gives 10472 (near enough for jazz)!
Private Declare Function Inp Lib "inpout32.dll" Alias "Inp32" (ByVal PortAddress As Integer) As Integer
Private Declare Sub Out Lib "inpout32.dll" Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Integer)
Private Sub Init()
Dim Baud As String
Dim LCR As Integer ' UART LCR Register contents
Dim Port As Integer
Baud = Combo_Baud.Text ' Get baud from combo box
Port = &H3F8 ' Address of com1 (could use com2 address etc)
MSComm1.CommPort = 1 ' Select com1
MSComm1.PortOpen = True ' Open the port
If Baud = "10400" Then ' Bespoke baud rate not supported by Windows
MSComm1.Settings = "9600,N,8,1" ' First set baud to 9600
LCR = Inp(Port + 3) ' Get current value of LCR register
Out (Port + 3), (LCR Or &H80) ' Set MSB
Out Port, 11 ' Set Lo byte UART divisor to 11 (10474 baud = 115200/11)
Out (Port + 1),0 Set hi byte of divisor to zero
Out (Port + 3), LCR ' Restore the LCR register
Else
MSComm1.Settings = Baud & ",N,8,1" ' Else set baud to whatever comes out combo box
End If
MSComm1.InputMode = comInputModeBinary ' Set up for binary transfer
End Sub
serial port to 10400 baud (the standard for IS0 9141
vehicle diagnostics) so I could monitor bus activity.
It's easy but you need inpout32.dll (get this from the web).
Basically what it's doing is setting the UART clock divisor manually. To do this you need to open the port and set the
MSbit of the LCR register, then write the Lo and Hi bytes
of the divisor word to the port address and port address + 1.
Then restore the LCR register.
The baud rates available are generally the fastest (115200)
divided by the divisor. In my case I wanted 10400 and a divisor
of 11 gives 10472 (near enough for jazz)!
Private Declare Function Inp Lib "inpout32.dll" Alias "Inp32" (ByVal PortAddress As Integer) As Integer
Private Declare Sub Out Lib "inpout32.dll" Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Integer)
Private Sub Init()
Dim Baud As String
Dim LCR As Integer ' UART LCR Register contents
Dim Port As Integer
Baud = Combo_Baud.Text ' Get baud from combo box
Port = &H3F8 ' Address of com1 (could use com2 address etc)
MSComm1.CommPort = 1 ' Select com1
MSComm1.PortOpen = True ' Open the port
If Baud = "10400" Then ' Bespoke baud rate not supported by Windows
MSComm1.Settings = "9600,N,8,1" ' First set baud to 9600
LCR = Inp(Port + 3) ' Get current value of LCR register
Out (Port + 3), (LCR Or &H80) ' Set MSB
Out Port, 11 ' Set Lo byte UART divisor to 11 (10474 baud = 115200/11)
Out (Port + 1),0 Set hi byte of divisor to zero
Out (Port + 3), LCR ' Restore the LCR register
Else
MSComm1.Settings = Baud & ",N,8,1" ' Else set baud to whatever comes out combo box
End If
MSComm1.InputMode = comInputModeBinary ' Set up for binary transfer
End Sub