Get reading from Serial COM1 port
Get reading from Serial COM1 port
Get reading from Serial COM1 port
Get reading from Serial COM1 port
Get reading from Serial COM1 port
Get reading from Serial COM1 port Get reading from Serial COM1 port Get reading from Serial COM1 port Get reading from Serial COM1 port Get reading from Serial COM1 port Get reading from Serial COM1 port Get reading from Serial COM1 port Get reading from Serial COM1 port
Get reading from Serial COM1 port Get reading from Serial COM1 port
Get reading from Serial COM1 port
Go Back  Xtreme Visual Basic Talk > > > Get reading from Serial COM1 port


Reply
 
Thread Tools Display Modes
  #1  
Old 06-19-2002, 08:05 AM
salsa
Guest
 
Posts: n/a
Question Get reading from Serial COM1 port


Hi, If anybody understands the MS Comm Control or anyother way of getting signals from serial ports, please help. I hope this doesn't get too long...

Ok, I have a pH meter connected to my COM1 Serial Port, and I would like to create a simple program that displays the pH value from the meter. In the manual for the Corning 315 pH meter, it says interfacing with computers, printers, and other RS232 compatible devices is possible. It says that the type of communications is:

uni directional, baud rate 1200, data format - 1 start bit : 8 data bits : 1 stop bit : no parity

The polarity of the output is the same as the polarity of the input signal.


I took a couple shots at creating a program using the MS Comm Control, but had no luck... but that's in part because I don't really understand the functions to the MS Comm Control.. I think this should be a very simple program to create, just a "start" button to start the program recieving the signal from the pH meter, and then a text box to display the pH value. Can anybody code this? Thanks for the help.

Just for the fun of it, I put the code to my last terrible attempt at MS Comm Control and trying to make a program for this. Don't laugh too hard..

*************

Private Sub Command1_Click()
If MSComm1.CommEvent = comEvReceive Then
Dim Buffer As Variant
Buffer = MSComm1.Input
End Sub

Private Sub Form_Load()

End Sub

Private Sub MSComm1_OnComm()


End If


End Sub

Private Sub Text1_Change()
Text1.Text = MSComm1.Input
End Sub
************
Thanx again
Reply With Quote
  #2  
Old 06-19-2002, 08:12 AM
salsa
Guest
 
Posts: n/a
Default

I forgot to add that the only pin on the serial port that will be recieving the pH value from the pH meter is from pin #2... i don't know if that makes any difference.. but the way that the two have been wired together, only two wires are actually connected with the DB9 connector, one for the data and one for the ground. Pin 2 needs to be read. Thanks again.
Reply With Quote
  #3  
Old 06-19-2002, 08:15 AM
ChiefRedBull's Avatar
ChiefRedBullGet reading from Serial COM1 port ChiefRedBull is offline
ISearchGoogle

Retired Moderator
* Expert *
 
Join Date: May 2001
Location: england
Posts: 6,321
Default

You'd be surprised how close you actually are. All you have to do is set the MSComm properties.
Code:
Private Sub Command1_Click()
  MSComm1.CommPort = 1 ' set the port
  MSComm1.Settings = "1200,n,8,1" ' set the settings
  MSComm1.RThreshold = 1 ' how many characters received per onComm event
  MSComm1.PortOpen = True ' open the port
End Sub

Private Sub MSComm1_OnComm() 

  Select Case MSComm1.CommEvent 
    Case comEvReceive 
        Text1.Text = MSComm1.Input 
  End Select 
End Sub
That should work, but I very rarely use the control myself... Try searching the forum for more info on MSComm.

Also, read these:
http://www.yes-tele.com/mscomm.html
http://www.vbweb.co.uk/show/21/4/
__________________
Chuck Norris ordered a Big Mac at Burger King, and got one.
Reply With Quote
  #4  
Old 06-20-2002, 10:38 AM
salsa
Guest
 
Posts: n/a
Default

Thanks for the info man!

It's not working yet though.. but I also think that now the script is pretty near to correct, if it isn't already.

I think my problem lays here.. and I don't know if you guys can give me an answer to this.

The pH meter has one port for it's ability to communicate, and that is it's 6 pin data socket.

The user's manual for the pH meter says that in order to communicate with a computer, users need to purchase the Interface wire that converts 6 pin socket to RS232 format.

Well, I took into my own hands and decided not to purchase the wire, and created myself from a 6-pin mouse cable and a spare DB9 part laying around, wired the two together. There are only two pins being used in the wire though, one for the ground and one for the data transmitting from the pH meter, which is read at pin 2 on the computer's end.

I don't think the program is working because of this and I was wondering if we could create a program that picks up the signal from pin 2 only?? Please help if possible. Thanks again
Reply With Quote
  #5  
Old 06-20-2002, 01:14 PM
ChiefRedBull's Avatar
ChiefRedBullGet reading from Serial COM1 port ChiefRedBull is offline
ISearchGoogle

Retired Moderator
* Expert *
 
Join Date: May 2001
Location: england
Posts: 6,321
Default

AFAIK the MSComm can't communicate with only one pin at a time, however, there are free DLLs out there on the net that will.
__________________
Chuck Norris ordered a Big Mac at Burger King, and got one.
Reply With Quote
  #6  
Old 06-20-2002, 06:45 PM
ThinkerGet reading from Serial COM1 port Thinker is offline
Iron-Fisted Programmer

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Fayetteville Arkansas USA
Posts: 18,127
Default

Probably all you need to do is tie some pins together on the PC
9 pin connector. The send data and ground lines are all you need
as long as there won't be so much data coming across that the
buffer on the PC is overrun. If it was a 25 pin, I would know what
pins to suggest you tie together, but I never memorized the 9 pin
layout. You need to tie together RTS and CTS, and tie DSR, DTR,
and CD all together. Hope this helps.
__________________
Posting Guidelines
Reply With Quote
  #7  
Old 06-21-2002, 12:30 AM
Sandy
Guest
 
Posts: n/a
Thumbs up

Hey

check here my code. It is funny too but still works. change the setting as you require..

Private Sub Form_Load()
' Use COM1.
MSComm1.CommPort = 1
' 9600 baud, no parity, 8 data, and 1 stop bit.
MSComm1.Settings = "9600,N,8,1"
' Tell the control to read entire buffer when Input is used.
MSComm1.InputLen = 0
' Open the port.
MSComm1.PortOpen = True
End Sub

i read it in the timer

Dim instring As String
If MSComm1.PortOpen = True Then
instring = Trim(MSComm1.Input)
Text1.Text = Text1.Text & instring
End If
End Sub

that is enough i think Check again the settings of scomm

set the threshold right and buffer size
Reply With Quote
  #8  
Old 07-05-2002, 06:42 AM
dynamo
Guest
 
Posts: n/a
Default

Quote:
Originally posted by Sandy
Hey

check here my code. It is funny too but still works. change the setting as you require..

Private Sub Form_Load()
' Use COM1.
MSComm1.CommPort = 1
' 9600 baud, no parity, 8 data, and 1 stop bit.
MSComm1.Settings = "9600,N,8,1"
' Tell the control to read entire buffer when Input is used.
MSComm1.InputLen = 0
' Open the port.
MSComm1.PortOpen = True
End Sub

i read it in the timer

Dim instring As String
If MSComm1.PortOpen = True Then
instring = Trim(MSComm1.Input)
Text1.Text = Text1.Text & instring
End If
End Sub

that is enough i think Check again the settings of scomm

set the threshold right and buffer size
This seems to work with my need. I need to loop this:


" If MSComm1.PortOpen = True Then
instring = Trim(MSComm1.Input)
Text1.Text = Text1.Text & instring"

Could anyone tell me how to set a loop (without overloading processor) and how to send AT-COMMAND: "AT&F&W0"
Reply With Quote
  #9  
Old 07-05-2002, 10:02 AM
BillSoo's Avatar
BillSooGet reading from Serial COM1 port BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

If you go into a loop, you need a way to get out of the loop. One way is to use a boolean flag that is set by a command button:
Code:
Dim bDone as Boolean  'module level or global variable
 .....

While not bDone
     If MSComm1.InBufferCount Then Text1 = Text1 & Trim$(MSComm1.Input)
     DoEvents
Wend
Another way is to use a Timer control and enable/disable it with a button....
Code:
Private Sub Timer1_Timer()
If MSComm1.InbufferCount then Text1.Text = Text1.Text & Trim$(MSComm1.Input)
End Sub
Yet another way is to set the RThreshold of the MSComm control to 1. Then in the ONComm Event, check to see if the CommEvent property is evreceived (something like that...I forget the exact spelling). If it is, input the data.
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
  #10  
Old 07-05-2002, 10:30 AM
dynamo
Guest
 
Posts: n/a
Default

Can this work? (can't test until monday)

Private Sub Command2_Click()

Dim instring As String
Text2.Text = "Program running"

If MSComm1.PortOpen = True Then
Do While PortOpen = True
instring = Trim(MSComm1.Input)
Text1.Text = Text1.Text & instring
Delay (10)
Loop

End If
End Sub
Reply With Quote
  #11  
Old 07-05-2002, 10:37 AM
BillSoo's Avatar
BillSooGet reading from Serial COM1 port BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

As long as your delay sub has a DOEVENTS in it that will allow you to close the port....

Also, I would normally check the InBufferCount size before using Input....I don't think it would matter much in your case though....
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
  #12  
Old 07-05-2002, 10:46 AM
dynamo
Guest
 
Posts: n/a
Default

When I clicked "RUN"-button many times: ...

Private Sub Command1_Click()
Dim instring As String
Text2.Text = "RUN pressed"
If MSComm1.PortOpen = True Then
instring = Trim(MSComm1.Input)
Text1.Text = Text1.Text & instring
End If
End Sub

... program readed received info from COM1 perfectly for the first time. It seems that I need to make a new program (old was serial program (COM1 -> COM2)) and this seems a good start. I just need a loop to get clicks done automatically.

LOOP1:

Private Sub Command2_Click()

Dim instring As String
Text2.Text = "Running looped (Friend's suggestion)"

If MSComm1.PortOpen = True Then
Do While PortOpen = True
instring = Trim(MSComm1.Input)
Text1.Text = Text1.Text & instring
Delay (10)
Loop

End If
End Sub


LOOP2:

Private Sub Command3_Click()
Dim bDone As Boolean 'module level or global variable
Dim instring As String
Text2.Text = "Running looped (boolean)"
If MSComm1.PortOpen = True Then
instring = Trim(MSComm1.Input)
Text1.Text = Text1.Text & instring
End If

While Not bDone
If MSComm1.InBufferCount Then Text1 = Text1 & Trim$(MSComm1.Input)
DoEvents
Wend

End Sub

LOOP3:

Private Sub Command4_Click()
Text2.Text = "Running looped (Timer)"

If MSComm1.InBufferCount Then Text1.Text = Text1.Text & Trim$(MSComm1.Input)
End Sub

3 loops for testing... Also I have to write that readed info to COM2. Will that work if I open COM2 port when the program starts and add "WRITETOCOM2 (I don't know yet how to do that)" before loop ends (after readCOM1)
Reply With Quote
  #13  
Old 07-05-2002, 11:02 AM
dynamo
Guest
 
Posts: n/a
Default

and "disable port / stop program"- button:

Private Sub Command5_Click()
'Disable port
IsPortOpen = False
If (Form1.MSComm1.PortOpen = True) Then
Form1.MSComm1.PortOpen = False
End If

Text2.Text = "Port disabled / Program stopped"
End Sub

My idea for whole program:

set COM1 settings
set COM2 settings

open com1
open com2

loop:

read com1
write com2

close COM1???
close COM2???

loop ends:

program ends
Reply With Quote
  #14  
Old 07-05-2002, 11:08 AM
BillSoo's Avatar
BillSooGet reading from Serial COM1 port BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

Your loop2 and loop3 won't work....

Loop2 has bDone defined as a procedural level module. You need to move it out into the form. Then set it to true in a Cancel Button.

Loop3 doesn't seem to have a timer control anywhere....
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
  #15  
Old 07-05-2002, 11:09 AM
BillSoo's Avatar
BillSooGet reading from Serial COM1 port BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

Quote:
Originally posted by dynamo
My idea for whole program:

set COM1 settings
set COM2 settings

open com1
open com2

loop:

read com1
write com2

close COM1???
close COM2???

loop ends:

program ends
I would not CLOSE the ports INSIDE the LOOP....

And as I said before, you need some method to tell when the loop has ended.
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
  #16  
Old 07-05-2002, 11:25 AM
dynamo
Guest
 
Posts: n/a
Default

Quote:
Originally posted by BillSoo


I would not CLOSE the ports INSIDE the LOOP....

And as I said before, you need some method to tell when the loop has ended.
Sorry, typo (or braino ). port closes when clicked "exit" or "disable port"?

Private Sub mnuExit_Click()

If MsgBox("Do you really want to exit?", vbYesNo + _
vbQuestion, "Quitting") = vbYes Then
'Disable port
IsPortOpen = False
If (Form1.MSComm1.PortOpen = True) Then
Form1.MSComm1.PortOpen = False
End If

'Form1.MSComm1.PortOpen = True
'Form1.MSComm1.PortOpen = False
Text1 = "Port disabled / Program stopped"

' Exit

Unload Me


How would you code loop2 & 3 ? (example )
Reply With Quote
  #17  
Old 07-05-2002, 11:35 AM
BillSoo's Avatar
BillSooGet reading from Serial COM1 port BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

Code:
Dim bDone as boolean

Private Sub Command3_Click()
If MSComm1.PortOpen Then
     bDone = False
     While Not bDone
            If MSComm1.InBufferCount then Text1 = Text1 & MSComm1.Input
            DoEvents  'or put your delay function here, assuming it has
                            'doevents in it somewhere....
     Wend
End If
End Sub

Private Sub CancelButton_Click()
bDone = TRUE
End sub
For loop 3, you add a timer control to your form and set it's interval to, say, 500 (1/2 a second). You then add code like:

Code:
Private sub Timer1_Timer()
If MSComm1.PortOpen Then
     If MsComm1.InBuffercount then Text1 = text1 & mscomm1.input
End If
End Sub

Private Sub CancelButton_Click()
Timer1.Enabled = False
MSComm1.PortOpen = False
End Sub
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
  #18  
Old 07-07-2002, 09:29 AM
dynamo
Guest
 
Posts: n/a
Default

Both "boolean" and "timer" - loops works perfectly (tested today). I selected the boolean loop. Next step is to write that info to COM2

Working loop:

Private Sub cmdRunbooleanloop_Click()
Dim bDone As Boolean

If (frmMain.MSComm1.PortOpen = False) Then
frmMain.MSComm1.PortOpen = True
End If

txtProgramState.Text = "Running looped (boolean)"
If MSComm1.PortOpen Then
bDone = False
While Not bDone
If MSComm1.InBufferCount Then txtCOM1Display.Text = txtCOM1Display.Text & MSComm1.Input
DoEvents 'or put your delay function here, assuming it has
'doevents in it somewhere....
Wend

End If
End Sub





This is my "READ COM1 WRITE COM2 (boolean loop) - button:

Private Sub cmdRead1write2_Click()
Dim bDone As Boolean

If (frmMain.MSComm1.PortOpen = False) Then
frmMain.MSComm1.PortOpen = True
End If

If (frmMain.MSComm2.PortOpen = False) Then
frmMain.MSComm2.PortOpen = True
End If

' MSComm2.PortOpen = True
txtProgramState.Text = "Running looped (boolean)"
If MSComm1.PortOpen Then
bDone = False
While Not bDone
If MSComm1.InBufferCount Then txtCOM1Display.Text = txtCOM1Display.Text & MSComm1.Input

' I ADDED THESE LINES TO WRITE COM2:

MSComm1.Output = MSComm1.Input
MSComm1.Output = MSComm2.Input
txtCOM2Display.Text = txtCOM2Display.Text & MSComm2.Input



DoEvents 'or put your delay function here, assuming it has
'doevents in it somewhere....
Wend
End If
End Sub

What do you think? Do I need "MSComm1.Output = MSComm1.Input" or is COM1input automaticly COM1output?


My modem need reset "AT&F&W0".
If I wirte MSComm1.Input = "AT&F&W0" & vbCrLf it says "property is read only" and wont work.
Reply With Quote
  #19  
Old 07-07-2002, 12:02 PM
ThinkerGet reading from Serial COM1 port Thinker is offline
Iron-Fisted Programmer

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Fayetteville Arkansas USA
Posts: 18,127
Default

Did you try MSComm1.Output = "AT&F&W0" & vbCrLf?
__________________
Posting Guidelines
Reply With Quote
  #20  
Old 07-08-2002, 09:14 AM
dynamo
Guest
 
Posts: n/a
Default

Quote:
Originally posted by Thinker
Did you try MSComm1.Output = "AT&F&W0" & vbCrLf?
Now I tried and it works!

But.... my "READ COM1 WRITE COM2 (boolean loop) -button's code is not working and it loses information...without adding: '' I ADDED THESE LINES TO WRITE COM2:" it works but now it looks like this:

'COM1Display

SI NUMB : 0
SYSTEM TYPE XXXXXXXXXXXXXXX (edited)
LOION : XXXXXXXXXXXXXXX (edited)
SERIAL NUR : A2402143
TIME 15:39:09 08.0002
NONACALARMS
TIME DA STATE ACK PRIORITY DESCRIPTION
3 15:38 08.07.2002 ACTIVE NEED ACK ITICAL BATTERY USE
2 1 15:36 08.07.2002 ACTIVE ED ACK MAJOR RECTIFIER FAUL3 160 15:34 0.2002 NEED ACK TICAL BATTERYUSE

+++

It should look something like this:

'COM1Display

SITE NUMBER : 0
SYSTEM TYPE : XXXXXXXXXXXXXXX (edited)
LOCATION : XXXXXXXXXXXXXXX (edited)
SERIAL NUMBER : A2402143
TIME : 14:52:04 05.07.2002
NON-ACKED ALARMS
TIME DATE STATE ACK PRIORITY DESCRIPTION
3 130 14:51 05.07.2002 ACTIVE NEED ACK CRITICAL BATTERY 1 FUSE
3 129 14:50 05.07.2002 NEED ACK CRITICAL BATTERY 1 FUSE
3 128 14:46 05.07.2002 NEED ACK CRITICAL BATTERY 1 FUSE
2 117 14:25 05.07.2002 ACTIVE NEED ACK MAJOR RECTIFIER FAULT
3 116 14:23 05.07.2002 NEED ACK CRITICAL BATTERY 1 FUSE

SV>+++

and txtCOM2Display.Text shows nothing...

Does it work with only :"MSComm1.Output = MSComm2.Input" ?
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Get reading from Serial COM1 port
Get reading from Serial COM1 port
Get reading from Serial COM1 port Get reading from Serial COM1 port
Get reading from Serial COM1 port
Get reading from Serial COM1 port
Get reading from Serial COM1 port Get reading from Serial COM1 port Get reading from Serial COM1 port Get reading from Serial COM1 port Get reading from Serial COM1 port Get reading from Serial COM1 port Get reading from Serial COM1 port
Get reading from Serial COM1 port
Get reading from Serial COM1 port
 
Get reading from Serial COM1 port
Get reading from Serial COM1 port
 
-->