Solved

Writing to com port using MsAccess, Accessing Hyperterminal saved profile settings to connect to device

Posted on 2004-04-05
13
1,625 Views
Last Modified: 2012-05-04
I have an LED sign "Pro-Lite PL-M2014R" that I need to communicate with, It has a simple html like protocol that is used to communicate with and I have accomplished this with Hyperterminal. Below are the steps used to test the sign. I need to develop a way to send a record in an access table to the sign using this protocol. I need help with how to setup communication between access2002 and the com port.

1.      Open up Hyper Terminal, Go to START, ALL PROGRAMS, ACCESSORIES, COMMUNICATIONS,
2.      Open up a New Connection
3.      Name the New Connection (anything you want)
4.      Choose the Icon with the big phone (red) and the little phone (yellow)
5.      Press OK
6.      When the Connect To dialog box opens in Connect Using choose the correct COM
7.      When the Com Properties dialog box opens under bits per second choose the baud rate of 300
8.      Data bits 8, Parity None, Stop bits 1, and Flow control None
9.      Press Apply if available then press OK
10.      Then go to File/Properties
11.      Choose the Settings Tab
12.      Then Choose ASCII Setup
13.      Under ASCII Sending
14.      Check- Send line ends with line feeds
15.      Check- Echo typed characters locally
16.      Set Line delay to 1200 milliseconds
17.      Character delay to 0 milliseconds
18.      Under ASCII Receiving
19.      Check- Append line feeds to incoming line ends
20.      Do not Check- Force incoming data to 7-bit ASCII
21.      Check- Wrap lines that exceed terminal width
22.      Press OK then Press OK again
Then do the following in all caps and if you make mistakes you must start all over again type the command:
<ID01><PA>TEST
23.      Press Enter
24.      If it did not work type the command again and press enter
25.      If it did not work again send the command <ID00><PA> TEST and press enter
26.      If it did not work type the command again and press enter

Link to protocol information:
http://wls.wwco.com/ledsigns/prolite/ProliteProtocol.html

Thank you,
0
Comment
Question by:Dalexan
  • 7
  • 5
13 Comments
 

Author Comment

by:Dalexan
ID: 10780034
is this Difficult, should I increase points?
0
 

Author Comment

by:Dalexan
ID: 10780357
Can someone atleast give me an example of how to use mscommlib in access vba to connect to com2?
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10788488
some sample code here that uses mscommlib, would this help

http://www.visualbasicforum.com/showthread.php?t=72936


basically its creating a MSCOMMLIB object

0
 

Author Comment

by:Dalexan
ID: 10788737
Thats a great link, trying it out now...
0
 

Author Comment

by:Dalexan
ID: 10788923
OK I can follow through this code and kinda see how it works but I still need more help I have increased the points to this due to the complexity and time needed for my help.

Below is the code from the link I think it is useable for what I am trying to accomplish "writing to a Prolite LED sign via com port"

In the below code the statement "Set mComm = CreateObject("MSCOMMLIB.MSCOMM")" when i type in MSCOMMLIB. I can look through the property list and MSCOMM is not there?



Public Property Get OutBufferCount() As Integer

On Error GoTo ErrHandler
OutBufferCount = mComm.OutBufferCount
Exit Property

ErrHandler:
If oErrorHandler.ErrReport(Err, Erl, "cMSComm", "OutBufferCount") Then Resume Next
End Property

Public Property Let PortOpen(ByVal NewValue As Boolean)

On Error GoTo ErrHandler
If m_PortOpen = False And NewValue = True Then
Set mComm = CreateObject("MSCOMMLIB.MSCOMM")     ,<------ this is not coming up as a property of MSCOMMLIB.
With mComm
.ParityReplace = vbNullString
.Settings = m_Settings
.CommPort = m_CommPort
.DTREnable = m_DTREnable
.Handshaking = m_Handshaking
.InBufferSize = m_InBufferSize
.InputLen = m_InputLen
.InputMode = m_InputMode
.OutBufferSize = m_OutBufferSize
.RThreshold = m_RThreshold
.SThreshold = m_SThreshold
.RTSEnable = m_RTSEnable
.PortOpen = True
End With
m_PortOpen = True
ElseIf NewValue = False Then
mComm.PortOpen = False
Set mComm = Nothing
m_PortOpen = False
End If
Exit Property

ErrHandler:
If oErrorHandler.ErrReport(Err, Erl, "cMSComm", "PortOpen") Then Resume Next
End Property

Public Property Get PortOpen() As Boolean

On Error GoTo ErrHandler
PortOpen = m_PortOpen
Exit Property

ErrHandler:
If oErrorHandler.ErrReport(Err, Erl, "cMSComm", "PortOpen") Then Resume Next
End Property

Public Property Get CommPort() As Integer
CommPort = m_CommPort
End Property

Public Property Let CommPort(ByVal NewValue As Integer)
m_CommPort = NewValue
If m_PortOpen = True Then mComm.CommPort = NewValue
End Property

Public Property Get DTREnable() As Boolean
DTREnable = m_DTREnable
End Property

Public Property Let DTREnable(ByVal NewValue As Boolean)
m_DTREnable = NewValue
If m_PortOpen = True Then mComm.DTREnable = NewValue
End Property

Public Property Get Handshaking() As FlowControl
Handshaking = m_Handshaking
End Property

Public Property Let Handshaking(ByVal NewValue As FlowControl)
m_Handshaking = NewValue
If m_PortOpen = True Then mComm.Handshaking = NewValue
End Property

Public Property Get InBufferSize() As Integer
InBufferSize = m_InBufferSize
End Property

Public Property Let InBufferSize(ByVal NewValue As Integer)
m_InBufferSize = NewValue
If m_PortOpen = True Then mComm.InBufferSize = NewValue
End Property

Public Property Get InputLen() As Integer
InputLen = m_InputLen
End Property

Public Property Let InputLen(ByVal NewValue As Integer)
m_InputLen = NewValue
If m_PortOpen = True Then mComm.InputLen = NewValue
End Property

Public Property Get InputMode() As Mode
InputMode = m_InputMode
End Property

Public Property Let InputMode(ByVal NewValue As Mode)
m_InputMode = NewValue
If m_PortOpen = True Then mComm.InputMode = NewValue
End Property

Public Property Get OutBufferSize() As Integer
OutBufferSize = m_OutBufferSize
End Property

Public Property Let OutBufferSize(ByVal NewValue As Integer)
m_OutBufferSize = NewValue
If m_PortOpen = True Then mComm.OutBufferSize = NewValue
End Property

Public Property Get RThreshold() As Integer
RThreshold = m_RThreshold
End Property

Public Property Let RThreshold(ByVal NewValue As Integer)
m_RThreshold = NewValue
If m_PortOpen Then mComm.RThreshold = NewValue
End Property

Public Property Get SThreshold() As Integer
SThreshold = m_SThreshold
End Property

Public Property Let SThreshold(ByVal NewValue As Integer)
m_SThreshold = NewValue
If m_PortOpen Then mComm.SThreshold = NewValue
End Property

Public Property Get RTSEnable() As Boolean
RTSEnable = m_RTSEnable
End Property

Public Property Let RTSEnable(ByVal NewValue As Boolean)
m_RTSEnable = NewValue
If m_PortOpen = True Then mComm.RTSEnable = NewValue
End Property

Public Property Get CDHolding() As Boolean
If m_PortOpen = True Then CDHolding = mComm.CDHolding
End Property

Public Property Get CTSHolding() As Boolean
If m_PortOpen = True Then CTSHolding = mComm.CTSHolding
End Property

Public Property Get DSRHolding() As Boolean
If m_PortOpen = True Then DSRHolding = mComm.DSRHolding
End Property

Public Property Get Settings() As String
If m_PortOpen Then Settings = mComm.Settings
End Property

Public Property Let Settings(ByVal NewValue As String)
m_Settings = NewValue
If m_PortOpen Then mComm.Settings = NewValue
End Property


'Example
Private Sub Command3_Click()
Dim oComm As cMSComm
Set oComm = New cMSComm

With oComm
.CommPort = iPort
.Settings = strBaud & "," & strParity & "," & strDatabit & "," & strStopbit
.OutBufferSize = 1024
.InBufferSize = 1024
.RThreshold = 1
.SThreshold = 1
.DTREnable = True
.InputMode = 1 'Note: Binary transmission is generally the most reliable
End With

On Error Resume Next
oComm.PortOpen = True
If Not Err.Number = 0 Then
Set oComm = Nothing
Exit Sub
End If

'Note: transmission of data as a byte array for this device
Call oComm.Output(Convert_StringToByteArray(strTerminate))   ,<----- is this where i could have a string from
                                                                                                       ,a textbox or a record in a table written out?
If Not Err.Number = 0 Then
oComm.PortOpen = False
Set oComm = Nothing
Exit Sub
End If

'Wait 500 Milliseconds
' Call Application.Wait(500)

strReceive = Convert_ByteArrayToString(oComm.InputData)
oComm.PortOpen = False
Set oComm = Nothing
'End first sample

End Sub

Public Function Convert_ByteArrayToString(ByVal vBytes As Variant) As String

Dim btByteData() As Byte
Dim i As Integer
Dim strReturn As String

btByteData = vBytes
For i = 0 To UBound(btByteData)
strReturn = strReturn & Chr(btByteData(i))
Next
Convert_ByteArrayToString = strReturn
End Function

Public Function Convert_StringToByteArray(ByVal strString As String) As Variant

Dim btByteData() As Byte
Dim i As Integer
Dim vReturn As Variant

If Not Len(strString) = 0 Then
ReDim btByteData(0 To Len(strString) - 1)
For i = 0 To UBound(btByteData)
btByteData(i) = Asc(Mid(strString, i + 1, 1))
Next
vReturn = btByteData
Else: vReturn = Empty
End If
Convert_StringToByteArray = vReturn
End Function
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10789773
ok, I took the code, and got it compiling

what you need to do is this

first create a class module (not a normal one) in your VBA editor and place the following code in there

(what I have done is indent it and put in error handlers, before it was using its own functionality which was not provided)

then when done, name is cMSComm and save
(look at next post for next code)

Option Explicit

Public Enum FlowControl
    None = 0
    XonXoff = 1
    CTSRTS = 2
    XonXoffCTSRTS = 3
End Enum

Public Enum Mode
    Text = 0
    Binary = 1
End Enum

Private mComm As Object
Private m_PortOpen As Boolean
Private m_Settings As String
Private m_CommPort As Integer
Private m_DTREnable As Boolean
Private m_Handshaking As FlowControl
Private m_InBufferSize As Integer
Private m_InputLen As Integer
Private m_InputMode As Mode
Private m_OutBufferSize As Integer
Private m_RTSEnable As Boolean
Private m_RThreshold As Integer
Private m_SThreshold As Integer

Private Sub Class_Initialize()
    m_Settings = "9600, N, 8, 1"
    m_CommPort = 1
    m_InBufferSize = 1024
    m_OutBufferSize = 1024
    m_RThreshold = 0
    m_SThreshold = 0
End Sub

Private Sub Class_Terminate()
    If m_PortOpen Then PortOpen = False
End Sub

Public Sub Output(varData As Variant)

On Error GoTo ErrHandler

    mComm.Output = varData
    Exit Sub

ErrHandler:
    MsgBox "MSCommLib: Output: Error " & Err.Number & vbCrLf & Err.Description
End Sub

Public Property Get InBufferCount() As Integer
    InBufferCount = mComm.InBufferCount
End Property

Public Property Get InputData() As Variant

    On Error GoTo ErrHandler
    InputData = mComm.Input
    Exit Property

ErrHandler:
    MsgBox "MSCommLib: GetInputData: Error " & Err.Number & vbCrLf & Err.Description
End Property

Public Property Get OutBufferCount() As Integer

    On Error GoTo ErrHandler
    OutBufferCount = mComm.OutBufferCount
    Exit Property

ErrHandler:
    MsgBox "MSCommLib: OutBufferCount: Error " & Err.Number & vbCrLf & Err.Description
End Property

Public Property Let PortOpen(ByVal NewValue As Boolean)

On Error GoTo ErrHandler
   
    If m_PortOpen = False And NewValue = True Then
        Set mComm = CreateObject("MSCOMMLIB.MSCOMM")
       
        With mComm
            .ParityReplace = vbNullString
            .Settings = m_Settings
            .CommPort = m_CommPort
            .DTREnable = m_DTREnable
            .Handshaking = m_Handshaking
            .InBufferSize = m_InBufferSize
            .InputLen = m_InputLen
            .InputMode = m_InputMode
            .OutBufferSize = m_OutBufferSize
            .RThreshold = m_RThreshold
            .SThreshold = m_SThreshold
            .RTSEnable = m_RTSEnable
            .PortOpen = True
        End With
       
        m_PortOpen = True
   
    ElseIf NewValue = False Then
       
        mComm.PortOpen = False
        Set mComm = Nothing
        m_PortOpen = False
    End If
    Exit Property

ErrHandler:
    MsgBox "MSCommLib: PortOpen-Let: Error " & Err.Number & vbCrLf & Err.Description
End Property

Public Property Get PortOpen() As Boolean

    On Error GoTo ErrHandler
    PortOpen = m_PortOpen
    Exit Property

ErrHandler:
    MsgBox "MSCommLib: PortOpen-Get: Error " & Err.Number & vbCrLf & Err.Description
End Property

Public Property Get CommPort() As Integer
    CommPort = m_CommPort
End Property

Public Property Let CommPort(ByVal NewValue As Integer)
    m_CommPort = NewValue
    If m_PortOpen = True Then mComm.CommPort = NewValue
End Property

Public Property Get DTREnable() As Boolean
    DTREnable = m_DTREnable
End Property

Public Property Let DTREnable(ByVal NewValue As Boolean)
    m_DTREnable = NewValue
    If m_PortOpen = True Then mComm.DTREnable = NewValue
End Property

Public Property Get Handshaking() As FlowControl
    Handshaking = m_Handshaking
End Property

Public Property Let Handshaking(ByVal NewValue As FlowControl)
    m_Handshaking = NewValue
    If m_PortOpen = True Then mComm.Handshaking = NewValue
End Property

Public Property Get InBufferSize() As Integer
    InBufferSize = m_InBufferSize
End Property

Public Property Let InBufferSize(ByVal NewValue As Integer)
    m_InBufferSize = NewValue
    If m_PortOpen = True Then mComm.InBufferSize = NewValue
End Property

Public Property Get InputLen() As Integer
    InputLen = m_InputLen
End Property

Public Property Let InputLen(ByVal NewValue As Integer)
    m_InputLen = NewValue
    If m_PortOpen = True Then mComm.InputLen = NewValue
End Property

Public Property Get InputMode() As Mode
    InputMode = m_InputMode
End Property

Public Property Let InputMode(ByVal NewValue As Mode)
    m_InputMode = NewValue
    If m_PortOpen = True Then mComm.InputMode = NewValue
End Property

Public Property Get OutBufferSize() As Integer
    OutBufferSize = m_OutBufferSize
End Property

Public Property Let OutBufferSize(ByVal NewValue As Integer)
    m_OutBufferSize = NewValue
    If m_PortOpen = True Then mComm.OutBufferSize = NewValue
End Property

Public Property Get RThreshold() As Integer
    RThreshold = m_RThreshold
End Property

Public Property Let RThreshold(ByVal NewValue As Integer)
    m_RThreshold = NewValue
    If m_PortOpen Then mComm.RThreshold = NewValue
End Property

Public Property Get SThreshold() As Integer
    SThreshold = m_SThreshold
End Property

Public Property Let SThreshold(ByVal NewValue As Integer)
    m_SThreshold = NewValue
    If m_PortOpen Then mComm.SThreshold = NewValue
End Property

Public Property Get RTSEnable() As Boolean
    RTSEnable = m_RTSEnable
End Property

Public Property Let RTSEnable(ByVal NewValue As Boolean)
    m_RTSEnable = NewValue
    If m_PortOpen = True Then mComm.RTSEnable = NewValue
End Property

Public Property Get CDHolding() As Boolean
    If m_PortOpen = True Then CDHolding = mComm.CDHolding
End Property

Public Property Get CTSHolding() As Boolean
    If m_PortOpen = True Then CTSHolding = mComm.CTSHolding
End Property

Public Property Get DSRHolding() As Boolean
    If m_PortOpen = True Then DSRHolding = mComm.DSRHolding
End Property

Public Property Get Settings() As String
    If m_PortOpen Then Settings = mComm.Settings
End Property

Public Property Let Settings(ByVal NewValue As String)
    m_Settings = NewValue
    If m_PortOpen Then mComm.Settings = NewValue
End Property

0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 10789784
Now how do you want to drive this, via a button on a form, if so create a form which a button
the code snippet you see was incomplete, had to fix that

place this code in a form


Option Compare Database
Option Explicit

Private Sub Command1_Click()

    Dim oComm As cMSComm
    Set oComm = New cMSComm


'XXX - my changes - define this lot
    Dim iPort As Integer
    Dim strBaud As String
    Dim strParity As String
    Dim strDatabit As String
    Dim strStopbit As String
    Dim strTransmit As String
    Dim strReceive As String


'XXX - my changes - give it some values
    iPort = 1
    strBaud = "9600"
    strParity = "N"
    strDatabit = "8"
    strStopbit = "1"
   
    With oComm
        .CommPort = iPort
        .Settings = strBaud & "," & strParity & "," & strDatabit & "," & strStopbit
        .OutBufferSize = 1024
        .InBufferSize = 1024
        .RThreshold = 1
        .SThreshold = 1
        .DTREnable = True
        .InputMode = 1 'Note: Binary transmission is generally the most reliable
    End With

    On Error Resume Next
    oComm.PortOpen = True

    If Not Err.Number = 0 Then
        Set oComm = Nothing
        Exit Sub
    End If

strTransmit = "TEST Message"
MsgBox "Sending " & strTransmit
   
    'Note: transmission of data as a byte array for this device
    Call oComm.Output(Convert_StringToByteArray(strTransmit))
    If Not Err.Number = 0 Then
        oComm.PortOpen = False
        Set oComm = Nothing
        Exit Sub
    End If

    'Wait 500 Milliseconds
    ' Call Application.Wait(500)

    strReceive = Convert_ByteArrayToString(oComm.InputData)
   
MsgBox "Received " & strReceive
    oComm.PortOpen = False
    Set oComm = Nothing


End Sub


Public Function Convert_ByteArrayToString(ByVal vBytes As Variant) As String

    Dim btByteData() As Byte
    Dim i As Integer
    Dim strReturn As String
   
    btByteData = vBytes
    For i = 0 To UBound(btByteData)
        strReturn = strReturn & Chr(btByteData(i))
    Next
    Convert_ByteArrayToString = strReturn
End Function

Public Function Convert_StringToByteArray(ByVal strString As String) As Variant

    Dim btByteData() As Byte
    Dim i As Integer
    Dim vReturn As Variant
   
    If Not Len(strString) = 0 Then
        ReDim btByteData(0 To Len(strString) - 1)
        For i = 0 To UBound(btByteData)
            btByteData(i) = Asc(Mid(strString, i + 1, 1))
        Next
        vReturn = btByteData
    Else: vReturn = Empty
    End If
    Convert_StringToByteArray = vReturn
End Function


OKAY ----------------------

Now we need to create a reference, go to Tools/References and find Microsoft Comm Control 6.0
If not on list then you need to browse for it -search for something like MSCOMM32.OCX
it should be in your windows\system32 directory
once you include this reference, you should be able to compile it - select debug/compile


What I have given you is some code to get you going, to be honest I dont know much about comms so you will have to figure that one out

I hope this is okay for ya

0
 

Author Comment

by:Dalexan
ID: 10819688
Still working on this, Trying to get the com port to initialize with my port settings. Tricky because it is so trial and error, there is no way to see what I am sending to the comm port.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10820404
if you have an alternative way (some other software) that uses your intialisation settings, u could try that then you know whether its settings, port or code
0
 

Author Comment

by:Dalexan
ID: 10832513
Yes I have been using Hyperterminal with all the port settings to test connectivity (This works) but I dont know if the ascii settings are correct to send the text to the sign the same as in the Hyperterminal settings.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10876345
Ive been having a look at this but having no luck, did u manage to get anywhere with this
0
 

Author Comment

by:Dalexan
ID: 10879937
I am still trying several settings changes, I cannot tell if I am sending anything. I can get the sign to work using hyperterminal.
0
 

Expert Comment

by:Nwulf
ID: 10981789
I believe the mscomm32.ocx only works if you have some sort of  licence to use it.  I found a free copy of a ocx that you can use to access the comm port and it works great.

http://ourworld.compuserve.com/homepages/richard_grier/NETCommOCX.htm

There are some help files and source code you can copy and get it to work.

I am not sure if this helps you....

Nick
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now