Click here to Skip to main content
15,881,092 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi, I'll make this short as possible..

I'm trying to communicate with boom barrier machine the connection is okay but in physically the barrier does not lift up this happens sometimes is there a way for me to know if the machine work or not? i only pass an IP address and a port to make it work..
btw I'm using c#..

C#
try
           {
               zkemkeeper.CZKEM zk = new zkemkeeper.CZKEM();
               bool connected = false;
               int PortNo = 4370;
               connected = zk.Connect_Net(globalVariables.boomGateIP, PortNo);
               if (connected)
               {
                   if (zk.ACUnlock(1, 100))
                   {
                       GatesRepository gateRepository = new GatesRepository();
                       string hostName = Dns.GetHostName();
                       gateRepository.OpenBoom(globalVariables.Username,  Settings.Default.BoothId, "", "", getIP.getHostName(), hostName, txtContainernumber.Text);
                   }
                   else
                   {
                       MessageBox.Show("error opening boom gate door.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                   }
                   zk.Disconnect();
               }
               else
               {
                   MessageBox.Show("error connecting with boom gate device. call it", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
               }
           }
           catch (Exception ex)
           {
               MessageBox.Show(ex.Message);
           }


What I have tried:

i tried a for loop but the problem is still there, i'm really out of option guys.. I'm drained..
Posted
Updated 23-Sep-20 20:14pm
v3

1 solution

I always Ping before connecting or trying to reconnect.

Ping Class (System.Net.NetworkInformation) | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900