Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2656
  • Last Modified:

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
0
louisdavec
Asked:
louisdavec
  • 8
  • 4
1 Solution
 
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 8
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now