Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Read Serial Communication Port

Posted on 2008-10-29
22
Medium Priority
?
934 Views
Last Modified: 2013-12-26
Hello Experts.
I am using VB6.

A program is running, and this Program is writing to the Serial Communication Port.
I need to write a Program- To run on the same machine at the same time - , that will be able to read that port.

Is this possible ?
If Yes, can you please show me how ?

Thanks
0
Comment
Question by:HESUS
  • 11
  • 9
22 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 22831545
Did you take a look at the following event:

Connection eg:
MSComm1.CommPort = 1
MSComm1.Settings = "9600,n,8,1"
MSComm1.PortOpen = True


Private Sub MSComm1_OnComm()

On Error Resume Next

If MSComm1.CommEvent = comEvReceive Then
msgbox MSComm1.Input
End If

End Sub
0
 

Author Comment

by:HESUS
ID: 22832040
Thank you very much.
If another program is already writing to the Comm Port, will my application still be able to view it as well ?
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 22833139
I doubt that, because you're one program has already the port blocked for communication. You can try it to see if your program works...
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:HESUS
ID: 22833807
It is not working.
I am looking for a way to read whats in the Comm buffer, even if another application is using the Comm Port.
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 22833970
I don't see why you would one program one the pc would send items, and another program on the same computer will receive the items...
0
 

Author Comment

by:HESUS
ID: 22834049
Because one Program is not mine, and this program is sending data to the RS232 Port.
I need to read that data for my application.
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 22839356
Then you'll have a problem, because the com-port is blocked by your first program until the program closes the connection with your comp-ort.
0
 

Author Comment

by:HESUS
ID: 22839598
But isn't there any way that I can read the Comm Port buffer ?
0
 

Author Comment

by:HESUS
ID: 22861191
Please Experts, if anybody can assist here...
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 22861528
You can't reaed it while the port is in use by the other program. Only one application at the time can use it.
0
 

Author Comment

by:HESUS
ID: 22861883
I am not trying to be difficult, I am just desperate&
The data is sitting in a buffer somewhere. Is there no way to read this buffer not using an Mscomm ?
0
 

Author Comment

by:HESUS
ID: 22865449
Just of interest, I talked to someone that wrote a program to listen to the Comm Port while other program is writing to it. He wrote his program in Delphi.
If Delphi can do it, why VB can not ?
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 22865527
>> If Delphi can do it, why VB can not ?

Are you sure that the program is listening/writing to the same com-port on the same pc ?
I also wrote already some communication through the comport, but it always was on different pc's (one pc was sending/receiving, the other also)
0
 

Author Comment

by:HESUS
ID: 22866120
I am 100% sure.
One Application is writing to the Comm Port - for an external equipment, and second application is listenning to the same Comm port and writes it to file. Both applications are running on the Same PC.
0
 

Author Comment

by:HESUS
ID: 22893232
I am still waiting for a solution in VB.
Please assist me, I am stuck...
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 22893244
Maybe a solution, I'm not sure because I haven't tested it
It has to do something with the MSComm1.PortOpen-setting

Communication over Serial Port for VB6 - Visual Basic 6
http://www.programmers-corner.com/sourcecode/111
0
 

Author Comment

by:HESUS
ID: 22893339
Thanks Dhaest for not giving up on me.
The url you sent to me will not let me access it. It says that I do not have permission to access the site.
Any suggestions ?

Thanks
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 22893348
This is the  complete code
(next time if you have a difficult question, increase your points. There will be more experts looking at the question)
'1 form with
'1 textbox : name=text1, multiline=true, scrollbars=3(both)
'1 textbox : name=text2
'1 command button
'1 mscomm control (Microsoft Comm Control 6.0)
Option Explicit
 
Private Sub Command1_Click()
  With MSComm1
    'make sure the serial port is open
    If .PortOpen = False Then .PortOpen = True
    'send the data (including a tailing carriage return as often needed)
    .Output = Text2.Text & vbCr
  End With 'MSComm1
  With Text2
    'place the focus back to the textbox
    .SetFocus
    'select the current text to be overwritten
    .SelStart = 0
    .SelLength = Len(.Text)
  End With 'Text1
End Sub
 
Private Sub Form_Load()
  With MSComm1
    'make sure the serial port is not open (by this program)
    If .PortOpen Then .PortOpen = False
    'set the active serial port
    .CommPort = 2
    'set the badurate,parity,databits,stopbits for the connection
    .Settings = "9600,N,8,1"
    'set the DRT and RTS flags
    .DTREnable = True
    .RTSEnable = True
    'enable the oncomm event for every reveived character
    .RThreshold = 1
    'disable the oncomm event for send characters
    .SThreshold = 0
    'open the serial port
    .PortOpen = True
  End With 'MSComm1
  With Text1
    'set the properties for the displaying textbox
    .BackColor = vbCyan
    .Locked = True
    .Text = ""
  End With 'Text1
  With Text2
    'set the properties for the 'send' textbox
    .TabIndex = 0
    .Text = ""
  End With 'Text2
  With Command1
    'set the properties for the 'send' command button
    .Caption = "&Send"
    .Default = True
    .TabIndex = 1
  End With 'Command1
End Sub
 
Private Sub Form_Resize()
  Dim sngWidth As Single, sngHeight As Single
  Dim sngDisplayHeight As Single
  Dim sngTxtWidth As Single
  Dim sngCmdWidth As Single, sngCmdHeight As Single
  'calculate the inner size of the form
  sngWidth = ScaleWidth
  sngHeight = ScaleHeight
  With Command1
    'resize and reposition the command button
    sngCmdHeight = .Height
    sngCmdWidth = .Width
    sngDisplayHeight = sngHeight - sngCmdHeight
    sngTxtWidth = sngWidth - sngCmdWidth
    .Move sngTxtWidth, sngDisplayHeight, sngCmdWidth, sngCmdHeight
  End With 'Command1
  'resize and reposition the label
  Text1.Move 0, 0, sngWidth, sngDisplayHeight
  'resize and reposition the textbox
  Text2.Move 0, sngDisplayHeight, sngTxtWidth, sngCmdHeight
End Sub
 
Private Sub MSComm1_OnComm()
  Dim strInput As String
  With MSComm1
    'test for incoming event
    Select Case .CommEvent
      Case comEvReceive
        'display incoming event data to displaying textbox
        strInput = .Input
        Text1.SelText = strInput
    End Select
  End With 'MSComm1
End Sub

Open in new window

0
 

Author Comment

by:HESUS
ID: 22893421
Thank you.
The code is not talking to the Comm port if another program is already using it.

I am taking your advise and raising the points.
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 22893468
Like I said earlier... I'm afraid that through vb6 there is no solution for your problem. One vb-program will be exclusively locking the com-port. As long as it's locked, it can't be used by other programs !
0
 

Accepted Solution

by:
ee_auto earned 0 total points
ID: 25783673
Question PAQ'd, 250 points refunded, and stored in the solution database.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question