hexagon logo

Anyone have any expereince getting data from COM ports?

Hi Guys

Was just wondering if anyone out there has got any experience with getting data from COM ports using VBA and excel. more specifically data from DTI's plugged into a multiplexer.

I have been tasked with implementing an SPC system at our company and me and a colleague had an idea of just creating it all in excel as it would be a bespoke system for our needs and it wouldn't cost any money except our time. Naturally it has proven a lot harder than we first anticipated.

I can get the data into excel easily using an activeX plug in and some code I found on the internet. This will read in all the instruments connected to the multiplexer in one go straight into excel. Our problem is that we don't want the data from all the instruments at once, just some of them and we can only use one excel sheet per project as the activex plug in turns the whole sheet into a data collection for just that one com port.

The idea is that we can have a button on each page per project which we can press and it will poll the multiplexer and then receive the wanted data. I found some code on the net again that looked promising but the problems I am encountering are just too far beyond my skills.

So far I have this

Dim intPortID As Integer ' Ex. 1, 2, 3, 4 for COM1 - COM4
    intPortID = 5
    Dim lngStatus As Long
    Dim strError  As String
    Dim strData   As String
    Call CommClose(intPortID)

     'Initialize Communications
    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


which gives me the COM error code in the code above and an access denied error for the COM port.

I know, not much to go on but I am hoping that someone out there has some experience with this.
Parents Reply Children