Solved

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

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
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 hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

806 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