kevy
Dec 12th, 2006, 01:31 PM
I am doing the VB programming for my microcontroller to communicate with PC.
The microcontroller have set the program which the PC send the command signal "character Q" and microcontroller will transmit the data in ASCII code (0 to 255) to PC. From the ASCII code, I will convert it to value and do some calculation to get my exact number.
The problem is the 0 showed when I click for get the first data. Then, the second displayed data was the previous one.
e.g. the 1st data suppose is 56 but the 0 showed when I click to get data at first time.
Then, I click again, it showed the 56 which is the previous data.
Suppose the data for that time is 255!!
I have using the hyperterminal to test my hardware and it showed the current data all the time when I click on Q button and no 0 showed at first time clicking. I think that was something problem with my coding.
How to get the current data from it???
I post my code for expert like u to give me guidance and tell me the mistake.
Thanks for helping me.
Private Sub cmdStart_Click() 'GET DATA
Dim ADCValue As String
Dim SolarValue As Double
MSComm1.Output = "Q"
X = MSComm1.Input
Z = (Val(X) * 4.4)
lblDisplay.Caption = Z
End Sub
Private Sub cmdStop_Click() 'stop timer
lblDisplay.Caption = ""
cmdStart.Enabled = True
cmdStop.Enabled = False
End Sub
Private Sub Form_Load() 'when project 1st load
MSComm1.CommPort = 1
MSComm1.Settings = "9600,N,8,1"
MSComm1.PortOpen = True 'open the COMM port
End Sub
Private Sub Form_Unload(Cancel As Integer)
MSComm1.PortOpen = False 'close the COMM port
End Sub
The microcontroller have set the program which the PC send the command signal "character Q" and microcontroller will transmit the data in ASCII code (0 to 255) to PC. From the ASCII code, I will convert it to value and do some calculation to get my exact number.
The problem is the 0 showed when I click for get the first data. Then, the second displayed data was the previous one.
e.g. the 1st data suppose is 56 but the 0 showed when I click to get data at first time.
Then, I click again, it showed the 56 which is the previous data.
Suppose the data for that time is 255!!
I have using the hyperterminal to test my hardware and it showed the current data all the time when I click on Q button and no 0 showed at first time clicking. I think that was something problem with my coding.
How to get the current data from it???
I post my code for expert like u to give me guidance and tell me the mistake.
Thanks for helping me.
Private Sub cmdStart_Click() 'GET DATA
Dim ADCValue As String
Dim SolarValue As Double
MSComm1.Output = "Q"
X = MSComm1.Input
Z = (Val(X) * 4.4)
lblDisplay.Caption = Z
End Sub
Private Sub cmdStop_Click() 'stop timer
lblDisplay.Caption = ""
cmdStart.Enabled = True
cmdStop.Enabled = False
End Sub
Private Sub Form_Load() 'when project 1st load
MSComm1.CommPort = 1
MSComm1.Settings = "9600,N,8,1"
MSComm1.PortOpen = True 'open the COMM port
End Sub
Private Sub Form_Unload(Cancel As Integer)
MSComm1.PortOpen = False 'close the COMM port
End Sub