?
Solved

Read & Write in ports COM1 & COM2

Posted on 2003-03-24
14
Medium Priority
?
2,538 Views
Last Modified: 2013-12-26
Hi,
I try to access (read & write) to the serial ports with PB7 in a easy way.
Can anyone help me?
Thanks in advance.
Louisdavec
0
Comment
Question by:louisdavec
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 4
14 Comments
 
LVL 2

Expert Comment

by:SylvainPouliot
ID: 8195139
you can use the mscomm32.ocx object.
Look for it in your system/system32 directory.

Put this ole in your window, then use this code to talk to it

OLE_1.Object.CommPort(1)
OLE_1.Object.Settings(1200,N,8,1)
OLE_1.Object.InputLen(0)
OLE_1.Object.NullDiscard(TRUE)
OLE_1.Object.Rthreshold(1)
OLE_1.Object.PortOpen(TRUE)
OLE_1.Object.OutPut = 'MyData'
OLE_1.Object.PortOpen(FALSE)

Look for an answer in the oncomm event of your control.
0
 

Author Comment

by:louisdavec
ID: 8205034
Well, I have use que output function and run.
But what's about que input function. Is imposible to receive something by com1.
I'm looking for information about the functions of the mscomm32.ocx but I don't find.
Anyone know where I can find this information?
0
 
LVL 2

Expert Comment

by:SylvainPouliot
ID: 8205066
In the oncomm event of your mscomm32 control.

String Ls_Dump
IF String(OLE_1.Object.CommEvent) = '2' THEN
     Ls_Dump = String(OLE_1.Object.Input)
ELSE
     OLE_1.Object.Input
END IF
0
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!

 

Author Comment

by:louisdavec
ID: 8208623
Well, I have use que output function and run.
But what's about que input function. Is imposible to receive something by com1.
I'm looking for information about the functions of the mscomm32.ocx but I don't find.
Anyone know where I can find this information?
0
 

Author Comment

by:louisdavec
ID: 8208707
First at all, thanks for yours comments.
I think that the oncomm event never fires.
The communications are fine because I check with the hiperterminal and characters are sending and received.
I change the Rthreshold and InputLen functions but doesn't run.
Any other suggestions?
0
 

Author Comment

by:louisdavec
ID: 8208709
First at all, thanks for yours comments.
I think that the oncomm event never fires.
The communications are fine because I check with the hiperterminal and characters are sending and received.
I change the Rthreshold and InputLen functions but doesn't run.
Any other suggestions?
0
 

Author Comment

by:louisdavec
ID: 8208747
First at all, thanks for yours comments.
I think that the oncomm event never fires.
The communications are fine because I check with the hiperterminal and characters are sending and received.
I change the Rthreshold and InputLen functions but doesn't run.
Any other suggestions?
0
 

Author Comment

by:louisdavec
ID: 8209143
Now the problem is the function input.
Always the same error: Error accessing external object property input at line 6 in oncomm event of object ole_1
The line 6 is the following:
Ls_Dump = String(OLE_1.Object.Input)
I've tried change the type of Ls_dump to Blob or not convert to String the input but doesn't run.
0
 
LVL 2

Expert Comment

by:SylvainPouliot
ID: 8210363
Does your ole_1 control has a Phone picture in it?

I had a similar problem once, and I had lost my link between my app and my control.

Try inserting a second mscomm32 control and deleting the old one.


Do you have MSDN from Microsoft?  Every Method/Event/properties are described...
Here's the example:

Private Sub Form_Load ()
   ' Buffer to hold input string
   Dim Instring As String
   ' 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
   ' Send the attention command to the modem.
   MSComm1.Output = "ATV1Q0" & Chr$(13) ' Ensure that
   ' the modem responds with "OK".
   ' Wait for data to come back to the serial port.
   Do
      DoEvents
   Buffer$ = Buffer$ & MSComm1.Input
   Loop Until InStr(Buffer$, "OK" & vbCRLF)
   ' Read the "OK" response data in the serial port.
   ' Close the serial port.
   MSComm1.PortOpen = False
End Sub

0
 

Author Comment

by:louisdavec
ID: 8211208
Thank for the example, but the problem is the buffer.
Always detect that the property InBufferCount is zero.
I do not why because when a press a key in the sender computer the on_comm event always fired.
And if I change the RTrheshold property to 3, the on_comm event trigger with the third key.
The system detect that a key has been pressed in the sender computer but don't receive that character.
In debug mode, pb7 always show a error and close it, but before close, in a watching variable, I can see that que character is recepted.
Anyone know more about it?
0
 
LVL 2

Expert Comment

by:SylvainPouliot
ID: 8221936
Hi

Are you sending text data?

Make sure that
object.InputMode = 0 //or 1 for binary

You can also try
object.NullDiscard  = true


Can you try the same "code" in VB to see if your connection or control is the problem?

if not, give me an email adresse where I can send you a TestApp...



0
 

Author Comment

by:louisdavec
ID: 8223874
At the end, the problem has been solved.
It was that I put the input function inside the oncomm event and I don't know why, never read the com and always the inbuffercount property was zero.
I tried to move this code out of this event and TACHAN¡¡¡
no problems to send or read data.
Thank you very much for all yours efforts and I sorry for all the time that you have loose help me.
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12591921
PAQed with points refunded (50)

modulo
Community Support Moderator
0

Featured Post

Technology Partners: 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

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
Suggested Courses

770 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