Solved

Application takes data from devices connected via converter RS485/USB.

Posted on 2012-03-14
5
620 Views
Last Modified: 2012-06-27
Hi.

My C# application takes data from devices connected via a converter RS485/USB.
However I get an error that does not know how to solve.
When the devices are turned off, my application freezes.
How can not lock the computer, but show a warning message to connect the devices or turn on and expects to receive data?

Thank you,
ocaccy
0
Comment
Question by:ocaccy
  • 3
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
tcss earned 500 total points
ID: 37727888
Are you reading from the serial/RS485 port directly or via a supplier provided API?

Assuming you reading fromthe port, are you responding to the datareceived event or using a blocking read with the timeout set to infinate?.

Often with a USB device if the connected hardware if not powered (ie off) the virtual serial port does not exist. Are you checking for the port before opening it?

Hylton
0
 

Author Comment

by:ocaccy
ID: 37727915
Hi,
snippet of the app:

public Form1()
        {
            InitializeComponent();
            
            LBL_message.Text = "";
            label4.Text = LBL_message.Text;

            int M_times = (Convert.ToInt32(nUD_KyuSoku.Value) + Convert.ToInt32(nUD_RyuSoku.Value) + Convert.ToInt32(nUD_Seiti.Value)) / 10;

            limpezadeAbertura();

            label127.Text = delta.ToString();
            preparando_lbl.Visible = false;
            button34.Visible = false;
            button5.Enabled = false;
            button33.Enabled = false;
            i_channel = Convert.ToInt32(nUD_Kesu.Value);

            GraphPane myPane02m = zed2mmccc.GraphPane;

            outputList_Initialize();

            Settings.Read();
            TopMost = Settings.Option.StayOnTop;

            // let form use multiple fonts
            origFont = Font;
            FontFamily ff = new FontFamily("Courier New");
            monoFont = new Font(ff, 8, FontStyle.Regular);
            Font = Settings.Option.MonoFont ? monoFont : origFont;

            CommPort com = CommPort.Instance;
            com.StatusChanged += OnStatusChanged;
            com.DataReceived += OnDataReceived;
            com.Open();

            rB_alarmON2.Checked = true;
            rB_alarmON1.Checked = true;
            rB_alarmOFF1.Checked = false;
            rB_alarmOFF2.Checked = false;
            limpezaInicial();
        }

        private DateTime inicio;

        int TickStart, intMode = 1;

        // shutdown the worker thread when the form closes
        protected override void OnClosed(EventArgs e)
        {
            CommPort com = CommPort.Instance;
            com.Close();

            base.OnClosed(e);
        }

Open in new window


Thank you,
ocaccy
0
 

Author Comment

by:ocaccy
ID: 37736426
Hi.
The problem was solved.
I put a routine time to access the serial port.
At the end of this time or if the loop condition is satisfied; Closes the commport.
If do not receive data in time; closes the commport.
CommPort com = CommPort.Instance;
com.Close();
With that I had no more problems with the serial port.

Best regards,
ocaccy
0
 
LVL 1

Expert Comment

by:tcss
ID: 37736461
Thank you for the feedback. Please you were able to solve it.
0
 

Author Closing Comment

by:ocaccy
ID: 37736476
Thank you,
ocaccy
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

11 Experts available now in Live!

Get 1:1 Help Now