MSComm Parity Error

Hello all I have a program in a transition phase. I currently communicate with a weighing scale device. That is a little older and the default settings for the program on my FORM LOAD for the MSComm1
are

MSComm1.CommPort = 1
MSComm1.Settings = "9600,E,7,1"
'MSComm1.InputLen = 0
MSComm1.InputMode = comInputModeText
MSComm1.RThreshold = 20
MSComm1.PortOpen = True

Now with the discontinuance of those scales I have newer scales
that have default factory(settings) of that can not be changed to my knowledge
"9600,N,8,1"

Any suggestions to have one program that can change settings on the fly based on InputBufferCount...

Only one port by the way ;)
[735 byte] By [cubic22] at [2007-11-19 19:59:58]
# 1 Re: MSComm Parity Error
I tested some code on my computer vb6 service pack 5 and it runs fine.

I run on another computer and I get a parity error. 1009 ..??

If (MSComm1.CommEvent = comEvReceive) And (MSComm1.Break = False) Then

If MSComm1.InBufferCount > 21 Then

If (MSComm1.InBufferCount > 24) Then
MsgBox "Please weigh the last two boxes again!"
MSComm1.InBufferCount = 0
MSComm1.PortOpen = False
MSComm1.PortOpen = True
Exit Sub
End If

End If

If MSComm1.InBufferCount = 21 Then
If onepass = False Then
MSComm1.Settings = "9600,E,7,1"
MSComm1.InBufferCount = 0
MSComm1.PortOpen = False
MSComm1.PortOpen = True
onepass = True
MsgBox ("Setting scale please re-weigh.")
Exit Sub
End If
If (onepass = True) Then


wstr = MSComm1.Input


wstr2 = Left(wstr, 8)
length = Len(wstr2)
wstr1 = LTrim(wstr2)
'wstr1 = Mid(wstr2, 2, length)
'wstr1 = LTrim(wstr1)

If val(wstr1) < 1 Then
MsgBox "Could not weigh the box correctly. Please weigh the box again.", vbOKOnly
Exit Sub
End If
If wstr = "" Or val(wstr1) = 0 Then
MsgBox "Please put the weight on the scale."
Exit Sub
End If

End If


ElseIf MSComm1.InBufferCount = 13 Or MSComm1.InBufferCount = 24 Then
If onepass = False Then
MSComm1.PortOpen = False
MSComm1.Settings = "9600,N,8,1"
MSComm1.InBufferCount = 0
MSComm1.PortOpen = True

MsgBox ("Setting scale please re-weigh.")
onepass = True

Exit Sub
End If
If (onepass = True) Then


wstr = MSComm1.Input


wstr2 = Left(wstr, 9)
length = Len(wstr2)
wstr1 = LTrim(wstr2)
wstr1 = Mid(wstr2, 2, length)
wstr1 = LTrim(wstr1)

'If Val(wstr1) < 1 Then
'MsgBox "Could not weigh the box correctly. Please weigh the box again.", vbOKOnly
'Exit Sub
'End If
If wstr = "" Or val(wstr1) = 0 Then
MsgBox "Please put the weight on the scale."
Exit Sub
End If

End If

End If
cubic22 at 2007-11-9 20:10:23 >
# 2 Re: MSComm Parity Error
the Easiest way to handle this is in the Error Routine. When you get a parity error, close the port adjust your settings and then resume next. It should then continue totally transparent to the user.
Bill Crawley at 2007-11-9 20:11:33 >
# 3 Re: MSComm Parity Error
Ok I have recently input the logic to close and re-open the port when the InputBufferCount is a set length. (based on the scale output) .
So I will put it into production soon.

Before I put in the logic out
Anything come to mind if MS Comms controls were updated.
It works at my computer without closing and re-opening . But when I put it out on production it ...:P... kaput..

My computer
Windows XP
Pro
Visual Studio Pro Srvc Pk 5

Their computer
Wndows 2k
Pro
VB 6.
..

thanks for the input though
cubic22 at 2007-11-9 20:12:25 >
# 4 Re: MSComm Parity Error
When you say Kaput...Is that installing the application or running it?

The Comm control itself hasn't changed between XP or W2K. However it is never a good idea to relly on the operating system to handle the opening and closing of the port for you. You should alway's open and close the port in code, then you can be sure that it is in the state that you expect it to be in.
Bill Crawley at 2007-11-9 20:13:30 >