Example #1
0
        private void btnAddToClass_Click(object sender, EventArgs e)
        {
            // Connect to the vault and continue if successful.
            if (!ConnectToSelectedVault())
            {
                return;
            }

            ObjectClasses classes = vault.ClassOperations.GetAllObjectClasses();

            foreach (ObjectClass cl in classes)
            {
                if (cl.ObjectType == 0)
                {
                    ObjectClassAdmin cla = vault.ClassOperations.GetObjectClassAdmin(cl.ID);
                    // Need to get the AssociatedPropertyDefs from the underlying ObjectClass (except
                    // for a few built-in properties), otherwise UpdateObjectClassAdmin() will fail.
                    CopyPropertiesToObjectClassAdmin(cla, cl);
                    AssociatedPropertyDef apd = new AssociatedPropertyDef();
                    apd.PropertyDef = ((PropertyComboBoxItem)propertyComboBox.SelectedItem).propID;
                    cla.AssociatedPropertyDefs.Add(-1, apd);
                    vault.ClassOperations.UpdateObjectClassAdmin(cla);
                }
            }
            MessageBox.Show("Done");
        }
Example #2
0
        // Note: Will go through ALL class, even built-in ones (modify the code if different behavior
        // is needed).
        private void ClearSelectedClassAliases()
        {
            ObjectClasses classes = vault.ClassOperations.GetAllObjectClasses();

            foreach (ObjectClass cl in classes)
            {
                // The corresponding ObjectClassAdmin
                ObjectClassAdmin cla = vault.ClassOperations.GetObjectClassAdmin(cl.ID);

                string clName  = cla.Name.Replace(" ", "");    //String.Empty);
                string aliases = cla.SemanticAliases.Value;

                // Remove the aliasPrefix if it exists.
                string updatedAliases = RemoveAlias(aliases, clPrefix + clName);
                if (aliases != updatedAliases)
                {
                    // Need to get the AssociatedPropertyDefs from the underlying ObjectClass (except
                    // for a few built-in properties), otherwise UpdateObjectClassAdmin() will fail.
                    CopyPropertiesToObjectClassAdmin(cla, cl);

                    cla.SemanticAliases.Value = updatedAliases;
                    vault.ClassOperations.UpdateObjectClassAdmin(cla);
                }
            }
        }
 private static bool TransmitCommand(ObjectClasses.ISerialPortIo serialPort1, byte[] Command, int ArrayLength)
 {
     try
     {
         serialPort1.DiscardInBuffer();
         serialPort1.DiscardOutBuffer();
         serialPort1.Write(Command, 0, ArrayLength);
     }
     catch (System.IO.IOException e)
     {
         DataComms.CreateThreadInstance("Transm. Command - exception Thrown! " + e.Message);
         return false;
     }
     catch (UnauthorizedAccessException e)
     {
         DataComms.CreateThreadInstance("Transm. Command - exception Thrown! " + e.Message);
         return false;
     }
     catch (Exception e)
     {
         DataComms.CreateThreadInstance("Transm. Command - exception Thrown! " + e.Message);
         return false;
     }
     return true;
 }
        public static bool TryCloseSerialPort(ObjectClasses.ISerialPortIo serialPort1, string source)
        {
            if (serialPort1.IsOpen == true)
            {
                try
                {
                    serialPort1.Close();
                    return true;
                }
                catch (System.IO.IOException)
                {
                    DataComms.CreateThreadInstance("TryCloseSerialPort - IOException: " + source);
                }
                catch (UnauthorizedAccessException)
                {
                    DataComms.CreateThreadInstance("TryCloseSerialPort - UnauthorizedAccessException: " + source);
                }
                catch (Exception)
                {
                    DataComms.CreateThreadInstance("TryCloseSerialPort - Exception: " + source);
                }

                finally
                {

                }

                return false;
            }
            else
            {
                return true;
            }
        }
        public static bool SetMotorSpeed(ObjectClasses.ISerialPortIo serialPort1, int SpeedRefVal, byte DirectionByte)
        {
            Encoding ascii = Encoding.ASCII;
            byte[] asciiBytes = ascii.GetBytes(SpeedRefVal.ToString());                  //Converts the string of ASCII characters to a byte array where each member is the decimal representation of the ASCII value

            byte[] RSSCommand = new byte[25];
            RSSCommand[0] = 0x05;               //ENQ Header
            RSSCommand[1] = 0x30;               //Station ID = 0;
            RSSCommand[2] = 0x30;               //Station ID = 0;
            RSSCommand[3] = 0x43;               //C
            RSSCommand[4] = 0x4A;               //J
            RSSCommand[5] = 0x52;               //R
            RSSCommand[6] = DirectionByte;      //Dir
            RSSCommand[7] = 0x30;               //Speed 1000.0
            RSSCommand[8] = 0x30;               //
            RSSCommand[9] = 0x30;               //
            RSSCommand[10] = 0x30;              //
            RSSCommand[11] = 0x30;              //
            RSSCommand[12] = 0x30;              //0
            RSSCommand[13] = 0x36;              //6
            RSSCommand[14] = 0x30;              //0
            RSSCommand[15] = 0x30;              //0
            RSSCommand[16] = 0x30;              //0
            RSSCommand[17] = 0x36;              //6
            RSSCommand[18] = 0x30;              //0
            RSSCommand[19] = 0x30;              //0
            RSSCommand[20] = 0x39;              //9
            RSSCommand[21] = 0x39;              //9
            RSSCommand[22] = 0x39;              //9
            RSSCommand[23] = 0x39;              //9
            RSSCommand[24] = 0x04;              //EOT

            for (int ii = 0; ii < asciiBytes.Length; ii++)
            {
                RSSCommand[10 - ii] = asciiBytes[asciiBytes.Length - 1 - ii];
            }

            /*return*/ TransmitCommand(serialPort1, RSSCommand, 25);


            System.Threading.Thread.Sleep(100);

            while (serialPort1.BytesToRead != 0)
            {
                string text = Convert.ToString(serialPort1.ReadByte().ToString("X"));
                System.Diagnostics.Debug.WriteLine(Convert.ToString(text));
            }
            //serialPort1.Close();
            return true;
        }
Example #6
0
        private ObjectClass GetObjectClass(string objectClassName)
        {
            //если такой есть, то возвращаем его
            foreach (ObjectClass oc in ObjectClasses)
            {
                if (oc.Name == objectClassName)
                {
                    return(oc);
                }
            }

            //иначе, добавляем и возвращаем добавленный
            ObjectClasses.Add(new ObjectClass(objectClassName));
            return(ObjectClasses[ObjectClasses.Count - 1]);
        }
        public MapRegionEditorForm(ObjectClasses.MapRegion mapRegion)
        {
            InitializeComponent();
            this.MapRegion = mapRegion;

            mapDropDown.Items.Add(MinimapLoader.World);
            mapDropDown.Items.Add(MinimapLoader.Dungeon);

            x1NumericUpDown.Value = MapRegion.X1;
            y1NumericUpDown.Value = MapRegion.Y1;
            x2NumericUpDown.Value = MapRegion.X2;
            y2NumericUpDown.Value = MapRegion.Y2;

            mapRegionControl.MapRegion = mapRegion;
            mapRegionControl.Focus();
        }
Example #8
0
        // Note: Will go through ALL classes, even built-in ones (modify the code if different behavior
        // is needed).
        private void ClearAllClassAliases()
        {
            ObjectClasses classes = vault.ClassOperations.GetAllObjectClasses();

            foreach (ObjectClass cl in classes)
            {
                // The corresponding ObjectClassAdmin
                ObjectClassAdmin cla = vault.ClassOperations.GetObjectClassAdmin(cl.ID);

                // Need to get the AssociatedPropertyDefs from the underlying ObjectClass (except
                // for a few built-in properties), otherwise UpdateObjectClassAdmin() will fail.
                CopyPropertiesToObjectClassAdmin(cla, cl);

                cla.SemanticAliases.Value = "";
                vault.ClassOperations.UpdateObjectClassAdmin(cla);
            }
        }
        public static bool SetMotorTorque(ObjectClasses.ISerialPortIo serialPort1, int TorqueRefVal)
        {
            string HexString = TorqueRefVal.ToString("X");
            Encoding ascii = Encoding.ASCII;
            byte[] asciiBytes = ascii.GetBytes(HexString);                  //Converts the string of ASCII characters to a byte array where each member is the decimal representation of the ASCII value

            byte[] WSSCommand = new byte[25];
            WSSCommand[0] = 0x05;               //ENQ Header
            WSSCommand[1] = 0x30;               //Station ID = 0;
            WSSCommand[2] = 0x30;               //Station ID = 0;
            WSSCommand[3] = 0x57;               //W
            WSSCommand[4] = 0x53;               //S
            WSSCommand[5] = 0x53;               //S
            WSSCommand[6] = 0x30;               //0 - BLOCK Q'TY
            WSSCommand[7] = 0x31;               //1
            WSSCommand[8] = 0x30;               //0 - VARIABLE LENGTH
            WSSCommand[9] = 0x36;               //6
            WSSCommand[10] = 0x25;              //%
            WSSCommand[11] = 0x4D;              //M
            WSSCommand[12] = 0x44;              //D
            WSSCommand[13] = 0x30;              //COMM CODE (044)
            WSSCommand[14] = 0x34;              //
            WSSCommand[15] = 0x34;              //
            WSSCommand[16] = 0x30;              //DATA
            WSSCommand[17] = 0x30;              //
            WSSCommand[18] = 0x30;              //
            WSSCommand[19] = 0x30;              //
            WSSCommand[20] = 0x30;              //
            WSSCommand[21] = 0x30;              //
            WSSCommand[22] = 0x30;              //
            WSSCommand[23] = 0x30;              //
            WSSCommand[24] = 0x04;              //EOT

            for (int ii = 0; ii < asciiBytes.Length; ii++)
            {
                WSSCommand[23 - ii] = asciiBytes[asciiBytes.Length - 1 - ii];
            }

            if (TransmitCommand(serialPort1, WSSCommand, 25) == false) return false;
            WSSCommand[15] = 0x35;
            return (TransmitCommand(serialPort1, WSSCommand, 25));
        }
        public static bool TryOpenSerialPort(ObjectClasses.ISerialPortIo serialPort1, string source)
        {
            if (serialPort1.IsOpen == false)
            {
                try
                {
                    serialPort1.Open();
                    return true;
                }
                catch (System.IO.IOException e)
                {
                    DataComms.CreateThreadInstance("TryOpenSerialPort - IOException: " + source);
                }

                catch (UnauthorizedAccessException e)
                {
                    DataComms.CreateThreadInstance("TryOpenSerialPort - UnauthorizedAccessException " + source);
                    serialPort1.Close();
                    //serialPort1.Dispose();
                    //serialPort1 = new SerialPort();
                    //Logger.Write("UnauthorizedAccessException while trying to open the serial port");
                    //LblStatus.Text = "UnauthorizedAccessException: Please exit and restart the program";
                }

                catch (Exception)
                {
                    DataComms.CreateThreadInstance("TryOpenSerialPort - Exception " + source);
                }

                finally
                {

                }

                return false;
            }
            else
            {
                return true;
            }
        }
Example #11
0
        /// <summary>
        /// Merges non-existing data from another set
        /// </summary>
        /// <param name="dataToMerge"></param>
        public void Merge(S57Data dataToMerge)
        {
            foreach (KeyValuePair <string, S57ObjectClass> pair in dataToMerge.ObjectClasses)
            {
                if (!ObjectClasses.Keys.Contains(pair.Key))
                {
                    ObjectClasses.Add(pair.Key, pair.Value);
                    _classes.Add(pair.Value.Code, pair.Value);
                }
            }

            foreach (KeyValuePair <string, S57Attribute> pair in dataToMerge.Attributes)
            {
                if (!Attributes.Keys.Contains(pair.Key))
                {
                    Attributes.Add(pair.Key, pair.Value);
                    _attrs.Add(pair.Value.Code, pair.Value);
                }
                else
                {
                    foreach (KeyValuePair <int, string> decode in pair.Value.AttrDecode)
                    {
                        if (!Attributes[pair.Key].AttrDecode.Keys.Contains(decode.Key))
                        {
                            Attributes[pair.Key].AttrDecode.Add(decode.Key, decode.Value);
                        }
                    }
                    foreach (KeyValuePair <int, string> expectedInput in pair.Value.ExpectedInput)
                    {
                        if (!Attributes[pair.Key].ExpectedInput.Keys.Contains(expectedInput.Key))
                        {
                            Attributes[pair.Key].ExpectedInput.Add(expectedInput.Key, expectedInput.Value);
                        }
                    }
                }
            }
        }
Example #12
0
        private void CreateClassAliases()
        {
            ObjectClasses classes = vault.ClassOperations.GetAllObjectClasses();

            foreach (ObjectClass cl in classes)
            {
                // Skip Assignment and Report classes (comment this line out if you want to include them).
                if (cl.ID < 0)
                {
                    continue;
                }

                // The corresponding ObjectClassAdmin
                ObjectClassAdmin cla = vault.ClassOperations.GetObjectClassAdmin(cl.ID);

                string clName  = cla.Name.Replace(" ", "");    //String.Empty);
                string aliases = cla.SemanticAliases.Value;

                Alias newAlias = new Alias(Alias.ELEMENT_TYPE_CL, clName, clPrefix);

                // Add the new alias if not already there.
                string updatedAliases = AddAlias(aliases, newAlias.ElementAlias);
                if (aliases != updatedAliases)
                {
                    // Need to get the AssociatedPropertyDefs from the underlying ObjectClass (except
                    // for a few built-in properties), otherwise UpdateObjectClassAdmin() will fail.
                    CopyPropertiesToObjectClassAdmin(cla, cl);

                    cla.SemanticAliases.Value = updatedAliases;
                    vault.ClassOperations.UpdateObjectClassAdmin(cla);
                }

                // We will need the alias object later when generating the "Aliases.cs" and "Config.cs" files.
                clAliases.Add(newAlias);
            }
        }
 public static bool TryReadSerialPort(ObjectClasses.ISerialPortIo serialPort1, out byte ReadByte)
 {
     try
     {
         ReadByte = Convert.ToByte(serialPort1.ReadByte());
         return true;
     }
     catch (System.IO.IOException)
     {
         DataComms.CreateThreadInstance("serialPort1.ReadByte - IOException");
         ReadByte = 0;
         return false;
     }
     catch (UnauthorizedAccessException e)
     {
         DataComms.CreateThreadInstance("serialPort1.ReadByte - UnauthorizedAccessException");
         ReadByte = 0;
         return false;
     }
     catch (Exception)
     {
         DataComms.CreateThreadInstance("serialPort1.ReadByte - Exception");
         ReadByte = 0;
         return false;
     }
 }
        public static bool DisableEmergencyStop(ObjectClasses.ISerialPortIo serialPort1, Label lblStatus)
        {
            byte[] RSSCommand = new byte[19];
            RSSCommand[0] = 0x05;               //ENQ Header
            RSSCommand[1] = 0x30;               //Station ID = 0;
            RSSCommand[2] = 0x30;               //Station ID = 0;
            RSSCommand[3] = 0x57;               //W
            RSSCommand[4] = 0x53;               //S
            RSSCommand[5] = 0x53;               //S
            RSSCommand[6] = 0x30;               //Request 1 Block Q'ty
            RSSCommand[7] = 0x31;               //Request 1 Block Q'ty
            RSSCommand[8] = 0x30;               //Block Varibale Length is 6
            RSSCommand[9] = 0x36;               //Block Varibale Length is 6
            RSSCommand[10] = 0x25;              //%
            RSSCommand[11] = 0x4D;              //M
            RSSCommand[12] = 0x58;              //X - Request %MD Request Data Type is 32bit
            RSSCommand[13] = 0x35;              //4
            RSSCommand[14] = 0x32;              //8
            RSSCommand[15] = 0x31;              //9
            RSSCommand[16] = 0x30;              //00
            RSSCommand[17] = 0x30;              //01 - E-Stop Enable
            RSSCommand[18] = 0x04;              //EOT

            return TransmitCommand(serialPort1, RSSCommand, 19);
        }
 public PowerStepTestDS(ObjectClasses.ISerialPortIo SerialPort) : base(SerialPort)
 {
     CycleCounter = 0;                                       //Reset the Cycle Counter when a new instance is created
     CounterFlag = false;                                    //Reset the counter flag when a new instance is created
 }
        public bool CanIncrementRep { get; set; }               //Boolean to prevent double incement of rep counter


        public TunkEcceLatsDS(ObjectClasses.ISerialPortIo SerialPort)
            : base(SerialPort)
        {
            TotalReps = 5;
        }
        public static objServoResult DisableDrive(ObjectClasses.SerialPortIo serialPort)
        {
            objServoResult ServoResult = new objServoResult();
            if (SerialMotorControl.DisableDrive(serialPort) == true)
            {
                ServoResult.IsSuccess = true;
                ServoResult.ErrorMessage = "";
                ServoResult.ErrorCode = 0;
            }
            else
            {
                ServoResult.IsSuccess = false;
                ServoResult.ErrorMessage = "Disable Drive Failed.";
                ServoResult.ErrorCode = -2;
            }

            if (ServoResult.IsSuccess == false)
            {
                frmMessageDialog.DisplayBriefMessage("Disable Drive Failed: Check cable connections.");
            }

            return ServoResult;
        }
 public frmSerialCommsTest(ObjectClasses.ISerialPortIo serialPort)
 {
     InitializeComponent();
     serialPort1 = serialPort;
     ServoController = new objServoController();
 }
        public static objServoResult ReadFeedback(ObjectClasses.ISerialPortIo serialPort1, double[] FeedbackParams, bool ReadSuccess, byte currentByte, byte[] streamPacket, byte[] currentSpeed, byte[] currentPulse, byte[] currentTorque, byte[] currentContactStatus, ref int ErrorCode, int TimeOutCounter, objServoResult RetVal, StringBuilder sb, string ByteString)
        {
            GlobalVariables.SerialPortBusyLeft = true;
            //objServoResult RetVal = new objServoResult();

            FeedbackParams[0] = 0;
            FeedbackParams[1] = 0;
            FeedbackParams[2] = 0;
            FeedbackParams[3] = 0;
            currentByte = 0;
            ReadSuccess = false;
            TimeOutCounter = 0;
            ErrorCode = 0;
            sb.Clear();

            //System.Diagnostics.Debug.WriteLine("Bytes in Buffer before empty: " + serialPort1.BytesToRead.ToString());
            ByteString = serialPort1.ReadExisting();
            //System.Diagnostics.Debug.WriteLine("Bytes in Buffer before empty: " + serialPort1.BytesToRead.ToString());
            //SerialPortFunctions.TryDiscardInputBuffer(serialPort1);
            //SerialPortFunctions.TryDiscardOutputBuffer(serialPort1);
            //System.Threading.Thread.Sleep(5);
            //if (SerialPortFunctions.TryDiscardInputBuffer(serialPort1) == false) { RetVal.ErrorCode = 1; RetVal.IsSuccess = false; return RetVal; }
            //if (SerialPortFunctions.TryDiscardOutputBuffer(serialPort1) == false) { RetVal.ErrorCode = 2; RetVal.IsSuccess = false; return RetVal; }

            do
            {
                if (currentByte != 0x06)                                                      //only read another byte if you don't already have a packet header, I.E. you only read here the first time through the do loop
                {
                    if (serialPort1.BytesToRead != 0)                                         //Check to make sure there are bytes in the buffer
                    {
                        //System.Diagnostics.Debug.WriteLine("Timeout Counter: " + TimeOutCounter);
                        if (SerialPortFunctions.TryReadSerialPort(serialPort1, out currentByte) == false)
                        {
                            RetVal.IsSuccess = false;
                            RetVal.ErrorCode = 4;
                            return RetVal;
                        }
                    }
                    else 
                        TimeOutCounter++;

                    if (TimeOutCounter >= 60000) 
                    {
                        System.Diagnostics.Debug.WriteLine("Timeout Counter: " + TimeOutCounter + ", Bytes to Read: " + serialPort1.BytesToRead);
                        RetVal.ErrorCode = 3; 
                        RetVal.IsSuccess = false; 
                        return RetVal; 
                    }                    
                }

                if (currentByte == 0x06)                                                       //Initiate Low Duty Cycle command success | Packet header
                {
                    for (int k = 0; k < 72; k++)        //56 is the old number of bytes excl contact status
                    {
                        currentByte = Convert.ToByte(serialPort1.ReadByte());
                        streamPacket[k] = currentByte;
                    }

                    try
                    {
                        currentSpeed[0] = Convert.ToByte(streamPacket[7].ToString("X2"));
                        currentSpeed[1] = Convert.ToByte(streamPacket[8].ToString("X2"));
                        currentSpeed[2] = Convert.ToByte(streamPacket[9].ToString("X2"));
                        currentSpeed[3] = Convert.ToByte(streamPacket[10].ToString("X2"));
                        currentSpeed[4] = Convert.ToByte(streamPacket[11].ToString("X2"));
                        currentSpeed[5] = Convert.ToByte(streamPacket[12].ToString("X2"));
                        currentSpeed[6] = Convert.ToByte(streamPacket[13].ToString("X2"));
                        currentSpeed[7] = Convert.ToByte(streamPacket[14].ToString("X2"));

                        currentPulse[0] = Convert.ToByte(streamPacket[23].ToString("X2"));
                        //currentPulse[1] = Convert.ToByte(streamPacket[24].ToString("X2"));
                        currentPulse[1] = SerialMotorControl.ConvertToByte(streamPacket[24]);
                        currentPulse[2] = Convert.ToByte(streamPacket[25].ToString("X2"));
                        currentPulse[3] = Convert.ToByte(streamPacket[26].ToString("X2"));
                        currentPulse[4] = Convert.ToByte(streamPacket[27].ToString("X2"));
                        currentPulse[5] = Convert.ToByte(streamPacket[28].ToString("X2"));
                        currentPulse[6] = Convert.ToByte(streamPacket[29].ToString("X2"));
                        currentPulse[7] = Convert.ToByte(streamPacket[30].ToString("X2"));

                        currentTorque[0] = Convert.ToByte(streamPacket[39].ToString("X2"));
                        currentTorque[1] = Convert.ToByte(streamPacket[40].ToString("X2"));
                        currentTorque[2] = Convert.ToByte(streamPacket[41].ToString("X2"));
                        currentTorque[3] = Convert.ToByte(streamPacket[42].ToString("X2"));
                        currentTorque[4] = Convert.ToByte(streamPacket[43].ToString("X2"));
                        currentTorque[5] = Convert.ToByte(streamPacket[44].ToString("X2"));
                        currentTorque[6] = Convert.ToByte(streamPacket[45].ToString("X2"));
                        currentTorque[7] = Convert.ToByte(streamPacket[46].ToString("X2"));

                        currentContactStatus[7] = Convert.ToByte(streamPacket[62].ToString("X2"));
                    }
                    catch (FormatException e)
                    {
                        ReadSuccess = true;
                        FeedbackParams[0] = 0;
                        FeedbackParams[1] = 0;
                        FeedbackParams[2] = 0;
                        FeedbackParams[3] = 0;
                        RetVal.ErrorCode = 4; 
                        RetVal.IsSuccess = false; 
                        return RetVal;
                    }
                    finally
                    { 
                    
                    }

                    //StringBuilder sb = new StringBuilder();

                    foreach (byte byteval in currentSpeed)
                    {
                        Char charval = Convert.ToChar(Int32.Parse(byteval.ToString(), System.Globalization.NumberStyles.HexNumber));
                        sb.Append(Convert.ToString(charval));
                    }

                    FeedbackParams[0] = ConvertToInt32(sb);

                    sb.Clear();
                    foreach (byte byteval in currentPulse)
                    {
                        Char charval = Convert.ToChar(Int32.Parse(byteval.ToString(), System.Globalization.NumberStyles.HexNumber));
                        sb.Append(Convert.ToString(charval));
                    }
                    FeedbackParams[1] = ConvertToInt32(sb) - Convert.ToInt32((12000 * CalibrationSettings.Default.GearRatio) * (Math.Floor(ConvertToInt32(sb) / (12000 * CalibrationSettings.Default.GearRatio))));

                    sb.Clear();
                    foreach (byte byteval in currentTorque)
                    {
                        Char charval = Convert.ToChar(Int32.Parse(byteval.ToString(), System.Globalization.NumberStyles.HexNumber));
                        sb.Append(Convert.ToString(charval));
                    }
                    FeedbackParams[2] = -ConvertToInt32(sb);

                    sb.Clear();
                    Char charval1 = Convert.ToChar(Int32.Parse(currentContactStatus[7].ToString(), System.Globalization.NumberStyles.HexNumber));
                    sb.Append(Convert.ToString(charval1));
                    FeedbackParams[3] = ConvertToInt32(sb);

                    ReadSuccess = true;
                }
            } while (ReadSuccess == false);

            RetVal.IsSuccess = true;

            GlobalVariables.SerialPortBusyLeft = false;
            return RetVal;
        }
 public static bool WriteSeatActuatorByte(ObjectClasses.ISerialPortIo serialPort, char charVal)
 {
     byte[] charByte = new byte[] { Convert.ToByte(charVal) };
     return TransmitCommand(serialPort, charByte, 1);
 }
        public static bool TryOpenSerialPort(ObjectClasses.ISerialPortIo serialPort1, Label lblStatus)
        {
            try
            {
                serialPort1.Open();
                return true;
            }
            catch (System.IO.IOException e)
            {
                lblStatus.Text = serialPort1.PortName + " failed to open. Check cable connections and Port Settings.";
            }

            finally
            {
                
            }

            return false;
        }
        //This command only works for VP-Drives (Embedded Controller)
        public static bool SetMotorPosition(ObjectClasses.ISerialPortIo serialPort1, int PositionRefVal)
        {
            string HexString = PositionRefVal.ToString("X");
            Encoding ascii = Encoding.ASCII;
            byte[] asciiBytes = ascii.GetBytes(PositionRefVal.ToString());                  //Converts the string of ASCII characters to a byte array where each member is the decimal representation of the ASCII value

            byte[] RSSCommand = new byte[27];
            RSSCommand[0] = 0x05;               //ENQ Header
            RSSCommand[1] = 0x30;               //Station ID = 0;
            RSSCommand[2] = 0x30;               //Station ID = 0;
            RSSCommand[3] = 0x43;               //C
            RSSCommand[4] = 0x50;               //P
            RSSCommand[5] = 0x52;               //R
            RSSCommand[6] = 0x30;               //Direction
            RSSCommand[7] = 0x30;               //1
            RSSCommand[8] = 0x30;               //2
            RSSCommand[9] = 0x30;               //3
            RSSCommand[10] = 0x32;              //4
            RSSCommand[11] = 0x30;              //5
            RSSCommand[12] = 0x30;              //6
            RSSCommand[13] = 0x30;              //Speed - 1
            RSSCommand[14] = 0x35;              //2
            RSSCommand[15] = 0x30;              //3
            RSSCommand[16] = 0x30;              //4
            RSSCommand[17] = 0x30;              //5
            RSSCommand[18] = 0x32;              //Accel Time - 1
            RSSCommand[19] = 0x30;              //2
            RSSCommand[20] = 0x30;              //3
            RSSCommand[21] = 0x30;              //4
            RSSCommand[22] = 0x31;              //Decel Time - 1
            RSSCommand[23] = 0x30;              //2
            RSSCommand[24] = 0x30;              //3
            RSSCommand[25] = 0x30;              //4
            RSSCommand[26] = 0x04;              //EOT

            /*return*/ TransmitCommand(serialPort1, RSSCommand, 27);

            System.Threading.Thread.Sleep(100);

            while (serialPort1.BytesToRead != 0)
            {
                string text = Convert.ToString(serialPort1.ReadByte().ToString("X"));
                System.Diagnostics.Debug.WriteLine(Convert.ToString(text));
            }
            //serialPort1.Close();
            return true;
        }
        public static bool DisableDrive(ObjectClasses.ISerialPortIo serialPort1)
        {
            byte[] RSSCommand = new byte[19];
            RSSCommand[0] = 0x05;               //ENQ Header
            RSSCommand[1] = 0x30;               //Station ID = 0;
            RSSCommand[2] = 0x30;               //Station ID = 0;
            RSSCommand[3] = 0x57;               //W
            RSSCommand[4] = 0x53;               //S
            RSSCommand[5] = 0x53;               //S
            RSSCommand[6] = 0x30;               //Request 1 Block Q'ty
            RSSCommand[7] = 0x31;               //Request 1 Block Q'ty
            RSSCommand[8] = 0x30;               //Block Varibale Length is 6
            RSSCommand[9] = 0x36;               //Block Varibale Length is 6
            RSSCommand[10] = 0x25;              //%
            RSSCommand[11] = 0x4D;              //M
            RSSCommand[12] = 0x58;              //X - Request %MD Request Data Type is 32bit
            RSSCommand[13] = 0x35;              //5
            RSSCommand[14] = 0x31;              //1
            RSSCommand[15] = 0x32;              //2
            RSSCommand[16] = 0x30;              //00
            RSSCommand[17] = 0x30;              //00 - Servo Off
            RSSCommand[18] = 0x04;              //EOT

            return TransmitCommand(serialPort1, RSSCommand, 19);
        }
        public static bool SetSpeedCommand(ObjectClasses.ISerialPortIo serialPort1, int SpeedRefVal)
        {
            SpeedRefVal = SpeedRefVal * 10;
            string HexString = SpeedRefVal.ToString("X");
            Encoding ascii = Encoding.ASCII;
            byte[] asciiBytes = ascii.GetBytes(HexString);                  //Converts the string of ASCII characters to a byte array where each member is the decimal representation of the ASCII value

            byte[] RSSCommand = new byte[25];
            RSSCommand[0] = 0x05;               //ENQ Header
            RSSCommand[1] = 0x30;               //Station ID = 0;
            RSSCommand[2] = 0x30;               //Station ID = 0;
            RSSCommand[3] = 0x57;               //W
            RSSCommand[4] = 0x53;               //S
            RSSCommand[5] = 0x53;               //S
            RSSCommand[6] = 0x30;               //Request 1 Block Q'ty
            RSSCommand[7] = 0x31;               //Request 1 Block Q'ty
            RSSCommand[8] = 0x30;               //Block Varibale Length is 6
            RSSCommand[9] = 0x36;               //Block Varibale Length is 6
            RSSCommand[10] = 0x25;              //%
            RSSCommand[11] = 0x4D;              //M
            RSSCommand[12] = 0x44;              //D - Request %MD Request Data Type is 32bit
            RSSCommand[13] = 0x31;              //1
            RSSCommand[14] = 0x32;              //2
            RSSCommand[15] = 0x37;              //7
            RSSCommand[16] = 0x30;              //00
            RSSCommand[17] = 0x30;              //00
            RSSCommand[18] = 0x30;              //00
            RSSCommand[19] = 0x30;              //00
            RSSCommand[20] = 0x30;              //00
            RSSCommand[21] = 0x30;              //00
            RSSCommand[22] = 0x30;              //00
            RSSCommand[23] = 0x30;              //00
            RSSCommand[24] = 0x04;              //EOT

            for (int ii = 0; ii < asciiBytes.Length; ii++)
            {
                RSSCommand[23 - ii] = asciiBytes[asciiBytes.Length - 1 - ii];
            }

            return TransmitCommand(serialPort1, RSSCommand, 25);
        }
        public static bool TryDiscardInputBuffer(ObjectClasses.ISerialPortIo serialPort1)
        { 
            if (serialPort1.IsOpen == true)
            {
                try
                {
                    serialPort1.DiscardInBuffer();
                    return true;
                }
                catch (System.IO.IOException)
                {
                    DataComms.CreateThreadInstance("TryDiscardInputBuffer - IOException");
                }
                catch (System.InvalidOperationException)
                {
                    DataComms.CreateThreadInstance("TryDiscardInputBuffer - InvalidOperation");
                }
                catch (UnauthorizedAccessException)
                {
                    DataComms.CreateThreadInstance("TryDiscardInputBuffer - UnauthorizedAccessException");
                }

                finally
                {

                }

                return false;
            }
            else
            {
                return false;
            }
        }
        //StopSequence - Move to DataSample?
        private void StopMotor(ObjectClasses.ISerialPortIo serialPort)
        {
            if (GlobalVariables.leftSerialPort.IsOpen == true)        //This function must be moved to the servocontroller
            {
                if (GlobalVariables.ServoController.TryStopMotor(serialPort).IsSuccess == false)
                    return;

                //Set Motor Torque Forward
                if (SerialMotorControl.WriteSingleRegister(166, (UInt16)100, serialPort) == false)
                    return;

                //Set Motor Torque Reverse
                if (SerialMotorControl.WriteSingleRegister(168, (UInt16)100, serialPort) == false)
                    return;
            }
        }
        //StopSequence - Move to DataSample?
        private void StopMotor(ObjectClasses.ISerialPortIo serialPort)
        {
            if (GlobalVariables.leftSerialPort.IsOpen == true)        //This function must be moved to the servocontroller
            {
                if (GlobalVariables.ServoController.TryStopMotor(serialPort).IsSuccess == false)
                    return;

                //Calculate Reference Torque value (in Percentage)
                double targetTorque = CalibrationSettings.Default.MaxAllowableForce * CalibrationSettings.Default.SprocketRadius;
                int torqueRefVal = GlobalFunctions.ConvertToTorqueRefVal(targetTorque);

                //SetMotorTorque blocks the thread, so we are not using it for now
                //Set Motor Torque Forward
                if (SerialMotorControl.WriteSingleRegister(166, (UInt16)torqueRefVal, serialPort) == false)
                    return;

                //Set Motor Torque Reverse
                if (SerialMotorControl.WriteSingleRegister(168, (UInt16)torqueRefVal, serialPort) == false)
                    return;
            }
        }
 //Constructor
 public objDataSample(ObjectClasses.ISerialPortIo SerialPort)
 {
     serialPort = SerialPort;
 }
        //Constructor
        public EcceScrumDS(ObjectClasses.ISerialPortIo SerialPort)
            : base(SerialPort)
        {

        }
        public static bool EnableFeedback(ObjectClasses.ISerialPortIo serialPort1)
        {
            byte[] RCBCommand = new byte[15];
            RCBCommand[0] = 0x05;               //ENQ Header
            RCBCommand[1] = 0x30;               //Station ID = 0;
            RCBCommand[2] = 0x30;               //Station ID = 0;
            RCBCommand[3] = 0x52;               //R
            RCBCommand[4] = 0x43;               //C
            RCBCommand[5] = 0x42;               //B
            RCBCommand[6] = 0x31;               //1 - > Read Current Speed + Command Speed
            RCBCommand[7] = 0x31;               //1 - > Read Current Pulse + Command Pulse
            RCBCommand[8] = 0x31;               //1 - > Read Current Load + Command Load
            RCBCommand[9] = 0x31;               //1 - > Read Contact Status + DC Voltage
            RCBCommand[10] = 0x30;              //0 - > Don't Read
            RCBCommand[11] = 0x30;              //0 - > Don't Read
            RCBCommand[12] = 0x30;              //0 - > Don't Read
            RCBCommand[13] = 0x30;              //0 - > Don't Read
            RCBCommand[14] = 0x04;              //1

            return TransmitCommand(serialPort1, RCBCommand, 15);
        }
Example #31
0
        //Performance Variables

        public MvcDS(ObjectClasses.ISerialPortIo SerialPort) : base(SerialPort)
        {

        }
        public WeighYourselfDS(ObjectClasses.ISerialPortIo SerialPort) : base(SerialPort)
        {

        }
        //Performance Variables

        public StaticStrengthTestDS(ObjectClasses.ISerialPortIo SerialPort) : base(SerialPort)
        {

        }
        public static bool TryStopMotor(ObjectClasses.ISerialPortIo serialPort1, Label lblStatus)
        {
            byte[] RSSCommand = new byte[25];
            RSSCommand[0] = 0x05;               //ENQ Header
            RSSCommand[1] = 0x30;               //Station ID = 0;
            RSSCommand[2] = 0x30;               //Station ID = 0;
            RSSCommand[3] = 0x43;               //W
            RSSCommand[4] = 0x4A;               //S
            RSSCommand[5] = 0x52;               //S
            RSSCommand[6] = 0x30;               //Request 1 Block Q'ty
            RSSCommand[7] = 0x30;               //Request 1 Block Q'ty
            RSSCommand[8] = 0x30;               //Block Varibale Length is 6
            RSSCommand[9] = 0x30;               //Block Varibale Length is 6
            RSSCommand[10] = 0x30;              //%
            RSSCommand[11] = 0x30;              //M
            RSSCommand[12] = 0x30;              //X - Request %MD Request Data Type is 32bit
            RSSCommand[13] = 0x36;              //5
            RSSCommand[14] = 0x30;              //1
            RSSCommand[15] = 0x30;              //2
            RSSCommand[16] = 0x30;              //00
            RSSCommand[17] = 0x36;              //00 - Servo Off
            RSSCommand[18] = 0x30;              //EOT
            RSSCommand[19] = 0x30;              //5
            RSSCommand[20] = 0x39;              //1
            RSSCommand[21] = 0x39;              //2
            RSSCommand[22] = 0x39;              //00
            RSSCommand[23] = 0x39;              //00 - Servo Off
            RSSCommand[24] = 0x04;              //EOT

            return TransmitCommand(serialPort1, RSSCommand, 25);

            //System.Threading.Thread.Sleep(100);
        }
 //Constructor
 public SpinShaperDS(ObjectClasses.ISerialPortIo SerialPort) : base(SerialPort)
 {
     spinShaperData = new Classes.SpinShaperData();
 }
 public ThreadOpenSerialPort(ObjectClasses.ISerialPortIo SerialPort, string Source)
 {
     f_SerialPort = SerialPort;
     f_Source = Source;
 }