Read & Write in ports COM1 & COM2

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
louisdavecAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SylvainPouliotCommented:
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
louisdavecAuthor Commented:
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
SylvainPouliotCommented:
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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

louisdavecAuthor Commented:
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
louisdavecAuthor Commented:
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
louisdavecAuthor Commented:
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
louisdavecAuthor Commented:
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
louisdavecAuthor Commented:
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
SylvainPouliotCommented:
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
louisdavecAuthor Commented:
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
SylvainPouliotCommented:
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
louisdavecAuthor Commented:
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
moduloCommented:
PAQed with points refunded (50)

modulo
Community Support Moderator
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.