?
Solved

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

Posted on 2012-03-14
5
Medium Priority
?
634 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
tcss earned 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

801 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