Serial communication in VB 2005

Posted on 2006-06-03
Last Modified: 2008-02-20
Ok I'm stumped. I'm trying to communicate with a digital multimeter that has software originally designed to work in windows 3.1. The software works but its old and crappy and I want to make something a little more up to date and flashy but I cant get the communication to work. All I have to go off of is an the old manual that came with the meter. I've tried several different things but none of them work, obviously I'm missing something. This is what the manual says:

3.1 Communicate with the Multimeter
To request data from the multimeter, send a character to the DMM/Data Logger through the PC's RS-232 port. Any character can be sent except the reserved characters (9,4,2,1,EEE,G,N,R,W,U,S,T,X,EEE). It is recommended that user send a SPACE character to the multimeter (The ASCII code of SPACE key is 20 in hex). As having received a character (except the reserved characters) from PC, the meter will sent out 5 bytes to PC.

Also, later in the manual it says:

It is strongly recommended that when the user opens the COM port, it is opened by the following command:
OPEN "COM1;9600,N,8,1,CS,DS,CD,RS" AS #1

So what I need is some code that sends that magic byte to the meter and then recieves the magical 5 bytes back. If I can get that much I can handle the rest, I already have a decoder for the bytes written, (if I could only get the damned thing to send me the bytes now...) This has to be for VB 2005, VB6 code wont work for me. I'm looking to use the SerialPort class that is buitl into VB2005.

Thanks in advance,

Question by:otsego85
    LVL 96

    Expert Comment

    by:Bob Learned
    What do you have so far?  Where is it not working?  What problems are you having?

    LVL 12

    Accepted Solution

    I  would start communicating "manually" with hyper terminal, send the space, then get the 5 bytes back, to be sure everything connects properly, then go with the serialport in VB.

    Author Comment

    I cant get hyperterminal to work, however the original software still works so I know the DMM is working properly.

    I dont really have any code to show because nothing I haved tried works. However here is what I do have that doesn't work anyway.

    Public Class Form1

        Private Sub Connect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
                '// Initializes port
            Catch Ex As Exception
                MessageBox.Show(Ex.Message, "Connection Error", MessageBoxButtons.OK)

            End Try
        End Sub

        Private Sub Send_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
                SerialPort1.Write(" ")
            Catch ex As Exception
                MessageBox.Show(ex.Message, "Connection Error", MessageBoxButtons.OK)
            End Try
        End Sub

        Private Sub Receive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            Dim Result(255) As Byte
                SerialPort1.Read(Result, 0, 1)
            Catch ex As Exception
                MessageBox.Show(ex.Message, "Connection Error", MessageBoxButtons.OK)
            End Try
        End Sub
    End Class

    Author Comment

    Here is port monitor log with the working software:

    0      0.00005839      NTVDM.EXE      IRP_MJ_CREATE      Serial0      SUCCESS      Options: Open       
    1      0.00000335      NTVDM.EXE      IOCTL_SERIAL_GET_BAUD_RATE      Serial0      SUCCESS            
    2      0.00000168      NTVDM.EXE      IOCTL_SERIAL_GET_LINE_CONTROL      Serial0      SUCCESS            
    3      0.00000168      NTVDM.EXE      IOCTL_SERIAL_GET_CHARS      Serial0      SUCCESS            
    4      0.00000168      NTVDM.EXE      IOCTL_SERIAL_GET_HANDFLOW      Serial0      SUCCESS            
    5      0.00000196      NTVDM.EXE      IOCTL_SERIAL_GET_BAUD_RATE      Serial0      SUCCESS            
    6      0.00000168      NTVDM.EXE      IOCTL_SERIAL_GET_LINE_CONTROL      Serial0      SUCCESS            
    7      0.00000168      NTVDM.EXE      IOCTL_SERIAL_GET_CHARS      Serial0      SUCCESS            
    8      0.00000168      NTVDM.EXE      IOCTL_SERIAL_GET_HANDFLOW      Serial0      SUCCESS            
    9      0.00000810      NTVDM.EXE      IOCTL_SERIAL_SET_BAUD_RATE      Serial0      SUCCESS      Rate: 9600      
    10      0.00000447      NTVDM.EXE      IOCTL_SERIAL_CLR_RTS      Serial0      SUCCESS            
    11      0.00000419      NTVDM.EXE      IOCTL_SERIAL_CLR_DTR      Serial0      SUCCESS            
    12      0.00000279      NTVDM.EXE      IOCTL_SERIAL_SET_LINE_CONTROL      Serial0      SUCCESS      StopBits: 1 Parity: NONE WordLength: 8      
    13      0.00000196      NTVDM.EXE      IOCTL_SERIAL_SET_CHAR      Serial0      SUCCESS      EOF:1a ERR:0 BRK:0 EVT:1a XON:11 XOFF:13      
    14      0.00000838      NTVDM.EXE      IOCTL_SERIAL_SET_HANDFLOW      Serial0      SUCCESS      Shake:0 Replace:0 XonLimit:2048 XoffLimit:512      
    15      0.00000223      NTVDM.EXE      IOCTL_SERIAL_LSRMST_INSERT      Serial0      SUCCESS      Char: ffffffff      
    16      0.00000419      NTVDM.EXE      IOCTL_SERIAL_SET_QUEUE_SIZE      Serial0      SUCCESS      InSize: 8192 OutSize: 100      
    17      0.00000168      NTVDM.EXE      IOCTL_SERIAL_GET_TIMEOUTS      Serial0      SUCCESS            
    18      0.00000196      NTVDM.EXE      IOCTL_SERIAL_SET_TIMEOUTS      Serial0      SUCCESS      RI:-1 RM:0 RC:0 WM:0 WC:500      
    19      0.00000419      NTVDM.EXE      IOCTL_SERIAL_SET_DTR      Serial0      SUCCESS            
    20      0.00000447      NTVDM.EXE      IOCTL_SERIAL_CLR_RTS      Serial0      SUCCESS            
    21      0.00000447      NTVDM.EXE      IOCTL_SERIAL_SET_DTR      Serial0      SUCCESS            
    22      0.00000168      NTVDM.EXE      IOCTL_SERIAL_GET_LINE_CONTROL      Serial0      SUCCESS            
    23      0.00000307      NTVDM.EXE      IOCTL_SERIAL_SET_LINE_CONTROL      Serial0      SUCCESS      StopBits: 1 Parity: NONE WordLength: 5      
    24      0.00000168      NTVDM.EXE      IOCTL_SERIAL_GET_LINE_CONTROL      Serial0      SUCCESS            
    25      0.00000279      NTVDM.EXE      IOCTL_SERIAL_SET_LINE_CONTROL      Serial0      SUCCESS      StopBits: 1 Parity: NONE WordLength: 8      
    26      0.00000810      NTVDM.EXE      IOCTL_SERIAL_SET_BAUD_RATE      Serial0      SUCCESS      Rate: 9600      
    27      0.00000531      NTVDM.EXE      IOCTL_SERIAL_SET_WAIT_MASK      Serial0      SUCCESS      Mask: RXCHAR CTS DSR RLSD ERR RING       
    28      49.37250768      NTVDM.EXE      IOCTL_SERIAL_WAIT_ON_MASK      Serial0      SUCCESS            
    29      0.00000754      NTVDM.EXE      IOCTL_SERIAL_GET_MODEMSTATUS      Serial0      SUCCESS            
    30      0.00002514      NTVDM.EXE      IRP_MJ_WRITE      Serial0      SUCCESS      Length 1: 20       
    31      0.00000559      NTVDM.EXE      IRP_MJ_READ      Serial0      SUCCESS      Length 10: FF 03 22 FF 00 02 18 01 A0 03       
    32      0.00000307      NTVDM.EXE      IRP_MJ_READ      Serial0      SUCCESS      Length 0:       
    33      0.00000587      NTVDM.EXE      IOCTL_SERIAL_WAIT_ON_MASK      Serial0      SUCCESS            
    34      0.00000279      NTVDM.EXE      IRP_MJ_READ      Serial0      SUCCESS      Length 0:       
    35      19.12805175      NTVDM.EXE      IOCTL_SERIAL_WAIT_ON_MASK      Serial0      SUCCESS            
    36      0.00002486      NTVDM.EXE      IRP_MJ_WRITE      Serial0      SUCCESS      Length 1: 20       
    37      0.00000559      NTVDM.EXE      IRP_MJ_READ      Serial0      SUCCESS      Length 5: 02 18 01 A0 03       
    38      0.00000307      NTVDM.EXE      IRP_MJ_READ      Serial0      SUCCESS      Length 0:       
    39      0.00000559      NTVDM.EXE      IOCTL_SERIAL_WAIT_ON_MASK      Serial0      SUCCESS            
    40      0.00000279      NTVDM.EXE      IRP_MJ_READ      Serial0      SUCCESS      Length 0:       
    41      16.02725710      NTVDM.EXE      IOCTL_SERIAL_WAIT_ON_MASK      Serial0      SUCCESS            
    42      0.00002570      NTVDM.EXE      IRP_MJ_WRITE      Serial0      SUCCESS      Length 1: 20       
    43      0.00000559      NTVDM.EXE      IRP_MJ_READ      Serial0      SUCCESS      Length 5: 02 18 01 A0 03       
    44      0.00000279      NTVDM.EXE      IRP_MJ_READ      Serial0      SUCCESS      Length 0:       
    45      0.00000559      NTVDM.EXE      IOCTL_SERIAL_WAIT_ON_MASK      Serial0      SUCCESS            
    46      0.00000307      NTVDM.EXE      IRP_MJ_READ      Serial0      SUCCESS      Length 0:       
    47      0.00000000      NTVDM.EXE      IOCTL_SERIAL_WAIT_ON_MASK      Serial0      

    Here is port monitor with my unworking software:
    0      0.00005978      WindowsApplicat      IRP_MJ_CREATE      Serial0      SUCCESS      Options: Open       
    1      0.00000391      WindowsApplicat      IOCTL_SERIAL_GET_PROPERTIES      Serial0      SUCCESS            
    2      0.00000307      WindowsApplicat      IOCTL_SERIAL_GET_MODEMSTATUS      Serial0      SUCCESS            
    3      0.00000168      WindowsApplicat      IOCTL_SERIAL_GET_BAUD_RATE      Serial0      SUCCESS            
    4      0.00000196      WindowsApplicat      IOCTL_SERIAL_GET_LINE_CONTROL      Serial0      SUCCESS            
    5      0.00000168      WindowsApplicat      IOCTL_SERIAL_GET_CHARS      Serial0      SUCCESS            
    6      0.00000168      WindowsApplicat      IOCTL_SERIAL_GET_HANDFLOW      Serial0      SUCCESS            
    7      0.00000168      WindowsApplicat      IOCTL_SERIAL_GET_BAUD_RATE      Serial0      SUCCESS            
    8      0.00000196      WindowsApplicat      IOCTL_SERIAL_GET_LINE_CONTROL      Serial0      SUCCESS            
    9      0.00000168      WindowsApplicat      IOCTL_SERIAL_GET_CHARS      Serial0      SUCCESS            
    10      0.00000168      WindowsApplicat      IOCTL_SERIAL_GET_HANDFLOW      Serial0      SUCCESS            
    11      0.00000782      WindowsApplicat      IOCTL_SERIAL_SET_BAUD_RATE      Serial0      SUCCESS      Rate: 9600      
    12      0.00000447      WindowsApplicat      IOCTL_SERIAL_SET_RTS      Serial0      SUCCESS            
    13      0.00000447      WindowsApplicat      IOCTL_SERIAL_CLR_DTR      Serial0      SUCCESS            
    14      0.00000307      WindowsApplicat      IOCTL_SERIAL_SET_LINE_CONTROL      Serial0      SUCCESS      StopBits: 1 Parity: NONE WordLength: 8      
    15      0.00030842      WindowsApplicat      IOCTL_SERIAL_SET_CHAR      Serial0      SUCCESS      EOF:1a ERR:0 BRK:0 EVT:1a XON:11 XOFF:13      
    16      0.00000587      WindowsApplicat      IOCTL_SERIAL_SET_HANDFLOW      Serial0      SUCCESS      Shake:0 Replace:40 XonLimit:1024 XoffLimit:1024      
    17      0.00000168      WindowsApplicat      IOCTL_SERIAL_GET_BAUD_RATE      Serial0      SUCCESS            
    18      0.00000196      WindowsApplicat      IOCTL_SERIAL_GET_LINE_CONTROL      Serial0      SUCCESS            
    19      0.00000140      WindowsApplicat      IOCTL_SERIAL_GET_CHARS      Serial0      SUCCESS            
    20      0.00000168      WindowsApplicat      IOCTL_SERIAL_GET_HANDFLOW      Serial0      SUCCESS            
    21      0.00000810      WindowsApplicat      IOCTL_SERIAL_SET_BAUD_RATE      Serial0      SUCCESS      Rate: 9600      
    22      0.00000447      WindowsApplicat      IOCTL_SERIAL_SET_RTS      Serial0      SUCCESS            
    23      0.00000419      WindowsApplicat      IOCTL_SERIAL_SET_DTR      Serial0      SUCCESS            
    24      0.00001006      WindowsApplicat      IOCTL_SERIAL_SET_LINE_CONTROL      Serial0      SUCCESS      StopBits: 1 Parity: NONE WordLength: 8      
    25      0.00000196      WindowsApplicat      IOCTL_SERIAL_SET_CHAR      Serial0      SUCCESS      EOF:1a ERR:0 BRK:0 EVT:1a XON:11 XOFF:13      
    26      0.00000531      WindowsApplicat      IOCTL_SERIAL_SET_HANDFLOW      Serial0      SUCCESS      Shake:1 Replace:40 XonLimit:1024 XoffLimit:1024      
    27      0.00000475      WindowsApplicat      IOCTL_SERIAL_SET_DTR      Serial0      SUCCESS            
    28      0.00000168      WindowsApplicat      IOCTL_SERIAL_SET_TIMEOUTS      Serial0      SUCCESS      RI:-1 RM:-1 RC:8000 WM:0 WC:8000      
    29      0.00000391      WindowsApplicat      IOCTL_SERIAL_SET_WAIT_MASK      Serial0      SUCCESS      Mask: RXCHAR RXFLAG CTS DSR RLSD BRK ERR RING       
    30      0.00000503      WindowsApplicat      IOCTL_SERIAL_SET_QUEUE_SIZE      Serial0      SUCCESS      InSize: 256 OutSize: 256      
    31      0.00005950      WindowsApplicat      IOCTL_SERIAL_WAIT_ON_MASK      Serial0      SUCCESS            
    32      0.00000000      WindowsApplicat      IOCTL_SERIAL_WAIT_ON_MASK      Serial0                  
    33      0.00002850      WindowsApplicat      IRP_MJ_WRITE      Serial0      SUCCESS      Length 1: 20       
    34      0.00001117      WindowsApplicat      IRP_MJ_READ      Serial0      SUCCESS      Length 1: 00       
    35      0.00002375      WindowsApplicat      IRP_MJ_WRITE      Serial0      SUCCESS      Length 1: 20       
    36      7.99880739      WindowsApplicat      IRP_MJ_READ      Serial0      TIMEOUT      Length 0:

    Author Comment

    Well folks, looks like I worked this one out myself. I am now getting the 5 bytes back. RtsEnable needed to be false not true... Doh.

    Anyway I may still need some help reading the bytes into my decoder, I'll give it a whirl and see if I can get that to work.
    LVL 12

    Expert Comment

    So the problem now is getting the 5 Result()-bytes into the decoder? Or?

    Author Comment

    Sorry vb I've solved my immediate issues, but since your question provoked my brain towards a soloution. Points are yours.
    LVL 12

    Expert Comment

    Nice that you got your app going. Humble thanks for the points!

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    746 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

    15 Experts available now in Live!

    Get 1:1 Help Now