More Serial Port Stuff

  • Thread starter Thread starter tkosel
  • Start date Start date
T

tkosel

I need to read data in from a serial port. (Scale is attached that sends
data.) I can read the data from the scale using Hyperterminal just fine.

I created the following code. Can you see why it doesn't work? It loops
forever
never seems to get any input.
Do I need to provide more explanation?
Is there a better way to do it?

Private Sub ReadComm_Click()
Dim V_IncomingDataStream
Me.MSCommU.CommPort = Me.ComPort
Me.MSCommU.Settings = Me.baudrate & "," & Me.Parity & "," & Me.DataBits
& "," & Me.StopBits

If Me.MSCommU.PortOpen = False Then
Me.MSCommU.PortOpen = True
End If

If Me.MSCommU.PortOpen = True Then
Do
V_IncomingDataStream = V_IncomingDataStream & Me.MSCommU.Input
If V_IncomingDataStream <> "" Then
Me.Unparsed = V_IncomingDataStream
Me.ComInputData = Val(Mid(V_IncomingDataStream, 5, 10))
End If
Loop Until InStr(V_IncomingDataStream, "g")
End If

If Me.MSCommU.PortOpen = True Then
Me.MSCommU.PortOpen = False
End If

Done:

End Sub
 
I need to read data in from a serial port. (Scale is attached that sends
data.) I can read the data from the scale using Hyperterminal just fine.

I created the following code. Can you see why it doesn't work? It loops
forever
never seems to get any input.
Do I need to provide more explanation?
Yes :-)
What are the values for me.baudrate etc? Presumably they are set somewhere else?

Possibly give an example of the incoming data stream.

You could connect another pc (or laptop) using a null modem cable and
hyperterminal (or something better like Brays Terminal) and use breakpoints to
see what happens with each character typed on the laptop.
 
Geo said:
Yes :-)
What are the values for me.baudrate etc? Presumably they are set somewhere else?

Possibly give an example of the incoming data stream.

You could connect another pc (or laptop) using a null modem cable and
hyperterminal (or something better like Brays Terminal) and use breakpoints to
see what happens with each character typed on the laptop.

Geo,

Yes, the values for those settings are set in some Public variables set
elsewhere and are correct. (2400, 7,e,1 and port number 1)

Me.MSCommU.CommPort = Me.ComPort
Me.MSCommU.Settings = Me.baudrate & "," & Me.Parity & "," & Me.DataBits
& "," & Me.StopBits

I have already connected another computer with a null modem cable and sent
the string using it. The string is simple:

12.32 g

(Carriage Return Line feed at the end of the line.)

As I mentioned, Hyperterminal reads the data fine, Access won't using the
code I provided. Interestingly enough, when HT is connected, the sending
computer using hyperterminal to send, sends it like zip, real fast. When
connected to the Access computer, it sends it real slow, like a character
every 3 or 4 seconds. At least thats what appears on the sending computers
screen during the send.

I have inserted breakpoints and it gets into my do loop fine, but never gets
out. The port gets open, but its like the INPUT statement doesn't work.
(V_IncomingDataStream = V_IncomingDataStream & Me.MSCommU.Input)
V_IncomingDataStream is another public variable.
 
Yes, the values for those settings are set in some Public variables set
elsewhere and are correct. (2400, 7,e,1 and port number 1)

Me.MSCommU.CommPort = Me.ComPort
Me.MSCommU.Settings = Me.baudrate & "," & Me.Parity & "," & Me.DataBits
& "," & Me.StopBits

I have already connected another computer with a null modem cable and sent
the string using it. The string is simple:

12.32 g

(Carriage Return Line feed at the end of the line.)

As I mentioned, Hyperterminal reads the data fine, Access won't using the
code I provided. Interestingly enough, when HT is connected, the sending
computer using hyperterminal to send, sends it like zip, real fast. When
connected to the Access computer, it sends it real slow, like a character
every 3 or 4 seconds. At least thats what appears on the sending computers
screen during the send.

I have inserted breakpoints and it gets into my do loop fine, but never gets
out. The port gets open, but its like the INPUT statement doesn't work.
(V_IncomingDataStream = V_IncomingDataStream & Me.MSCommU.Input)
V_IncomingDataStream is another public variable.

I am not too familiar with HT (I refuse to use it for serious work) but could it
be that the handshaking lines are not set correctly when using access (DTR and
RTS)? If you have an RS232 breakout box or similar with LEDs this might show a
problem.
An other possible thing to try is setting MSCommU.InputLen = 0 (if not already
done).
No doubt an expert will arrive shortly...
 
Geo said:
I am not too familiar with HT (I refuse to use it for serious work) but could it
be that the handshaking lines are not set correctly when using access (DTR and
RTS)? If you have an RS232 breakout box or similar with LEDs this might show a
problem.
An other possible thing to try is setting MSCommU.InputLen = 0 (if not already
done).
No doubt an expert will arrive shortly...

Geo,

Thanks so much for your suggestions regarding Handshaking. Thats what it
was. The default for that control is no handshaking. I set it to:

Me.MSCommU.Handshaking = 3

and it works fine. Again, I thank you for your suggestion, it was good!!!
 
Thanks so much for your suggestions regarding Handshaking. Thats what it
was. The default for that control is no handshaking. I set it to:

Me.MSCommU.Handshaking = 3

and it works fine. Again, I thank you for your suggestion, it was good!!!

Glad you got it working :-)
 
If you are looking for an excellent tool for inputting data from a
scale to an Access database, you might want to try a program called
WinWedge. WinWedge is an exectuable program that runs in the
background and reads in serial data from scales, barcode scanners and
other RS232 devices and feeds data directly from those devices
directly to any other Windows application. It can send the data to
other programs either by stuffing the keyboard buffer or by using
Dynamic Data Exchange (DDE). It works extremely well for inputting
data from a scale to any Access database.
Visit: www.taltech.com for more information.
 
Back
Top