Link to home
Start Free TrialLog in
Avatar of Dalexan
DalexanFlag for Afghanistan

asked on

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

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,
Avatar of Dalexan
Dalexan
Flag of Afghanistan image

ASKER

is this Difficult, should I increase points?
Avatar of Dalexan

ASKER

Can someone atleast give me an example of how to use mscommlib in access vba to connect to com2?
Avatar of rockiroads
some sample code here that uses mscommlib, would this help

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


basically its creating a MSCOMMLIB object

Avatar of Dalexan

ASKER

Thats a great link, trying it out now...
Avatar of Dalexan

ASKER

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
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

ASKER CERTIFIED SOLUTION
Avatar of rockiroads
rockiroads
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dalexan

ASKER

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.
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
Avatar of Dalexan

ASKER

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.
Ive been having a look at this but having no luck, did u manage to get anywhere with this
Avatar of Dalexan

ASKER

I am still trying several settings changes, I cannot tell if I am sending anything. I can get the sign to work using hyperterminal.
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