Hello,
I am having a strange issue, and I don't really know where to look to fix it.
I have a form that communicates with a microcontroller via a serial port. The form works as expected as long as the Filter text box is always zero.
When the Filter text box is non-zero, the data is sent, but the microcontroller doesn't change modes. When I return to the main form and then return to the configuration form, the microcontroller changes its mode.
The configuration form code is attached below. Please let me know if you need to see anything else.
![Name: config.png
Views: 64
Size: 6.8 KB]()
I appreciate any input. Thanks.
Matt
I am having a strange issue, and I don't really know where to look to fix it.
I have a form that communicates with a microcontroller via a serial port. The form works as expected as long as the Filter text box is always zero.
When the Filter text box is non-zero, the data is sent, but the microcontroller doesn't change modes. When I return to the main form and then return to the configuration form, the microcontroller changes its mode.
The configuration form code is attached below. Please let me know if you need to see anything else.
Code:
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Dim UNITSV As Byte
Dim INTYPE As Byte
Dim ZPO2 As Byte
Dim ZPO1 As Byte
Dim ZPO0 As Byte
Dim HPO2 As Byte
Dim HPO1 As Byte
Dim HPO0 As Byte
Dim OPTLST As Byte
Dim FLTRCNT As Byte
Dim InBuffer
Private Sub back_Click()
If serial_comm.MSComm1.PortOpen = True Then serial_comm.MSComm1.PortOpen = False
main_menu.Show
config_update_form.Hide
Unload config_update_form
End Sub
Private Sub transmit_configuration()
'Dim bytearray(10) As Byte
'If serial_comm.MSComm1.PortOpen = False Then serial_comm.MSComm1.PortOpen = True
'Sleep (500)
serial_comm.MSComm1.Output = Chr$(&H62) '"a" (61H) - transmits Configuration UNITS,TYPE,ZPO,HPO,OPT,FLTR (10 bytes) good
Sleep (500)
'Sleep (1)
'bytearray(0) = UNITSV
'bytearray(1) = INTYPE
'bytearray(2) = ZPO2
'bytearray(3) = ZPO1
'bytearray(4) = ZPO0
'bytearray(5) = HPO2
'bytearray(6) = HPO1
'bytearray(7) = HPO0
'bytearray(8) = OPTLST
'bytearray(9) = FLTRCNT
'
'serial_comm.MSComm1.Output = bytearray
serial_comm.MSComm1.Output = Chr$(UNITSV)
Sleep (100)
serial_comm.MSComm1.Output = Chr$(INTYPE)
Sleep (100)
serial_comm.MSComm1.Output = Chr$(ZPO2)
Sleep (100)
serial_comm.MSComm1.Output = Chr$(ZPO1)
Sleep (100)
serial_comm.MSComm1.Output = Chr$(ZPO0)
Sleep (100)
serial_comm.MSComm1.Output = Chr$(HPO2)
Sleep (100)
serial_comm.MSComm1.Output = Chr$(HPO1)
Sleep (100)
serial_comm.MSComm1.Output = Chr$(HPO0)
Sleep (100)
serial_comm.MSComm1.Output = Chr$(OPTLST)
Sleep (100)
serial_comm.MSComm1.Output = Chr$(FLTRCNT)
Sleep (100)
End Sub
Private Sub receive_configuration()
'serial_comm.MSComm1.RThreshold = 10
serial_comm.MSComm1.Output = Chr$(&H61) '"b" (62H) - receive Configuration (10 bytes)
Sleep (500)
InBuffer = serial_comm.MSComm1.Input
UNITSV = CByte(InBuffer(0))
INTYPE = CByte(InBuffer(1))
ZPO2 = CByte(InBuffer(2))
ZPO1 = CByte(InBuffer(3))
ZPO0 = CByte(InBuffer(4))
HPO2 = CByte(InBuffer(5))
HPO1 = CByte(InBuffer(6))
HPO0 = CByte(InBuffer(7))
OPTLST = CByte(InBuffer(8))
FLTRCNT = CByte(InBuffer(9))
End Sub
Private Sub Command1_Click()
get_data_from_form
transmit_configuration
End Sub
Private Sub Form_Load()
If serial_comm.MSComm1.PortOpen = False Then serial_comm.MSComm1.PortOpen = True
receive_configuration
fill_form_with_data
End Sub
Private Sub fill_form_with_data()
Select Case UNITSV
Case 8
Combo1.ListIndex = 0
Case 4
Combo1.ListIndex = 1
Case 3
Combo1.ListIndex = 2
Case 2
Combo1.ListIndex = 3
Case 7
Combo1.ListIndex = 4
Case 6
Combo1.ListIndex = 5
Case Else
Combo1.ListIndex = -1
End Select
Select Case INTYPE
Case 1
Combo2.ListIndex = 0
Case 2
Combo2.ListIndex = 1
Case 3
Combo2.ListIndex = 2
Case 4
Combo2.ListIndex = 3
Case 5
Combo2.ListIndex = 4
Case 6
Combo2.ListIndex = 5
Case 7
Combo2.ListIndex = 6
Case 8
Combo2.ListIndex = 7
Case 9
Combo2.ListIndex = 8
Case 10
Combo2.ListIndex = 9
Case 11
Combo2.ListIndex = 10
Case 12
Combo2.ListIndex = 11
Case 13
Combo2.ListIndex = 12
Case 14
Combo2.ListIndex = 13
Case 15
Combo2.ListIndex = 14
Case 16
Combo2.ListIndex = 15
Case 17
Combo2.ListIndex = 16
Case 18
Combo2.ListIndex = 17
Case 19
Combo2.ListIndex = 18
Case 20
Combo2.ListIndex = 19
Case Else
Combo2.ListIndex = -1
End Select
'calculate zero and span
'add them to their boxes
Text1.Text = ZPO2
Text2.Text = HPO2
'options
'add filter to its box
Text3.Text = FLTRCNT
End Sub
Private Sub get_data_from_form()
Select Case Combo1.ListIndex
Case 0
UNITSV = 8
Case 1
UNITSV = 4
Case 2
UNITSV = 3
Case 3
UNITSV = 2
Case 4
UNITSV = 7
Case 5
UNITSV = 6
Case Else
UNITSV = 99
End Select
FLTRCNT = Val(Text3.Text)
End Sub
I appreciate any input. Thanks.
Matt