Solved

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

Posted on 2012-03-14
5
622 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
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.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

863 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

24 Experts available now in Live!

Get 1:1 Help Now