Solved

Read Serial Communication Port

Posted on 2008-10-29
22
901 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

863 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now