Application on other PC's
Application on other PC's
Application on other PC's
Application on other PC's
Application on other PC's
Application on other PC's Application on other PC's Application on other PC's Application on other PC's Application on other PC's Application on other PC's Application on other PC's Application on other PC's
Application on other PC's Application on other PC's
Application on other PC's
Go Back  Xtreme Visual Basic Talk > > > Application on other PC's


Reply
 
Thread Tools Display Modes
  #1  
Old 08-26-2008, 11:29 AM
mrphysics mrphysics is offline
Newcomer
 
Join Date: Aug 2004
Posts: 12
Default Application on other PC's


All,

Here is my problem. I have a VB.NET 2005 application that I have created that uses 2 serial ports to communicate with external devices. The app reads from these and then fills out a spreadsheet that it opens. The app works just fine on my PC, either running it from the IDE or running the ".exe" file. So, here is the problem. I created a Package and Deploy project and packaged mine up to install, no problems so far. Installed it on another PC, that had .NET 2.0 BTW, still no problems. Now here is the problem. When it runs, it opens Excel like it should (I can see that Excel is running), it tries to communicate with one of the serial ports (I am using a USB to 4-port adapter and it has status lights), and it then just closes. I am really at a loss? I also have a version of this app in VB6, and it works just fine on the same computer. I converted it to VB.Net. So, where should I be looking? Anyone have any ideas?

Your help is much appreciated,
Thanks,
Mr. Physics
Reply With Quote
  #2  
Old 08-26-2008, 11:49 AM
gpraceman's Avatar
gpracemanApplication on other PC's gpraceman is offline
Contributor

* Expert *
 
Join Date: Sep 2002
Location: Highlands Ranch, CO
Posts: 560
Default

You mean the app is crashing?

Have you tried stepping through line by line in the debugger to see where it is tripping up?
__________________
Awana Grand Prix and Pinewood Derby racing - Where a child, an adult and a small block of wood combine for a lot of fun and memories.
Reply With Quote
  #3  
Old 08-26-2008, 12:35 PM
mrphysics mrphysics is offline
Newcomer
 
Join Date: Aug 2004
Posts: 12
Default

I don't think the app is crashing "per se", in other words, I am not getting an error message. Here is some futher information. On my box, I have a 2 port serial port PCI card installed. On the other box, I use a USB to 4-Port Serial port adapter. Now, this USB adapter has worked just fine with VB6. And I have used this same USB adapter with my box, again with VB6. Now, I had never tried this with .NET, so I tried this. I get this same problem now with my box. App starts Excel, tries to access a serial port, then the app closes. I have tried 2 different converters, one StarTech and one Keyspan, and got the same results. So, I am not sure to make of this. With the Keyspan, I know that I have the latest drivers, I am going to check for the latest drivers with the StarTech. It appears to be something weird with either the drivers or .NET with USB to Serial Port adapters.

Any ideas?
Thanks,
Mr. Physics
Reply With Quote
  #4  
Old 08-26-2008, 12:44 PM
gpraceman's Avatar
gpracemanApplication on other PC's gpraceman is offline
Contributor

* Expert *
 
Join Date: Sep 2002
Location: Highlands Ranch, CO
Posts: 560
Default

What version of Windows are you running?

Have you checked the Window's Device Manager to see if the drivers installed properly? You should see the port (when the adapter is plugged in) be listed on the "Ports - COM and LPT" list and it should not have an exclamation point icon.
__________________
Awana Grand Prix and Pinewood Derby racing - Where a child, an adult and a small block of wood combine for a lot of fun and memories.
Reply With Quote
  #5  
Old 08-27-2008, 08:50 AM
mrphysics mrphysics is offline
Newcomer
 
Join Date: Aug 2004
Posts: 12
Default

Well, the drivers I know are working just fine. I can communicate to these devices through Hyperterminal, so I know that they work. I am starting to think that it is some sort of problem with my code that opens the serial ports. I am in the process of investigating this, and will advise on what I find. It's either this, or something related to the fact that I am using a USB to Serial Port adapater and it's associated drivers.

Mr. Physics.
Reply With Quote
  #6  
Old 08-27-2008, 08:54 AM
gpraceman's Avatar
gpracemanApplication on other PC's gpraceman is offline
Contributor

* Expert *
 
Join Date: Sep 2002
Location: Highlands Ranch, CO
Posts: 560
Default

If you can communicate fine using HyperTerminal, then the problem is not the adapters.

If you post a bit of your code, that may help.

You should also step through the code line by line with the debugger and see where it is tripping up.
__________________
Awana Grand Prix and Pinewood Derby racing - Where a child, an adult and a small block of wood combine for a lot of fun and memories.
Reply With Quote
  #7  
Old 08-27-2008, 10:41 AM
mrphysics mrphysics is offline
Newcomer
 
Join Date: Aug 2004
Posts: 12
Default

Ok here is my code that is giving my trouble:
First I open the Serial port with:
Code:
        If comOriental.IsOpen Then
            comOriental.Close()
        End If
        Try
            With comOriental
                .PortName = udtOriental.ComPort
                .BaudRate = CInt(udtOriental.BaudRate)
                .DataBits = CInt(udtOriental.DataBits)
                '.Parity = Parity.Even
                '.StopBits = StopBits.One
                Select Case udtOriental.Parity
                    Case "Even"
                        .Parity = Parity.Even
                    Case "Mark"
                        .Parity = Parity.Mark
                    Case "None"
                        .Parity = Parity.None
                    Case "Odd"
                        .Parity = Parity.Odd
                    Case Else
                        .Parity = Parity.Space
                End Select
                Select Case udtOriental.StopBit
                    Case "None"
                        .StopBits = StopBits.None
                    Case "One"
                        .StopBits = StopBits.One
                    Case "OnePointFive"
                        .StopBits = StopBits.OnePointFive
                    Case Else
                        .StopBits = StopBits.Two
                End Select
                '.ReadTimeout = 500
                '.WriteTimeout = 500
                '.Encoding = System.Text.Encoding.Unicode
                '.ReadBufferSize = 1
                .Open()
            End With
            PauseTime(1.0)
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
Then call a sub to get information from a device through the above serial port. This sub writes a command "REPORT" to the serial port, then the device returns basically a status report.
Code:
Call OrientalReport()
Subroutine. My code gets stuck in an endless loop in the Do Loop below. Its like I am not getting anything back from the serial port after issuing the "REPORT" command.
Code:
    Public Sub OrientalReport()
        txtOriental.Text = String.Empty
        strOrientalReport = String.Empty
        comOriental.DiscardInBuffer() 'Clear the Input Buffer
        comOriental.Write("REPORT" & vbCrLf)
        'PauseTime(1.0)
        Do
            System.Windows.Forms.Application.DoEvents()
            Debug.Print(txtOriental.Text)
        Loop Until Len(txtOriental.Text) >= 953
        strOrientalReport = txtOriental.Text
    End Sub
Code to get info from serial port as is comes in. This is based off some code that I found as an example of how to communicate through a serial port.
Code:
    Public Delegate Sub myDelOriental()
    Public Sub comOriental_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs)
        txtOriental.Invoke(New myDelOriental(AddressOf updateOriental), New Object() {})
    End Sub
    Public Sub updateOriental()
        With txtOriental
            .Font = New Font("Garamond", 12.0!, FontStyle.Bold)
            .SelectionColor = Color.Red
            .AppendText(comOriental.ReadExisting)
            .ScrollToCaret()
            Debug.Print("1" + txtOriental.Text)
        End With
    End Sub
Here is the example that I found:
Code:
    Private Sub DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles serialPort.DataReceived

        txtDataReceived.Invoke(New myDelegate(AddressOf updateTextBox), New Object() {})
    End Sub

    Private Sub btnSend_Click( _
       ByVal sender As System.Object, _
       ByVal e As System.EventArgs) _
       Handles btnSend.Click
        Try
            Debug.Print(txtDataToSend.Text)
            serialPort.Write(txtDataToSend.Text & vbCrLf)
            txtDataToSend.Text = String.Empty
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Public Delegate Sub myDelegate()
    Public Sub updateTextBox()
        With txtDataReceived
            .Font = New Font("Garamond", 12.0!, FontStyle.Bold)
            .SelectionColor = Color.Red
            .AppendText(serialPort.ReadExisting)
            .ScrollToCaret()
        End With
    End Sub

    Private Sub btnConnect_Click( _
       ByVal sender As System.Object, _
       ByVal e As System.EventArgs) _
       Handles btnConnect.Click
        If serialPort.IsOpen Then
            serialPort.Close()
        End If
        Try
            With serialPort
                .PortName = cbbCOMPorts.Text
                .BaudRate = 9600
                .Parity = IO.Ports.Parity.None
                .DataBits = 8
                .StopBits = IO.Ports.StopBits.One
            End With
            serialPort.Open()

            lblMessage.Text = cbbCOMPorts.Text & " connected."
            btnConnect.Enabled = False
            btnDisconnect.Enabled = True
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub btnDisconnect_Click( _
       ByVal sender As System.Object, _
       ByVal e As System.EventArgs) _
       Handles btnDisconnect.Click
        Try
            serialPort.Close()
            lblMessage.Text = serialPort.PortName & " disconnected."
            btnConnect.Enabled = True
            btnDisconnect.Enabled = False
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
If I issue the "REPORT" command in the above example code, I get what I expect. So......I guess I am at a loss at this point. So any help would be appreciated.

Thanks,
Mr. Physics
Reply With Quote
  #8  
Old 08-27-2008, 11:10 AM
gpraceman's Avatar
gpracemanApplication on other PC's gpraceman is offline
Contributor

* Expert *
 
Join Date: Sep 2002
Location: Highlands Ranch, CO
Posts: 560
Default

Offhand, I do not see a problem. Are you sure that data is being received? I would put a breakpoint in the data received event to check.

In your loop, I'd highly recommend that you put in a timeout check. That is, start a stopwatch just before going into the loop and then add a condition to escape out of the loop if so many seconds have elapsed. Otherwise, you can get in an endless loop, if you only receive partial data or there is some other comms problem.
__________________
Awana Grand Prix and Pinewood Derby racing - Where a child, an adult and a small block of wood combine for a lot of fun and memories.
Reply With Quote
  #9  
Old 08-27-2008, 04:17 PM
mrphysics mrphysics is offline
Newcomer
 
Join Date: Aug 2004
Posts: 12
Default

In the example code that I found, it had:
Code:
 Handles serialPort.DataReceived
after serial port data received sub. Mine did not have that. Now, I'm pretty sure that I had it at one time, but......I guess I deleted it some how. Anyway, I added it back into my code, and I can now get past the problem spot. I do like the idea of a time out timer. Any suggestions on the best way to implement that?

Thanks,
Mr. Physics
Reply With Quote
  #10  
Old 08-27-2008, 04:24 PM
gpraceman's Avatar
gpracemanApplication on other PC's gpraceman is offline
Contributor

* Expert *
 
Join Date: Sep 2002
Location: Highlands Ranch, CO
Posts: 560
Default

Check out the Stopwatch class. Start the stopwatch before going into the loop and while in the loop check the elapsed time against some appropriate value. If it equals or exceeds that value, then exit the loop.
__________________
Awana Grand Prix and Pinewood Derby racing - Where a child, an adult and a small block of wood combine for a lot of fun and memories.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Application on other PC's
Application on other PC's
Application on other PC's Application on other PC's
Application on other PC's
Application on other PC's
Application on other PC's Application on other PC's Application on other PC's Application on other PC's Application on other PC's Application on other PC's Application on other PC's
Application on other PC's
Application on other PC's
 
Application on other PC's
Application on other PC's
 
-->