Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2012-03-14
5
Medium Priority
?
641 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

618 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