Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

What replaces MSCOMM PortOpen in Measurement Studio?

I'm trying to ID comm ports in a system by attempting to open each within a range.  This is my VB code, but what is equivalent if I'm using the CWSerial object?
 
For I = 1 To 20         ' Try each in turn
      MSComm1.CommPort = I
      MSComm1.PortOpen    ' See if it will open
      If MSComm1.PortOpen = True Then  ' If so, ...
         MSComm1.PortOpen = False      ' Close for now
         cmbPort.AddItem I    ' Add to list
         DoEvents
      End If
Next I
0 Kudos
Message 1 of 11
(10,745 Views)
You might want to check this post.
Pat P.
Software Engineer
National Instruments
0 Kudos
Message 2 of 11
(10,708 Views)

Yes, I've looked at this ( and before ), but this doesn't tell me everthing.  I get data, but in multiples of groups instead of a group at a time.  So far, it works no differently or better than MSCOMM.

Have anything else?

0 Kudos
Message 3 of 11
(10,705 Views)
What exactly do you mean by groups of data?  Do you have data that is grouped by special termination characters?  There aren't really any more CWserial examples that are in Visual Basic.  That example covers most of the functionality of the CWserial control.  There are some other properties that can be set, but those three events that are used are all of the events available.  If you want a listing of all the properties and what they do I would check out the Measurement Studio reference help and search for CWserial.   It lists all of these.

Message Edited by Patrick P. on 02-23-2006 10:20 AM

Pat P.
Software Engineer
National Instruments
0 Kudos
Message 4 of 11
(10,692 Views)

What I mean is if I'm receiving 3 bytes ( a group ), I get 6 or 9 bytes together rather than 3 bytes.  Even if I set the threshold to 3, I get more than 3.  Why?  The data is sent at regular, predictable intervals.

No termination character.

This still doesn't answer basic questions, such as how to open a port, close a port, determine if the port is open or closed.  I get that "Configure" probably opens it, but what closes it?  What, in detail, does "Reset" do?  How do I ping a port to see if it exists?  These details are what are characteristically missing from NI documentation. 

>...check out the Measurement Studio reference help ...

Ok, where is it?  I don't have a manual.

>It lists all of these.

Ok, but I'll bet it lists them and doesn't explain them.

0 Kudos
Message 5 of 11
(10,680 Views)

The help should be installed by default if you installed Measurement Studio.  The easiest way to get to it is to go through your start menu.  The help is located at Start>>Programs>>National Instruments>>Measurement Studio>>Help>>Measurement Studio Reference.  Then from there I just did a search on CWserial.  It lists and explains several of the things I believe you are looking for.  If you still can’t find it, I can post the help files here for you.

I was curious how you were setting the threshold to read?  Were calling a Read or ReadAsync with a value of three?

Pat P.
Software Engineer
National Instruments
0 Kudos
Message 6 of 11
(10,674 Views)
>It lists and explains several of the things I believe you are looking for.

Yes, this is better.  However, it still doesn't explain how to use them together.  For example, if I select cwserial1.read, how is this invoked?  In what circumstances would I use it over ReadAsync?

Honestly, I've tried the example programs. They are a bit flaky and sometimes flat don't work.  In this case, the example is not really different than the typical MSCOMM type of approach. What am I missing?

>I was curious how you were setting the threshold to read? 

I was using a slider to modify the value from 1 to 10 for test purposes.

>Were calling a Read or ReadAsync with a value of three?

Read on a timer.  From examples I've seen using MSCOMM, you hammer it with calls until you get something.  Then process it.  Or, wait for OnComm event to fire then collect it.  But, I always have to collect it in pieces, not the entire string.  This is the core of the problem I'm having.

I also presume the async read is similar to the MSOnComm event?  If so, why use the NI version if it isn't different ( or better )?
 
Is there a published philosophy on how to use this stuff somewhere on the web?  Explanations of how each works is not bringing them together on how to use them effectively together.
 
Also, I still don't have any suggestions on how to detect whether a COMM Port exists or not.
 
 
0 Kudos
Message 7 of 11
(10,671 Views)

I have this connected to a button and the DataReady procedure.   It does nothing until I click the button.

CWSerial1.ReadAsync 3  ' I want 3 bytes at a time...

Private Sub CWSerial1_DataReady(ByVal taskNumber As Integer, data As Variant)
   lstData.AddItem data, 0
End Sub

The only time I get anything is when I press a button.  Why won't the DataReady fire on its own? 
 
Also, how do I Ping a serial port to find out if it exists?   There must be an API or some other facility within Windows that has these enumerated.
0 Kudos
Message 8 of 11
(10,657 Views)

When you use ReadAsync, it is setting up just a single read.  If you want it to continuously keep reading 3 bytes, you would just add a ReadAsync 3 inside of your dataready event handler.  This way it would always set another 3 bytes to read.

I don’t know of a single function call you can make to view all of the available serial ports.  If you want to get all of them with the CWSerial control, you could create a global Boolean that tells you whether an error occurred or not within configuration.  It would be similar to the code you had listed above for the mscomm interface.  You would need to create a global variable called ConfigError.

    CWSerial1.ExceptionOnError = False
    ConfigError = False

For I = 1 To 20         ' Try each in turn
    CWSerial1.ComPort = I
    CWSerial1.Configure
    If ConfigError = False Then
        MsgBox "add port to list"
    End If
    ConfigError = False
Next I

Private Sub CWSerial1_OnError(ByVal errorCode As Long, ByVal ErrMsg As String)
‘30312 is for a serial port that doesn’t exist
‘30315 is for a serial port that is already in use

    If errorCode = -30312 Or errorCode = -30315 Then
        ConfigError = True
    Else
        MsgBox ErrMsg
    End If
End Sub

Pat P.
Software Engineer
National Instruments
0 Kudos
Message 9 of 11
(10,636 Views)

BINGO!!  It is the same approach, but at least I have an answer and some useful details.

For the benefit of others, here is some more info I received from another source:

To find out which ports are enumerated use the SetupDiGetDeviceRegistryProperty from the setupapi.h library. The ‘SPDRP_FRIENDLYNAME’ field contains the device descriptor and allocated COM port.

Useful links:

SetupDiGetDeviceRegistryProperty:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/setupdigetdeviceregistry...

Example code:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/displaying_the_installed...

See next post for code.
0 Kudos
Message 10 of 11
(10,629 Views)