Wednesday, December 12, 2012

MPLAB X IDE So Slow and takes for EVER

Anyone can help with this would be great.  It was working fine for ever, then suddenly it started to take forever when I connect to the board to download FW or edit project settings.

I now I installed some Java for Android development recently and this is about the time it started to do this...
What part is causing this I am not sure yet...


Some of the things I did so far and did not work:

  1. I changed the path to  jdkhome=""  in the following file  "C:\Program Files (x86)\Microchip\MPLABX\mplab_ide\etc\mplab_ide.conf"
  2. I also, added the switch to the start-up icon "C:\Program Files (x86)\Microchip\MPLABX\mplab_ide\bin\mplab_ide.exe" --jdkhome "C:\Program Files (x86)\Microchip\MPLABX\sys\java\jre1.6.0_32-windows-x64\java-windows"




This is not good, it is killing me, I can not do any development like this...

Updates: 12/13/2012:
It was something with my Bluetooth.  I started working on Bluetooth around the same time when MPLAB started acting this way.  So, I thought to disconnect my BT dongle, and walla, MPLAB working just fine!!  Something was going on between BT dongle and MPLAB.  I will have to find out!

Monday, December 10, 2012

Configure Eclipse to Auto-Save before Executing App

So, if you develop using  Eclipse, you must know how you have to save your modules every time you click on run.  So, it is an extra click every time.  Usually in most other IDEs you would not have to do this, because they have an option to auto-save your modified documents.

I know there was an option in Eclipse too, and I used it before but, I forgot how to do that and it took me a while to find it again.
so, here it is, a note to my self and to others who need to know how...

Click on Window -> Preferences
Select General from the list on the left
Expand it and click on Workspace
In the right side make sure the "Save automatically before build" is checked



Now Select Run/Debug from the list on the left
and Expand it to Select Launching
In the right side find and make sure "Save required dirty editors before launching" is Always



Click OK and you are set to go.



Tuesday, December 4, 2012

Do you get this message: "javadoc java platform manager"

If you are using NetBeans and writing Java applications, you try to get some information on functions or properties details and you get this message, "javadoc java platform manager". Then you most likely missing some Documentation from Java JDK.




Try and delete this folder first after backing it up some where:
/home/elsaghir/.netbeans/7.0/var/cache

Here is what you need to add:
sudo aptitude install openjdk-6-jdk
sudo aptitude install openjdk-6-doc

replace the number 6 with the latest revision of java at this time...
you should see new data and folders in this folder 
/usr/lib/jvm/default-java/docs

How to: Retrieve Time in C++ OR Calculate Elapsed Time


Here are few different methods to retrieve time in C++ depends on your requirements

I always need to retrieve time information one way or anther to use in my code. so I decided to create this Knol to keep/list all methods and related information for everyone so we can retrieve this easier in the future!




/*
The Goal of this project is to be a reference to all Date and time stuff
Author: Hesham Elsaghir
Date: 10/13/2010
*/
#include"stdafx.h"#include "iostream"#include "time.h"#include "atltime.h"
using namespace std;

int  _tmain(int argc, _TCHAR* argv[])
{
SYSTEMTIME st;
FILETIME ft;

unsigned short File_Time_Date;
unsigned short File_Time_Time; // time and date in numbers format...

GetLocalTime(&st);

SystemTimeToFileTime(&st, &ft);
cout << "Today's Day # is: " << st.wDay << endl;
cout << "Today's Month # is: " << st.wMonth << endl;
cout << "Today's Year is: " << st.wYear << endl;
// This function will convert the time and date to Dos Date and Time format
FileTimeToDosDateTime(&ft, &(File_Time_Date), &(File_Time_Time));
cout << "Time now in File time is: " << File_Time_Time << endl;
cout << "Time now in File Date is: " << File_Time_Date << endl;
// This is a different method to obtain Date and Time
struct tm now;
time_t time_now;
time(&time_now);
now = *localtime(&time_now); 
/* Get time and date structure */mktime(&now);
cout << "Time now is: " << now.tm_mon << now.tm_mday << now.tm_year << endl;cout << "Ctime format to time: " << ctime(&time_now) << endl;

long time_taken = clock();
printf(
"%ld\n", time_taken);
printf("%d\n", CLOCKS_PER_SEC);
// How to use sscanf() to int day, month, year;
char test[] = "10/3/2010";
sscanf(test, "%d/%d/%d", &day, &month, &year);
printf(
"day: %02d\n",day);
printf(
"moth: %02d\n",month);
printf(
"year: %04d\n",year);
// Here is a way to print local and Gtime "UTC"struct tm *local;
time_t t;
t = time(NULL);
local = localtime(&t);
printf(
"Local time and date: %s\n", asctime(local));
local = gmtime(&t);
printf(
"UTC time and date: %s\n", asctime(local));

// Using sprintf to write a formated string into an array
GetLocalTime(&st);
char temp_mdy[50];
sprintf(temp_mdy, "    @date       %02d/%02d/%04d\n",st.wMonth,st.wDay, st.wYear);

cout << temp_mdy << endl;


// Different methods to capture time elapsed
long st_time = clock();
// do some work here
Sleep(500);             // sleep 500 milliseconds
long sp_time = clock();
printf("Time Elapsed is: %ld Millisecond\n", sp_time - st_time);
// Or you can use this
time_t time_1, time_2;
time(&time_1);
Sleep(10000);                 // sleep 10 seconds
time(&time_2);
printf("Time Elapsed is: %.2lf seconds\n", difftime(time_2,time_1));


return
 0;
}

Here is the output of the program:
 



I will be adding more futures to cover C# later.

References:
http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/

How to convert a Structure to byte array

So many times we need to use a structure to hold and organize some data. Then later we will need to send this structure to a client or another system via serial or ethernet. C# is not a very cast friendly! so you can't just cast the structure to a byte array like you can do in C or C++.





I have this strucure for example.
struct str_packet
{
    byte           key;
    byte    []    offset;
    byte          length;
    byte    []    data;
    short         Check_Sum;
};
 
 
 
 
 /*
    This Function will return a Byte Array that contains the data in the structure
*/ 
static byte [] StructureToByteArray(object obj)

{
    int len = Marshal.SizeOf(obj);
    byte [] arr = new byte[len];
    IntPtr ptr = Marshal.AllocHGlobal(len);
    Marshal.StructureToPtr(obj, ptr, true);
    Marshal.Copy(ptr, arr, 0, len);
    Marshal.FreeHGlobal(ptr);
    return arr;
}
/*
This Function will set a pointer to the new data extracted from the Byte Array
*/
static void ByteArrayToStructure(byte [] bytearray, ref object obj)
{
    int len = Marshal.SizeOf(obj);
    IntPtr i = Marshal.AllocHGlobal(len);
    
    Marshal.Copy(bytearray,0, i,len);
    obj = Marshal.PtrToStructure(i, obj.GetType());
    Marshal.FreeHGlobal(i);
}

Useful Linux Console Commands and tricks

Every day I learn a new command or trick and then if I do not use again or I need it later I search for it again and spend a lot of time on that. So, I know the best efficient way to track knowledge we learned is by writing it.


List of Commands I find while I am working and I hope this will help me later and you too!



"dmesg"'  Print or Control the Kernel ring buffer
That is to print the bootup messages.  and you can direct the output messages to a file by using 
dmesg ? boot.messages
Then use a text editor to view that output
You can also use
dmesg | grep sometext
where some text is any text you searching for in the output of dmesg.  so if you searching for tty occurrence in booting up process you need to type   dmesg | grep tty

who  will list all users logged in to the same


cat  >  file_name.txt   Will create the file name and allow you to enter text and save it

which find out what a command path is.
for example, use
which adduser  -->  the return should be /bin/adduser
or
which passwd   -->  the return should be /usr/bin/passwd


passwd  to change your password or another user password


nano is a great editor if you have a basic linux console and do not have the GUI

tar     un-tar a compressed file
use tar xvjf \path_to_file_with_ext_.tar.bz2
use tar -zxvf \path_to_file_with_ext_.tgz



Some Good References:
https://help.ubuntu.com/community/UsingTheTerminal

Using GNU Octave to solve symbolic Equations


GiNaC is the Symbolic package for GNU Octave


I have been trying to move completely to use GNU Octave instead of using Matlab.  Matlab is a high-level programming language for working with matrices and is very widely used now by Engineers and other fields for calculations and analyses.  The issue is Matlab is very expensive package to own and not everyone can install it on his/her personal computer.  Moreover, now that I use Ubuntu Linux as my main OS, Hello to the Free world and goodbye to other OS ties and limitations, I can not run Matlab anyway on Ubuntu.
So, I use GNU Octave to perform all my calculations and code algorithms I need.  I just realized that I need to do some symbolic calculations and I know what I need to do that in Matlab
    syms x
or
    x =  
sym("x")
and that is enough for what I need.  I come to find out that it does not work for GNU Octave.  So, to make the long story short , here is what you need to do to get that working
when installing GNU Octave I used this command
    sudo apt-get install octave3.2 octave3.2-common octave3.2-doc octave3.2-dbg
This will install all what you need to install Octave.  but you still missing one package
    sudo apt-get install octave-symbolic
This is the package that contains GiNaC support for symbolics.

Here is a simple example to show you how to use it in GNU Octave:

% This is an example to show you how to calculate total value to two resistors in parallel
octave-3.2.3:1> symbols        % Initialize symbolic manipulation
octave-3.2.3:2> R1 = sym("r1")
R1 =

r1
octave-3.2.3:3> R2 = sym("r2")
R2 =

r2
octave-3.2.3:13> Z = (R1 * R2)/(R1 + R2)
Z =

(r2+r1)^(-1)*r2*r1
octave-3.2.3:14> subs(Z, {R1, R2}, {10,10})  % substitute the R1, R2 values with 10 Ohms each
ans =

5.0

Please, Leave me comments or opinions about what you think, Thanks,

How to configure your iPhone to work with Gmail


Using your Gmail Email, Contacts, and Calendar on your iPhone

Well, with the new iPhone OS 4 you can link your email application on your iPhone to your Google account resources. If you make use of Google Email "Gmail", Google contacts, and Google calendar, now you have access to all three resources from you iPhone. But, you need to configure your phone first.




To start you need to know that you can not have more than one exchange account configured on your iPhone.  What that means?  Well, we are going to connect to your Google account via Microsoft Exchange tool on your iPhone, and it can only be configured to use one account.  So, we can only have one account of this type.
Steps to configure your Google account:
  1. Go to your iPhone and tap Settings
  2. In Settings find "Mail, Contacts, Calendars" and tap it
  3. Find "Add Account..." at the bottom of the Accounts Section and tap it
  4. You will see the following screen capture


  5. Tap "Microsoft Exchange" to Configure it
  6. You will need to enter the following items as shown in the following screen capture:
    1. Your Google email account address
    2. Server name: n.google.com
    3. Domain: Leave blank
    4. User name: Enter your Google email address again
    5. Password: Enter your Google Email account password
    6. Description: A Description will be filled for you, you can change it if you want
    7. Use SSL:  Make sure it is ON
    8. Once you are done, confirm your settings and you should get a screen asking to choose what services you want to enable Mail, Contacts, and Calendar
      1. .
    9. You are done, you should be able to access all your Google resources from your iPhone.

More details to be added...
 



 
 
Links to Web sites:

Concerns About Button Layout in Ubuntu Lucid

I am used to see my close, minimize and maximize buttons on the top right side of my windows, so when I go to change the window state I always hid to the that top right corner, but nothing is there any more. Do you want to know how to bring them back HOME?



As simple as follow:
  • run a command by going to a Terminal Window or Alt+F2
  • Type gconf-editor
  • You will see the Configuration Editor Screen shown below
  • Look for /apps/metacity/general/button_layout
  • You should see something like close, minimize, maximize:
  • All you need to do is move the colon : from the end of the line to the beginning of the line and press Enter
  • VOILA!, that is all about it
  • You can explore more in Configuration Editor to learn about what other option you can control "Only if you are comfortable with that"




Warring, Changes will take effect Immediately, if you do not know what you just changed you could experience system miss-functioning.  Do it at your own risk.

All About Ubuntu Network Configuration


The Console Commands

Have you ever wondered what is the equivalent to ipconfig /renew /release in Ubuntu Linux? I collected all the information I thought about related to Ubuntu Network in this Knol. If you have any other questions or suggestions, please, let me know.



So, to start, here is the common question.
1)  How can I start restart my network?
Well, in Ubuntu you can bring the network down and up using these commands
ifup, ifdown you will need to supply the network interface you trying to restart so,
 
Restart Network Interface #0 Restart Network Interface #1
ifdown eth0
ifup eth0
 ifdown eth1
ifup eth1
Also, you can use one of the following commands to start. stop, or restart the networksudo /etc/init.d/networking start
sudo /etc/init.d/networking stop
sudo /etc/init.d/networking restart

How would you know what is the ethx number for your N
etwork Interface?
  you can type
ip addr show OR
sudo ifconfig -a
this command will display all your network interfaces with their information.  Usually you will have lo and eth0 or eth1.  The lo is your loopback interface and always has the IP Address 127.0.0.1 and a MAC address of 00:00:00:00:00:00
 
.  However, the other Network interface will have the label link/ether and that is what you need to work with.
There is also ifconfig which will give you more information on your network and still will sort the information by Network interface lo and eth0.  If you are not interrested in lo network interface as I do most of the time, you can type  ifconfig eth0  so you do not have to see the other interfacce information.
 
2)  The next question is, how can I configure my network to use a proxy?
Well, Ubuntu looks for a file in /etc/apt with the name apt.conf  so you need to create this file if it does not exist.  and if it does, you can edit it with root access using the program nano, which is a very nice simple editor.
you will need to enter the following line
 Acquire::gttp::proxy "http://xyz.xyz.zyx:portnumber";
for example this is a link to proxy with URL, http://www.google.com and uses port number 3456.
 
 Acquire::gttp::proxy "http://www.google.com:3456";
 
 3) How to connect/map a network share on my Ubuntu session?
This done by using the command smbclient.  Make sure smbclient is installed on your system first.  All you need to do is type smbclient and if you get an error not found, then just install it.
sudo apt-get install smbclient
Then you can type  smbclient //server/name/share -U username
You will be prompt for a your password on this server and a prompt like this
smb: \>
Now you can start typing your commands or Type  ?  for command list.
 
There is also, sudo mount -t cifs  that will give you the option to map to a network share.
 
 
More to be added,
 
 
 
References:

Install AVR32 Studio and GNU on my Ubuntu 10.04 Lucid


As Usual, I like to update my Ubuntu with the latest release even if it is still in beta stage. But there is a price to pay. When I wanted to install AVR32 Studio and GNU it did not work and returned an error that there are few libraries missing. Here is what I did to get it to work.


Install the following items in this order:
To get the library packages in blue, you will need to visit Ubuntu Package site and download them.  Make sure you download the correct version number for the package.
Avr32-binutilsAvr32-gcc-newlib
Avr32-gdbAvr32-buildroot-essentials           need network connection
 
Libboost-system1.38                  karmicLibboost-filesystem1.38              Karmic
Libboost-thread1.38                    KarmicLibboost-filesystem1.34.1           Karmic
Libboost-thread1.34.1                 Karmic
Libavrtools_                               GNUAvr32parts
Libavr32ocdLibavr32sim
LibelfdwarfparserAvr32trace
Avr32programAvr32headers
 
Libboost-date-time1.34.1         Karmic 
Avr32gdbproxy
Avrfwupgrade
Avr32-gnu-toolchain


Java stuff:   you will need to install Eclipse or just install Openjre.....
I have to add more details here

How to Add Folder Browser Dialog Option to Your C# CSharp Program


I am writting these programs in C# "C Sharp" and always needed to give the user the option to select a folder.  Well, this should not be a segnificant task.  Dialog folders are always been provided by the toolbox in Visual Studio, Open, Save, Print, Font, etc...  so the Folder Browser should not be an issue.  So, I spent all day looking for a way to give the user the option to select a folder in my program.  search all over the internet and all blogs.  found a lot of feed back, but wow, that was so much to do to add this little option to my program.   So finally I look in my toolbox components and I saw it.  the Folderbrowserdialog component.  it is there!!!
 
all you have to do is add this to a button click: 
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
Selected_Folder_Button.Text = folderBrowserDialog1.SelectedPath;
}
I can not believe all that talk out there on the internet and complecated feed back, this is two lines of code!!!!

Installing VirtualBox Guest Additions on Debian


Step-by-Step procedure

I use Vbox a lot with my research, development, and testing with linux Ubuntu. I installed the guest additions no problem just by running the VBoxLinuxAdditions-x86.run. I happed to need Debian as one of my VirtualBox images to do some testing with it. I like to have the guest additions installed as it makes life much easier to switch between the host computer and the guest window. chocking I could not, no matter what, get that guest additions to install. After a lot of research and reading here is what I had to do to get it installed.

The following process is done on the Guest OS not the Host OS.
  1. Start a terminal and su to root.  working with sudo will not help at this time
  2. Update your system APT database by using apt-get update then apt-get upgrade
  3. Also make sure you do aptitude update then aptitude upgrade
  4. Run the apt-get upgrade  to install the latest security needed for your system 
  5. Install the required packages for the guest additions by running
    • apt-get install build-essential module-assistant
  6. Run m-a prepare   to configure your system for building kernel modules.  without this the guest additions will fail and ask you to "please install the build and header files for your current kernel"
  7. Now click on install guest additions from the top menu in the sun VirtualBox under Devices.  This should add a new CD Media to your Debian system and a window will open showing all the Guest Additions shell files for different system
  8. If the system did not mount the CD-Rom image for you use this command
    • mount /media/cdrom0
  9. Run the shell file VBoxLinuxAdditions-x86.run to start the installations
  10. Replace the shell file name with the proper file that matches your system
 
 
Enjoy.

User is not in the sudoers file. How to add the user to the sudoers file?

I installed Debian few times on my systems and evey time I start using it I find out that the sudo command does not work with my user account.  I am a big fan of Ubuntu and I am used to it as I used for the last few years and I think the sudo command always worked for me out of the box.  so here is how you get the sudo command to work.
First:  all you need to do is add the following line to the sudoers file in /etc/sudoers
user_name   ALL=(ALL) ALL
Replace user_name with your own user ID
however, you have to use the visudo command to edit the file while being root
so, here is what you need to do:
open a new terminal
switch to root, type "su" then enter the root password
type "visudo" and you will see the sudoers file opened for editting
go to the end of the file and type the line
user_name  ALL=(ALL) ALL
Again, Make sure you replace user_name with your own user ID
then hold the CTRL key and press "o" to save the file and confirm by pressing enter
now hold CTRL key and press "x" to exit the program
type "exit" to exit root mood
then now type sudo gedit and enter your password
if everything went well, you should see the gedit program
you are done,
Enjoy,


Update:  How to add a user to Sudoers account in Ubuntu?
I found out that if you create a new account using "adduser" you do not get the sudoers group by default
so,
  1. Open a terminal using another account such as root or main account
  2. type "sudo nano /etc/sudoers"
  3. Go to the end of the file and type the following
    1. user_name ALL=(ALL)ALL
    2. Replace user_name with your new user name
    3. Save the file and exit "Ctrl x" when asked type y and press Enter to confirm the file name
  4. now log out and login using that user_name and you should have the sudo command working
I tested this process on an embedded Debian system, works great.