Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6697045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:24:49+00:00 2026-05-26T06:24:49+00:00

I’m writing a software that communicates with 4 devices via serial port. One of

  • 0

I’m writing a software that communicates with 4 devices via serial port. One of them, Input/output module (ICP CON) has 4 input channels (DL) and 4 output channels (RL). I need to monitor status of DL channels and then, when a signal is detected I have to do some processing, which depends on which signal has been detected.

I’m calling 4 methods asynchronously, every 500ms (timer), here’s the tick event:

//stop the timer
timer1.Stop();

//open com port 2
Tester.Devices.ICP.OpenICPPort(2, 9600);

//dl 0
ic = new CheckDLStatus(0, this);
ic.Execute();

//dl 1
ic = new CheckDLStatus(1, this);
ic.Execute();

//dl 2
ic = new CheckDLStatus(2, this);
ic.Execute();

//dl3 
ic = new CheckDLStatus(3, this);
ic.Execute();

//close com port 2
Tester.Devices.ICP.CloseICPPort(2);

//enable the timer again
timer1.Enabled = true;

public CheckDLStatus(int DL, Form1 F1)
{
    //form 1 instance
    f1 = F1;

    // setup the delegate to call
    switch (DL)
    {
        case (0):
        {
            checkDL_delegate = new checkDL(
                BusinessLogicLayer.Classes.
                DevicesCommunication.CheckDl0);

            break;
        }
        case (1):
        {
            checkDL_delegate = new checkDL(
                BusinessLogicLayer.Classes.
                DevicesCommunication.CheckDl1);

                break;
        }
        case (2):
        {
            checkDL_delegate = new checkDL(
                BusinessLogicLayer.Classes.
                DevicesCommunication.CheckDl2);

                break;
        }
        case (3):
        {
            checkDL_delegate = new checkDL(
                BusinessLogicLayer.Classes.
                DevicesCommunication.CheckDl3);

                break;
        }
    }
}


public static void CheckDl2()
{
    //declare
    bool currentStatus;

    try
    {
        //input
        currentStatus = DevicesCommunication.Dl_2_On; 
        //should be false at the start of the test, 
        //so when it becomes true, the change is detected immediately

        //dl2?
        if (ICP.LookForSignal_DL2((short)2, 
            Util.Classes.Util.ResolveComPortNumber(
                Cache.settings.icpModulePort),     
            Convert.ToInt32(Cache.settings.icpModuleBaudRate)))
        {
            //signal detected
            DevicesCommunication.Dl_2_On = true;
        }
        else
        {
            //signal not detected
            DevicesCommunication.Dl_2_On = false;
        }

        //check, if status of DL2 has been changed 
        //(from true to false, from false to true)
        if (currentStatus != DevicesCommunication.Dl_2_On)
        {
            //status from before checking signal is different
            // from status read from the device so
            //status has changed

            if (DevicesCommunication.Dl_2_On)
            {
                DevicesCommunication.DL2_apperancesCounter += 1;

                //TODO
                //process
                //ProcessDL2();
            }
        }
        else
        {
            //status did not change
            //just clear buffer
            ClearBuffer();
        }

        return;
    }
    catch (Exception ex)
    {
        Util.Classes.ErrorLogging.LogError(ex, true);
        //EndCurrentTest(); 
        return;
    }
}

Execute() method, that invokes a delegate:

public void Execute()
{
    // call the method on the thread pool
    checkDL_delegate.BeginInvoke(
        this.CallBack, null);

    //checkDL_delegate.Invoke();
}

The method that is called for checking DL2 status:

public static bool LookForSignal_DL2(short DL_number, int port, int baudRate)
{
    //declare
    bool iBit;

    try
    {
        //check if there is a signal at specified Dl_number
        iBit = DCON.Read_DI_Bit(Convert.ToByte(port), 1, -1, 
            DL_number, 16, 0, 100);

        //return resposne
        return iBit; //true/false
    }
    catch (Exception ex)
    {
        Util.Classes.ErrorLogging.LogError(ex, true);
        return false;
    }
}

My problem is, when I turn on signal on DL2 channel, and I call LookForSignal_DL2 like this, without the timer and asynchronous calls (just for test):

private void button25_Click(object sender, EventArgs e)
{
    ICP.OpenICPPort(2, 9600);

    if (ICP.LookForSignal_DL2(2, 2, 9600))
    {
        MessageBox.Show("True");
    }
    else
    {
        MessageBox.Show("false!");
    }

    ICP.CloseICPPort(2);
}

It works – returns true.

If, in Execute() method I use Invoke, which makes the method call synchronous – it works (returns true), but this way I can only check 1 signal at the time.

If, in Execute() method I use BeginInvoke it doesn’t work, it returns false, even though there is signal in DL2.

I admit I don’t know what’s going on. Do you have any idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:24:49+00:00Added an answer on May 26, 2026 at 6:24 am

    I figured it out, if it helps anyone, I made a mistake here (bold text):

    //stop the timer
    timer1.Stop();
    
    //open com port 2
    Tester.Devices.ICP.OpenICPPort(2, 9600);
    
    //dl 0
    ic = new CheckDLStatus(0, this);
    ic.Execute();
    
    //dl 1
    ic = new CheckDLStatus(1, this);
    ic.Execute();
    
    //dl 2
    ic = new CheckDLStatus(2, this);
    ic.Execute();
    
    //dl3 
    ic = new CheckDLStatus(3, this);
    ic.Execute();
    

    Tester.Devices.ICP.CloseICPPort(2);

    I ran my methods asynchronously, but the execution of the code went on, and everytime the port had been closed before any of the methods was able to check for signal. Unfortunetely the SDK library doesn’t return any error in that case, so it just kept returning false.

    Thank you for your comments.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I need to clean up various Word 'smart' characters in user input, including but
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.