The problem I see after Start or Start with Full Compile is that the first DeBug.Print listing sometimes(50% of the time) shows the HByte and LByte reversed. By clearing the buffer at the end of the If statement, the second cycle and subsequent cycles show the HByte and LByte correctly.
I've tried placing the "MSComm1.InBufferCount = 0" above the If Statement but that causes an error at the 1st HighByte calculation.
I believe the header info is correct, the code is straight from Reynolds Electronics.
http://www.rentron.com/receiving_data.htm
VB Code:
' If comEvReceive Event then get data and display If MSComm1.CommEvent = comEvReceive Then ' Get data (2 bytes) sData = MSComm1.Input lHighByte = Asc(Mid$(sData, 1, 1)) ' Get 1st byte lLowByte = Asc(Mid$(sData, 2, 1)) ' Get 2nd byte 'Look at the HighByte and LowByte Debug.Print "HB=", CStr(lHighByte), " ", "LB=", CStr(lLowByte) ' Combine bytes into a word lWord = (lHighByte * &H100) Or lLowByte ' Convert value to a string and display lblRCTime.Caption = CStr(lWord) 'Clear Buffer so next cycle will be correct MSComm1.InBufferCount = 0 End If


Reply With Quote