|
-
Aug 14th, 2005, 09:49 AM
#1
Thread Starter
Need-a-life Member
Serial Port
I have two computers connected to each other through the serial port with an RS232 cable. I tried with some snippets I found out there, but I cannot make anything going out of the port to the other computer (MSComm1.OutBufferCount is always 0 regardless what I wrote on its Output property). Does anybody have any example I can try? TIA,
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Aug 14th, 2005, 10:47 AM
#2
New Member
Re: Serial Port
Do you have the right cable? It should be "cross-over"
-
Aug 14th, 2005, 01:41 PM
#3
Thread Starter
Need-a-life Member
Re: Serial Port
It's the same RS232 cable I've used before to transmit files from one machine to another (using Norton Commander, for example).
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Aug 14th, 2005, 02:14 PM
#4
Re: Serial Port
Is your firewall blocking it?
-
Aug 14th, 2005, 02:21 PM
#5
Thread Starter
Need-a-life Member
Re: Serial Port
Nope, both firewalls are disabled and stil the OutBufferCount remains equals to zero. Any ideas?
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Aug 14th, 2005, 02:45 PM
#6
Frenzied Member
Re: Serial Port
Are you using any handshaking (RTS/CTS) in your code?
-
Aug 14th, 2005, 02:45 PM
#7
Frenzied Member
Re: Serial Port
Actually - can you post some code
-
Aug 14th, 2005, 02:50 PM
#8
Thread Starter
Need-a-life Member
Re: Serial Port
On the receiver:
VB Code:
Private Sub Form_Load()
' Use COM2.
MSComm1.CommPort = 2
' 9600 baud, no parity, 8 data, and 1 stop bit.
MSComm1.Settings = "9600,N,8,1"
End Sub
'*************
Private Sub MSComm1_OnComm()
Stop
End Sub
On the sender:
VB Code:
Option Explicit
Private Sub Command1_Click()
Dim sText As Variant
With MSComm1
.PortOpen = True
sText = Chr$(Val(txtSend.Text))
.Output = sText
Do
DoEvents
Loop Until .OutBufferCount = 0
.PortOpen = False
End With
End Sub
Private Sub Form_Load()
' Use COM1.
MSComm1.CommPort = 1
' 9600 baud, no parity, 8 data, and 1 stop bit.
MSComm1.Settings = "9600,N,8,1"
End Sub
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Aug 14th, 2005, 02:52 PM
#9
Thread Starter
Need-a-life Member
Re: Serial Port
 Originally Posted by David.Poundall
Are you using any handshaking (RTS/CTS) in your code?
No. Handshaking = 0 comNone
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Aug 14th, 2005, 03:01 PM
#10
Thread Starter
Need-a-life Member
Re: Serial Port
The cable is Ok, and the firewall is not blocking since I receive these events on the receiver:
comEvDSR: When I open the port on the sender to send a data out (twice)
comEventBreak: When I close the port after (not) sending the data.
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Aug 14th, 2005, 03:23 PM
#11
Frenzied Member
Re: Serial Port
OK - just a couple of points. I am referring to a comprehensive PLC comms routine that I have been successfully running for the past 5 years. But as you may imagine it was written five years ago. Anyway - enough of my problem and on to yours.
Here are a few snippets of my code that works. Unlike yours it works in binary mode though.
My receive code just unloads the Rxbuff array. The data received event fires when I receive the correct number of incoming bytes as PLC comms is quite predictable.
VB Code:
' ---------------------------------------------------------------------
' Globals
Public Rxbuff() As Byte
' ---------------------------------------------------------------------
' Code behind the Form containing the comm control
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive ' Received RThreshold # of chars.
Rxbuff() = MSComm1.Input
Call HandleReceivedData
End Select
End Sub
' ---------------------------------------------------------------------
' called at comms kickoff
Sub InitialiseComms()
frmPlcComms.MSComm1.CommPort = ComPort
frmPlcComms.MSComm1.Settings = "9600,E,7,1"
frmPlcComms.MSComm1.PortOpen = True
frmPlcComms.MSComm1.DTREnable = True
frmPlcComms.MSComm1.RTSEnable = True
frmPlcComms.MSComm1.InputMode = comInputModeBinary
frmPlcComms.MSComm1.InputLen = 0 'Forces entire buffer read
End Sub
' ---------------------------------------------------------------------
' send code
Sub Transmit()
Dim txbuff() As Byte, k as long
Dim SendBuffer(1) As Variant ' VIP for sending Binary
frmPlcComms.MSComm1.InBufferCount = 0 'Flush the RX Buffer
' Dim the TX buffer
redim txbuff(0 to 100)
k = 0
' Send pre-amble
txbuff(k) = &H2 : k = k+1
txbuff(k) = &H31 : k = k+1
txbuff(k) = &H31 : k = k+1
' Add further text to the byte buffer as byte...
' Trim the TXbuffer
ReDim txbuff(0 to k-1)
SendBuffer(1) = txbuff()
frmPlcComms.MSComm1.Output = SendBuffer(1)
' Set the RX buffer length to the value expected from the PLC
frmPlcComms.MSComm1.RThreshold = 1 ' Note - Not typical.
End Sub
Something in that lot may jog your thinking.
-
Aug 14th, 2005, 03:25 PM
#12
Thread Starter
Need-a-life Member
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Aug 14th, 2005, 03:28 PM
#13
Frenzied Member
Re: Serial Port
Hmmm have you tried ....
??
-
Aug 14th, 2005, 03:29 PM
#14
Thread Starter
Need-a-life Member
Re: Serial Port
 Originally Posted by David.Poundall
OK - just a couple of points. I am referring to a comprehensive PLC comms routine that I have been successfully running for the past 5 years. But as you may imagine it was written five years ago. Anyway - enough of my problem and on to yours.
Here are a few snippets of my code that works. Unlike yours it works in binary mode though.
My receive code just unloads the Rxbuff array. The data received event fires when I receive the correct number of incoming bytes as PLC comms is quite predictable.
VB Code:
' ---------------------------------------------------------------------
' Globals
Public Rxbuff() As Byte
' ---------------------------------------------------------------------
' Code behind the Form containing the comm control
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive ' Received RThreshold # of chars.
Rxbuff() = MSComm1.Input
Call HandleReceivedData
End Select
End Sub
' ---------------------------------------------------------------------
' called at comms kickoff
Sub InitialiseComms()
frmPlcComms.MSComm1.CommPort = ComPort
frmPlcComms.MSComm1.Settings = "9600,E,7,1"
frmPlcComms.MSComm1.PortOpen = True
frmPlcComms.MSComm1.DTREnable = True
frmPlcComms.MSComm1.RTSEnable = True
frmPlcComms.MSComm1.InputMode = comInputModeBinary
frmPlcComms.MSComm1.InputLen = 0 'Forces entire buffer read
End Sub
' ---------------------------------------------------------------------
' send code
Sub Transmit()
Dim txbuff() As Byte, k as long
Dim SendBuffer(1) As Variant ' VIP for sending Binary
frmPlcComms.MSComm1.InBufferCount = 0 'Flush the RX Buffer
' Dim the TX buffer
redim txbuff(0 to 100)
k = 0
' Send pre-amble
txbuff(k) = &H2 : k = k+1
txbuff(k) = &H31 : k = k+1
txbuff(k) = &H31 : k = k+1
' Add further text to the byte buffer as byte...
' Trim the TXbuffer
ReDim txbuff(0 to k-1)
SendBuffer(1) = txbuff()
frmPlcComms.MSComm1.Output = SendBuffer(1)
' Set the RX buffer length to the value expected from the PLC
frmPlcComms.MSComm1.RThreshold = 1 ' Note - Not typical.
End Sub
Something in that lot may jog your thinking.
Yes, the key was the "RThreshold" and I had found it (almost at the same time you posted it) at http://www.programmers-corner.com/sourcecode/111.
VB Code:
'enable the oncomm event for every reveived character
.RThreshold = 1
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Aug 14th, 2005, 03:29 PM
#15
Frenzied Member
Re: Serial Port
 Originally Posted by Mc Brain
It seems I made it work.
That's good news. How did you do it ?
-
Aug 14th, 2005, 03:30 PM
#16
Frenzied Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|