Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MSComm serial input - getting corruption of data

Status
Not open for further replies.

jjjacko

Vendor
May 15, 2001
3
NZ
Hi!

I'm trying to input data from a simple device via COM1, and using VB sample dialer.vbp have been able to make a start. I am reading data, but not correctly. (Windows Hyper terminal gives an 8 digit code - but so far I get other symbols which are different each time I read.)

I have checked:
Baud rate = 9600
Data bits = 8
Stop bit = 1
Parity = N
Handshaking = Xon/Xoff
InBufferCount = 0
InputLen = 0
InputMode = Text

I've coded as follows:

MSComm1.CommPort = 1
MSComm1.Settings = "9600,N,8,1"

On Error Resume Next
MSComm1.PortOpen = True
If Err Then
MsgBox "COM1: not available. Change the CommPort property to another port."
Exit Sub
End If

' Flush the input buffer.
MSComm1.InBufferCount = 0
MSComm1.InputLen = 0
MSComm1.InputMode = comInputModeText


Do
' If there is data in the buffer, then read it.
If MSComm1.InBufferCount Then
If MSComm1.CommEvent > 0 Then
MsgBox(MSComm_CommEvent)
End If
FromScanner$ = MSComm1.Input
'Display input string
MsgBox (FromScanner$)
End If

Loop


I have checked for Errors (OnComm) - but don't seem to be getting any.

Any suggestions - have I missed anything obvious?

Thanks for your help
 
Ok, I think the problem would probably be that all the information doesn't have time to pass through the serial port before continuing the code. So Just at the beginning of the onComm event, I would put a timer here.

good luck.
 
If it is binary data, you should set InputMode = comInputModeBinary. By using a string, your data is being converted to UniCode (if possible) and binary 00's are probably thrown away.
"The InputMode property determines the type of data that is retrieved with the Input property. If InputMode is set to comInputModeText then the Input property returns text data in a Variant. If InputMode is comInputModeBinary then the Input property returns binary data in an array of bytes in a Variant."
Code:
Dim Arr() as Byte

' Set and open port
MSComm1.CommPort = 1
MSComm1.PortOpen = True

' Set InputMode to read binary data
MSComm1.InputMode = comInputModeBinary

If MSComm1.InBufferCount Then
    'Assign to byte array for processing
    Arr = MSComm1.Input
End if
...etc

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top