Exemple #1
0
        // Menu
        private void openDatabaseToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FileDialog dlg;

            if (sender == createDatabaseToolStripMenuItem)
            {
                SaveFileDialog dlgsave = new SaveFileDialog();
                dlgsave.CreatePrompt = true;
                dlg = dlgsave;
            }
            else
            {
                dlg = new OpenFileDialog();
            }

            dlg.FileName = Properties.Settings.Default.DatabaseFile;
            dlg.Filter   = "sdf|*.sdf";
            if (dlg.ShowDialog(this) != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }
            if (File.Exists(dlg.FileName) || (sender == createDatabaseToolStripMenuItem))
            {
                DeviceDescrProvider.CreateDatabase(dlg.FileName);
                Properties.Settings.Default.DatabaseFile = dlg.FileName;
            }
        }
Exemple #2
0
        // Menu
        private void addSalveToDatabaseToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter = "xml|*.xml";
            if (dlg.ShowDialog(this) != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }
            string ret = DeviceDescrProvider.AddDeviceDescr(Properties.Settings.Default.DatabaseFile, dlg.FileName);

            if (ret == "Done")
            {
                MessageBox.Show(ret, "EtherCATExplorer", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show(ret, "EtherCATExplorer", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public static List <PDODictionaryEntry> GetDictionary(String DatabaseName, EthCATDevice slave)
        {
            string connectionString = "Data Source=" + DatabaseName;

            System.Data.SqlServerCe.SqlCeConnection con = new System.Data.SqlServerCe.SqlCeConnection(connectionString);
            try
            {
                con.Open();

                int databaseid = DeviceDescrProvider.GetSlaveDatabaseId(con, slave._ManufacturerId, slave._TypeId, slave.Revision);
                if (databaseid == -1)
                {
                    return(null);
                }

                List <PDODictionaryEntry> ret = new List <PDODictionaryEntry>();

                string          command = "SELECT * FROM PDO_Dictionary WHERE SlaveId=" + databaseid.ToString();
                SqlCeCommand    cmd     = new SqlCeCommand(command, con);
                SqlCeDataReader reader  = cmd.ExecuteReader();

                while (reader.Read())
                {
                    string FinalType = GetFinalType(con, databaseid, (string)reader[4]);
                    // At this level RW is unknow (not in the XML file)
                    PDODictionaryEntry e = new PDODictionaryEntry(Convert.ToInt32(reader[1]), Convert.ToUInt32(reader[2]),
                                                                  (string)reader[3], FinalType, PDOAccessLevel.Unknow);
                    ret.Add(e);
                    e.AddSubIndexData(con, databaseid);
                }
                con.Close();

                return(ret);
            }
            catch
            {
                Trace.WriteLine("Database content Error");
            }

            return(null);
        }