Data from serial port, but not modem 
Author Message
 Data from serial port, but not modem

Can someone give me an idea of how to use MSCOMM32.OCX to read from a
serial port?  Maybe some lines of sample code?

I'm trying to use a small unit to transmit text via the serial port into my
PC, but all of the samples and instructions I'm finding involves modems.  

Any assistance is appreciated.

thanks--
SLiM Durham



Tue, 10 Aug 1999 03:00:00 GMT  
 Data from serial port, but not modem

a) insert a MScomm into a form
b) set it's properties
c) write code in the MSComm_ONcomm sub e.g. as follows

Private Sub Comm1_OnComm()

Dim SynPos          As Integer          'paketin alkumerkin positio
Dim PadPos          As Integer          'paketin loppumerkin positio
Dim TempBuf         As String
Dim Endpos          As Integer
Dim Ok              As Integer
Dim Index           As Integer
Dim OrgBaud         As Integer
Dim NxtBaud         As Integer
Dim OrgPos          As Integer

 On Error Resume Next
 If Not Me.Comm1.PortOpen Then Exit Sub
 Index = Val(Me.Tag)
 Select Case Me.Comm1.CommEvent
  Case comEvDSR

  Case comEvRing
   'Call AddText("|RING|", 5, Index)
  Case comEvReceive
    Me.Comm1.InputLen = 0     'get all data
    GB_Blockbuf$(Index) = GB_Blockbuf$(Index) + Me.Comm1.Input

    'Valid blocks begin always with SYN+SYN
    SynPos = InStr(GB_Blockbuf$(Index), GB_SYNSYN)
    If SynPos = 0 Then Exit Sub
    'Get Rid of SYNs (temp !)
    TempBuf$ = Mid$(GB_Blockbuf$(Index), SynPos + 2)

    'Valid blocks end always with PAD+PAD
    PadPos = InStr(TempBuf$, GB_PADPAD)
    If PadPos = 0 Then Exit Sub

    Ok = True   'Default is Packet OK (ACK, ENQ etc do not contain data !)
    If InStr(TempBuf$, GB_STX) = 1 Then     'Data block
        'Find LAST PAD character (may be also in the DATA or CRCs)
        Do
            OrgPos = PadPos
            PadPos = InStr(PadPos + 1, TempBuf$, Left$(GB_PADPAD, 1))
        Loop Until (PadPos = 0)
        PadPos = OrgPos - 1

        'Packet is complete IF DLE+ETX or DLE+ETB are -4 positions from the
PAD
        Select Case Mid$(TempBuf$, PadPos - 4, 2)
            Case GB_DLE + GB_ETX, GB_DLE + GB_ETB: Ok = True
            Case Else
                Ok = False
        End Select
    ElseIf InStr(TempBuf$, GB_SOH) = 1 Then 'Start of Heading, same tricks
as above
        'Note: NO DLE-ETB - just plain ETB or ETX
        Select Case Mid$(TempBuf$, PadPos - 3, 1)
            Case GB_ETX, GB_ETB: Ok = True
            Case Else
                Ok = False
        End Select
    End If

    If Ok Then
        GB_Blockbuf$(Index) = Left$(TempBuf$, PadPos + 1)
        GB_Disc_Timer!(Index) = Timer
        Call TMS_Got_Packet(GB_Blockbuf$(Index), Index)  'process data ...
             GB_Blockbuf$(Index) = ""
    End If

 End Select
end sub



Quote:
> Can someone give me an idea of how to use MSCOMM32.OCX to read from a
> serial port?  Maybe some lines of sample code?

> I'm trying to use a small unit to transmit text via the serial port into
my
> PC, but all of the samples and instructions I'm finding involves modems.

> Any assistance is appreciated.

> thanks--
> SLiM Durham




Tue, 10 Aug 1999 03:00:00 GMT  
 Data from serial port, but not modem

This is just slightly modified from MS help file, I think this is correct,
but most of my serial comm code is on my home PC, so hopefully this helps.
If you have an additional question, send me an email to my home email:  

Private Sub Form_Load ()
        ' Use COM1.
        Comm1.CommPort = 1
        ' 9600 baud, no parity, 8 data, and 1 stop bit.
        Comm1.Settings = "9600,N,8,1"
        ' Tell the control to read entire buffer when Input is used.
        Comm1.InputLen = 0
        ' Open the port.
        Comm1.PortOpen = True
        ' Send the output data to xxx serial device
        Comm1.Output = "YOUR STRING HERE TO SEND"
        ' Wait for data to come back to the serial port.
        Do
                Dummy = DoEvents()
        Loop Until Comm1.InBufferCount >= 1   'or the number of characters you
expect to receive before processing incoming data

        ' Read the response data in the serial port.
        InString$ = Comm1.Input

' Close the serial port.
        Comm1.PortOpen = False
End Sub



Quote:
> Can someone give me an idea of how to use MSCOMM32.OCX to read from a
> serial port?  Maybe some lines of sample code?

> I'm trying to use a small unit to transmit text via the serial port into
my
> PC, but all of the samples and instructions I'm finding involves modems.

> Any assistance is appreciated.

> thanks--
> SLiM Durham




Tue, 10 Aug 1999 03:00:00 GMT  
 Data from serial port, but not modem

Quote:

> Can someone give me an idea of how to use MSCOMM32.OCX to read from a
> serial port?  Maybe some lines of sample code?

> I'm trying to use a small unit to transmit text via the serial port into my
> PC, but all of the samples and instructions I'm finding involves modems.

> Any assistance is appreciated.

> thanks--
> SLiM Durham


Take a look at the source code at
http://members.aol.com/rander1040/index.html.

Randy



Tue, 10 Aug 1999 03:00:00 GMT  
 Data from serial port, but not modem

A modem is a perfectly good example of how to send and receive serial data.
 The commands that you send to a modem are analogous to commands or data
that you might sent to the connected device.  The modem responses are just
like data that you would receive from the same device.

Just because the example is a modem doesn't mean that it isn't valid -- the
differences will be in the details, not in the theory.

If you have a specific question, I'll be glad to try to help.
--
{*filter*} Grier
Hard & Software
12962 West Louisiana Avenue
Lakewood, CO  80228
303-986-2179 (voice)
303-986-3143 (fax)




Tue, 10 Aug 1999 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. help w/ serial port - but not modem

2. Help to program the serial port (null modem) with the win32 api (not MSComm)

3. Serial port/modem access/file transfer in VB

4. VB Communications, MSComm, Serial Ports and Modems...

5. Modems, Serial Ports, MSComm and VB

6. Modem, serial port, MSComm and VB Communications

7. Serial port, MSComm, Modem and VB communication

8. ocx that handles modem and serial port !!

9. Getting modem serial port

10. Getting modem serial port

11. I/O port, Parallel port, Serial port

12. Modems and Modem Ports

 

 
Powered by phpBB® Forum Software