Comm Ports without mscomm32

nae0254

Registered User.
Local time
Today, 03:34
Joined
Sep 6, 2014
Messages
10
[SOLVED]Comm Ports without mscomm32

I love Access, but I hate mscomm32.ocx.
With modules we can write our own code, even declare ocx and dlls
I have a class (google searching) which can handle this ports but I don't understand how to implement it.
Anyone interested in help me a little bit?
I will send the class if you wish.
Guillermo
 
Last edited:
I can't help that much especially since I don't know what you are doing but I was able to use this: http://www.thescarms.com/vbasic/CommIO.aspx

I recently built some functionality that reads a com port into an access application using those functions.

I hope it helps.

SHADOW
 
Thank you, Shadow, very much for your answer.
I have read the article but I have a doubt.
There is an event in mscomm32: "OnComm" where it remains waiting to receive a character.
I read the data character by character and when it reaches a vbCrLf I use the string to fill a textbox.
This is the software of a scale.
But I don´t know how to do this with the class: make it waiting for a data.
Any help will be welcome, and excuse me for my awful English.
Guillermo.
 
It's hard to advise without knowing more about the device or how it's supposed to read the port, but here's the code that I use for that purpose. I put my data into a variable called DataRecord:

Code:
   DataRecord = ""
   ' Wait for data to come back to the serial port.
   Do
    DoEvents
   ' Read data.
        
     lngStatus = CommRead(intPortID, Instring, 1)
    If lngStatus > 0 Then
        ' Process data.
        DataRecord = DataRecord & Instring
    ElseIf lngStatus < 0 Then
        ' Handle error.
    End If

Loop Until InStr(Instring, vbCr)

This works for me and hopefully it will guide you.

SHADOW
 
Last edited:
Shadow:
Your code looks great, but I couldn’t make it works.
Let me tell you what I’m doing.
I developed (years ago) Software that take the weight of trucks recieving data via serial ports. Visual Basic – Mscomm32 - Win 7.
Now my client ask me for a new software but not using exe files, o third party components (company policies).
They use Office as a standard software, so I thought Access was a good choice.
For my tests I’m using 2 computers connected via rs232 and Hyperterminal to send data and trying to recieve this data with another Hyperterminal (the real scale is huge).
The data send is a string ended with a VBcrlf.
I started a new form in the CommIO project with a button and a text box.
I’ll send my code in another post.
 
Private Sub Command2_Click()
Dim intPortID As Integer ' Ex. 1, 2, 3, 4 for COM1 - COM4
Dim lngStatus As Long
Dim strError As String
Dim sngStart As Single
Dim intPollComResult As Integer '0 Timed Out, 1 Success, 2 Error
Dim Instring As String
intPortID = 3

DataRecord = ""

lngStatus = CommOpen(intPortID, "COM" & CStr(intPortID), "baud=9600 parity=N data=8 stop=1")
MsgBox lngStatus
Do
DoEvents
lngStatus = CommRead(intPortID, Instring, 1)

If lngStatus > 0 Then
' Process data.
DataRecord = DataRecord & Instring
ElseIf lngStatus < 0 Then
' Handle error.
End If
Loop Until InStr(Instring, Chr$(13)) ' I also tryed other characters as "terminators" instead of Chr$(13) but didn't work
Text1.Text = DataRecord

End Sub

Please, what am I doing wrong?
Guillermo.

:banghead:
 
It's really hard to know without knowing what "end file" terminator they are using. Maybe it's in the documentation somewhere?

SHADOW
 
Doesn't matter, the scale sends a carriage return (chr&(13)) but I'm trying with another characters.
For example, I send with my other computer (the scale emulator) this string "123454b"
And I change the code like this: Loop Until InStr(Instring, "b")
But I can´t read 123454 with the code I show you
What am I doing wrong in the whole code?
Thanks in advance.
Guillermo
 
I used a similar method to access the COM once ...

www .ontrak.net/basic.htm
 
I used a similar method to access the COM once ...

www .ontrak.net/basic.htm
¿Pablo Neruda? You probably speak Spanish... Don´t you?
That is a DOS program and it will not run on w7.
But I am very grateful for your advice.
Thank you very much.
 
This may have some use to you. I found it via Google after reading your post.
 
[SOLVED] Comm Ports without mscomm32

Hello everyone!
With the mix of all your advice I managed to run my program in MsAccess.
I added a global constant in module:
Code:
Global Parar As Boolean
In a new form, I drew two buttons, "Start" and "Stop" and a text box (Text1)
In the Start button I wrote this code:

Code:
    Dim intPortID As Integer ' Ex. 1, 2, 3, 4 for COM1 - COM4
    Dim lngStatus As Long
    Dim strError  As String
    Dim strData   As String
    Dim sngStart As Single
    Dim intPollComResult As Integer '0 Timed Out, 1 Success, 2 Error
    Dim Instring As String
    intPortID = 3
Parar = False


On Error GoTo PROC_ERR
lngStatus = CommOpen(intPortID, "COM" & CStr(intPortID), "baud=9600 parity=N data=8 stop=1")
    If lngStatus <> 0 Then
        ' Handle error.
        lngStatus = CommGetError(strError)
        MsgBox "COM Error: " & strError
    End If
DataRecord = ""
   ' Wait for data to come back to the serial port.
Do While Parar = False
Do
    DoEvents
    lngStatus = CommRead(intPortID, Instring, 1)
    If lngStatus > 0 Then
        DataRecord = DataRecord & Instring
    ElseIf lngStatus < 0 Then
        ' Handle error.
    End If
Loop Until InStr(Instring, Chr$(13))
Text1.SetFocus
Text1.Text = Replace(DataRecord, Chr$(10), "")
DataRecord = ""
Loop
    
PROC_EXIT:
    
     ' Reset modem control lines.
    lngStatus = CommSetLine(intPortID, LINE_RTS, False)
    lngStatus = CommSetLine(intPortID, LINE_DTR, False)

    ' Close communications.
    Call CommClose(intPortID)
    
    Exit Sub
    

PROC_ERR:
    MsgBox Err.Number & Err.Description
    Resume PROC_EXIT
    Resume
In the Stop button, I wrote this code:

Code:
Parar = True
It works fine.
Thank you all for your assistance!
Guillermo
 
I'm glad you have it working also.
If you have a database or function, you might consider posting in the code repository or sample databases area.
I'm sure others will find it difficult to find good examples, as you did.
 
Jdraw:
I would be honored to publish the source code and the Access sample, but do not know how.
Could you help, please?
Thanks in advance.
Guillermo Sieder.
 

Users who are viewing this thread

Back
Top Bottom