Example #1
0
        public static void Soft_Reset(string querytype, string IP, string Port)
        {
            byte[] code = new byte[6];

            if (querytype == "Reset")
            {
                code = new byte[] { 0xFF, 0x01, 0x00, 0x0F, 0x00, 0x00, 0x10 };
            }

            Peclo_Over_IP.Connect(IP, Port);
            SendCommand(code, IP, Port);
            Thread.Sleep(200);
        }
Example #2
0
 public static void SendCommand(byte[] command, string IP, string Port)
 {
     Peclo_Over_IP.Connect(IP, Port);
     SendToSocket(command, true);
 }
Example #3
0
        public static int Focus_Query(uint address, string IP, string Port)
        {
            byte[] code         = new byte[6];
            byte   pelcoaddress = 0x01;

            if (address == 1)
            {
                pelcoaddress = 0x01;
            }
            else if (address == 2)
            {
                pelcoaddress = 0x02;
            }
            else if (address == 3)
            {
                pelcoaddress = 0x03;
            }


            byte command1           = 0x01;
            byte command2           = 0x55;
            byte data1              = 0x00;
            byte data2              = 0x00;
            byte CalculatedCheckSum = (byte)((address + command1 + command2 + data1 + data2) % 256);

            code = new byte[] { 0xFF, pelcoaddress, command1, command2, data1, data2, CalculatedCheckSum };



            Peclo_Over_IP.Connect(IP, Port);
            bool   validreply = false;
            string response   = "";
            int    zoomreply  = 0;

            int count = 0;

            while (validreply == false && count < 200)
            {
                response = Peclo_Over_IP.GetResponseManual(code).Result;
                if (response != null)
                {
                    string[] responsearray = response.Split(' ');


                    for (int i = 0; i < responsearray.Length - 6; i++)
                    {
                        if (responsearray[i] == "FF" && responsearray[i + 2] == "01" && responsearray[i + 3] == "5D")
                        {
                            try
                            {
                                address  = Convert.ToByte(Convert.ToInt32(responsearray[i + 1], 16));
                                command1 = Convert.ToByte(Convert.ToInt32(responsearray[i + 2], 16));
                                command2 = Convert.ToByte(Convert.ToInt32(responsearray[i + 3], 16));
                                data1    = Convert.ToByte(Convert.ToInt32(responsearray[i + 4], 16));
                                data2    = Convert.ToByte(Convert.ToInt32(responsearray[i + 5], 16));
                                byte returnedchecksum = Convert.ToByte(Convert.ToInt32(responsearray[i + 6], 16));

                                CalculatedCheckSum = (byte)((address + command1 + command2 + data1 + data2) % 256);

                                if (returnedchecksum == CalculatedCheckSum && response.StartsWith("00 00") == false)
                                {
                                    response = "FF " +
                                               responsearray[i + 1] + " " +
                                               responsearray[i + 2] + " " +
                                               responsearray[i + 3] + " " +
                                               responsearray[i + 4] + " " +
                                               responsearray[i + 5] + " " +
                                               responsearray[i + 6];

                                    string data = responsearray[i + 4] + responsearray[i + 5];
                                    zoomreply  = Convert.ToInt32(data, 16);
                                    validreply = true;
                                    break;
                                }
                            }
                            catch (Exception g)
                            {
                            }
                        }
                    }
                }


                Thread.Sleep(200);
                count++;
            }
            return(zoomreply);
        }
Example #4
0
        public static string Pelco_Mode_Query(string querytype, string IP, string Port)
        {
            byte[] code = new byte[6];

            if (querytype == "Pelco Mode")
            {
                code = new byte[] { 0xFF, 0x01, 0x03, 0x6B, 0x00, 0x00, 0x6F };
            }

            Peclo_Over_IP.Connect(IP, Port);
            bool   validreply = false;
            string response   = "";


            int count = 0;

            while (validreply == false && count < 200)
            {
                response = Peclo_Over_IP.GetResponseManual(code).Result;
                if (response != null)
                {
                    string[] responsearray = response.Split(' ');


                    for (int i = 0; i < responsearray.Length - 6; i++)
                    {
                        if (responsearray[i] == "FF" && responsearray[i + 1] == "01" && responsearray[i + 2] == "03" && responsearray[i + 3] == "6D")
                        {
                            try
                            {
                                byte address          = Convert.ToByte(Convert.ToInt32(responsearray[i + 1], 16));
                                byte command1         = Convert.ToByte(Convert.ToInt32(responsearray[i + 2], 16));
                                byte command2         = Convert.ToByte(Convert.ToInt32(responsearray[i + 3], 16));
                                byte data1            = Convert.ToByte(Convert.ToInt32(responsearray[i + 4], 16));
                                byte data2            = Convert.ToByte(Convert.ToInt32(responsearray[i + 5], 16));
                                byte returnedchecksum = Convert.ToByte(Convert.ToInt32(responsearray[i + 6], 16));

                                byte CalculatedCheckSum = (byte)((address + command1 + command2 + data1 + data2) % 256);

                                if (returnedchecksum == CalculatedCheckSum && response.StartsWith("00 00") == false)
                                {
                                    string modedata     = responsearray[i + 4] + responsearray[i + 5];
                                    int    modedata_int = Convert.ToInt32(modedata, 16);

                                    BitArray b = new BitArray(new int[] { modedata_int });

                                    string binary = Convert.ToString(modedata_int, 2);

                                    if (b[10] == false && b[11] == false)
                                    {
                                        response = "Traditional";
                                        return(response);

                                        break;
                                    }
                                    else if (b[10] == true && b[11] == false)
                                    {
                                        response = "Strict";
                                        return(response);

                                        break;
                                    }
                                    else if (b[10] == false && b[11] == true)
                                    {
                                        response = "RevTilt";
                                        return(response);

                                        break;
                                    }



                                    response   = "";
                                    validreply = true;
                                    break;
                                }
                            }
                            catch (Exception g)
                            {
                            }
                        }
                    }
                }


                Thread.Sleep(200);
                count++;
            }
            return(response);
        }
Example #5
0
        public static int Tilt_Query(string querytype, string IP, string Port)
        {
            byte[] code = new byte[6];

            if (querytype == "Tilt")
            {
                code = new byte[] { 0xFF, 0x01, 0x00, 0x53, 0x00, 0x00, 0x54 };
            }

            Peclo_Over_IP.Connect(IP, Port);
            bool   validreply = false;
            string response   = "";
            int    tiltreply  = 0;

            int count = 0;

            while (validreply == false && count < 200)
            {
                response = Peclo_Over_IP.GetResponseManual(code).Result;
                if (response != null)
                {
                    string[] responsearray = response.Split(' ');


                    for (int i = 0; i < responsearray.Length - 6; i++)
                    {
                        if (responsearray[i] == "FF" && responsearray[i + 1] == "01" && responsearray[i + 2] == "00" && responsearray[i + 3] == "5B")
                        {
                            try
                            {
                                byte address          = Convert.ToByte(Convert.ToInt32(responsearray[i + 1], 16));
                                byte command1         = Convert.ToByte(Convert.ToInt32(responsearray[i + 2], 16));
                                byte command2         = Convert.ToByte(Convert.ToInt32(responsearray[i + 3], 16));
                                byte data1            = Convert.ToByte(Convert.ToInt32(responsearray[i + 4], 16));
                                byte data2            = Convert.ToByte(Convert.ToInt32(responsearray[i + 5], 16));
                                byte returnedchecksum = Convert.ToByte(Convert.ToInt32(responsearray[i + 6], 16));

                                byte CalculatedCheckSum = (byte)((address + command1 + command2 + data1 + data2) % 256);

                                if (returnedchecksum == CalculatedCheckSum && response.StartsWith("00 00") == false)
                                {
                                    response = "FF " +
                                               responsearray[i + 1] + " " +
                                               responsearray[i + 2] + " " +
                                               responsearray[i + 3] + " " +
                                               responsearray[i + 4] + " " +
                                               responsearray[i + 5] + " " +
                                               responsearray[i + 6];

                                    string data = responsearray[i + 4] + responsearray[i + 5];
                                    tiltreply  = Convert.ToInt32(data, 16);
                                    validreply = true;
                                    break;
                                }
                            }
                            catch (Exception g)
                            {
                            }
                        }
                    }
                }


                Thread.Sleep(200);
                count++;
            }
            return(tiltreply);
        }