Thursday, May 22, 2014

Install Hyper-V Server 2012 in VM VirtualBox

Problem
When try to install Hyper-V Server 2012 will get the error as below

Your PC needs to restart.
Please hold down the power button.
Error code: 0x000000C4
Parameters:
0×0000000000000091
...

Solution

  1. Go to command prompt by click START, type cmd.
  2. Find your virtual machine name that want to install Hyper-V server, to list down all existing virtual machine,type "c:\Program Files\Oracle\VirtualBox\VBoxManage.exe" list vms
  3. After found the VM name, type this command: "c:\Program Files\Oracle\VirtualBox\VBoxManage.exe" setextradata [your vmname] VBoxInternal/CPUM/CMPXCHG16B 1
  4. Done.
For more info pls refer http://en.wikipedia.org/wiki/X86-64

Tuesday, April 1, 2014

Chromecast connection to Unifi

To connect Google Chromecast to unifi internet:-


  1. Go to router setting, 192.168.0.1,TM Unifi router default username and password as below:
    • Username: operator
    • Password: h566UniFi
  2. Go to Advance -> Advance Network. 
  3. Check "Enable Multicast Streams"

Monday, March 10, 2014

NO USB Debugging Mode in Android 4.2


  1. Open Setting, go to About Device
  2. Tap the Build Number 7 times
  3. Developer Options menu will appear

Thursday, March 8, 2012

Pelco P and D protocol implementation in C#

PTZ camera have many type of protocol such as Samsumg-T, Pelco-P, Pelco-D, Bosch, Honeywell, Vicon, Ad, Samsung-E, Panasonic to supports commands. This is a full C# classes to control a PTZ cameras via RS422/485 Pelco 'P' and 'D' protocol.

Pelco-P
/*-------------------------------------------------------------------------------
* Author: Tamir Khason, 2004
* Email: tamir@khason.biz
* Web: http://www.dotnet.us/
*
* Freeware: Please do not remove this header
*
* File: P.cs
*
* Description: PELCO P Protocol Implementation dot.NET Way
* This is GPL software. Do with it as you want, but feed us back any improvements.
*
* This is a simple class to control a PELCO PTZ camera via RS422/485
* 'P' protocol. It supports all of the commands including UP, DOWN, IN, OUT, LEFT,
* RIGHT, NEAR, FAR, as well as all other extended commands.
*
* To use this, you need to put a RS232->RS422 adapter on the output
* of your desired serial port.
*
* The Pelco doesn't return ANY usefull info back, so you only really need 2-wire support
* (one way) communications out.
*
*
* Version: 1.4
* ------------------------------------------------------------------------------*/
using System;
using System.Collections;

//namespace Pelco
//{
///
/// dot.NET Implementation of Pelco P Protocol
///

public class P //: Pelco
{
private const byte STX = 0xA0;
private const byte ETX = 0xAF;

#region Pan and Tilt Commands
#region Data1
private const byte FocusFar = 0x01;
private const byte FocusNear = 0x02;
private const byte IrisOpen = 0x04;
private const byte IrisClose = 0x08;
private const byte CameraOnOff = 0x10;
private const byte AutoscanOn = 0x20;
private const byte CameraOn = 0x40;
#endregion

#region Data2
private const byte PanRight = 0x02;
private const byte PanLeft = 0x04;
private const byte TiltUp = 0x08;
private const byte TiltDown = 0x10;
private const byte ZoomTele = 0x20;
private const byte ZoomWide = 0x40;
#endregion

#region Data3
private const byte PanSpeedMin = 0x00;
private const byte PanSpeedMax = 0x40;
#endregion

#region Data4
private const byte TiltSpeedMin = 0x00;
private const byte TiltSpeedMax = 0x3F;
#endregion
#endregion

#region Enums
public enum PresetAction {Set,Clear,Goto}
public enum PatternAction {Start,Stop,Run}
public enum Action {Start,Stop}
public enum LensSpeed {Low=0x00,Medium=0x01,High=0x02,Turbo=0x03}
public enum Pan {Left = PanLeft,Right = PanRight}
public enum Tilt {Up = TiltUp,Down = TiltDown}
public enum Iris {Open = IrisOpen,Close = IrisClose}
public enum Zoom {Wide = ZoomWide,Tele = ZoomTele}
public enum Switch {On,Off}
public enum Focus {Near = FocusNear,Far = FocusFar}
#endregion

#region Extended Command Set
public byte[] Preset(uint deviceAddress, byte preset, PresetAction action)
{
byte m_action;
switch (action)
{
case PresetAction.Set:
m_action = 0x03;
break;
case PresetAction.Clear:
m_action = 0x05;
break;
case PresetAction.Goto:
m_action = 0x07;
break;
default:
m_action = 0x03;
break;
}
return Message.GetMessage(deviceAddress,0x00,m_action,0x00,preset);
}

public byte[] Flip(uint deviceAddress)
{
return Message.GetMessage(deviceAddress,0x00,0x07,0x00,0x21);
}

public byte[] ZeroPanPosition(uint deviceAddress)
{
return Message.GetMessage(deviceAddress,0x00,0x07,0x00,0x22);
}

public byte[] AutoScan(uint deviceAddress, Action action)
{
byte m_action;
if(action == Action.Start)
m_action = 0x09;
else
m_action = 0x0B;
return Message.GetMessage(deviceAddress,0x00,m_action,0x00,0x00);
}

public byte[] RemoteReset(uint deviceAddress)
{
return Message.GetMessage(deviceAddress,0x00,0x0F,0x00,0x00);
}

public byte[] Zone(uint deviceAddress,byte zone, Action action)
{
if(zone<0x01 & zone>0x08)
throw new Exception("Zone value should be between 0x01 and 0x08 include");
byte m_action;
if(action == Action.Start)
m_action = 0x11;
else
m_action = 0x13;

return Message.GetMessage(deviceAddress,0x00,m_action,0x00,zone);
}



public byte[] WriteToScreen(uint deviceAddress,string text)
{
if(text.Length > 40)
text = text.Remove(40,text.Length-40);
System.Text.Encoding encoding = System.Text.Encoding.ASCII;
byte[] m_bytes = new byte[encoding.GetByteCount(text)*8];
int i = 0;
byte m_scrPosition;
byte m_ASCIIchr;

foreach(char ch in text)
{
m_scrPosition = Convert.ToByte(i/8);
m_ASCIIchr = Convert.ToByte(ch);
Array.Copy(Message.GetMessage(deviceAddress,0x00,0x15,m_scrPosition,m_ASCIIchr),0,m_bytes,i,8);
i = i + 8;
}

return m_bytes;
}

public byte[] ClearScreen(uint deviceAddress)
{
return Message.GetMessage(deviceAddress,0x00,0x17,0x00,0x00);
}

public byte[] AlarmAcknowledge(uint deviceAddress, uint alarmID)
{
if(alarmID < 1 & alarmID>8)
throw new Exception("Only 8 alarms allowed for Pelco P implementation");
return Message.GetMessage(deviceAddress,0x00,0x19,0x00,Convert.ToByte(alarmID));
}

public byte[] ZoneScan(uint deviceAddress,Action action)
{
byte m_action;
if(action == Action.Start)
m_action = 0x1B;
else
m_action = 0x1D;
return Message.GetMessage(deviceAddress,0x00,m_action,0x00,0x00);
}

public byte[] Pattern(uint deviceAddress,PatternAction action)
{
byte m_action;
switch (action)
{
case PatternAction.Start:
m_action = 0x1F;
break;
case PatternAction.Stop:
m_action = 0x21;
break;
case PatternAction.Run:
m_action = 0x23;
break;
default:
m_action = 0x23;
break;
}
return Message.GetMessage(deviceAddress,0x00,m_action,0x00,0x00);
}

public byte[] SetZoomLensSpeed(uint deviceAddress, LensSpeed speed)
{
return Message.GetMessage(deviceAddress,0x00,0x25,0x00,(byte)speed);
}

public byte[] SetFocusLensSpeed(uint deviceAddress, LensSpeed speed)
{
return Message.GetMessage(deviceAddress,0x00,0x27,0x00,(byte)speed);
}

#endregion

#region Base Command Set

public byte[] CameraSwitch(uint deviceAddress,Switch action)
{
byte m_action = CameraOnOff;
if(action == Switch.On)
m_action += CameraOnOff; //Maybe wrong !!!
return Message.GetMessage(deviceAddress,m_action,0x00,0x00,0x00);

}

public byte[] CameraIrisSwitch(uint deviceAddress,Iris action)
{
return Message.GetMessage(deviceAddress,(byte)action,0x00,0x00,0x00);
}

public byte[] CameraFocus(uint deviceAddress,Focus action)
{
return Message.GetMessage(deviceAddress,(byte)action,0x00,0x00,0x00);
}

public byte[] CameraZoom(uint deviceAddress,Zoom action)
{
return Message.GetMessage(deviceAddress,0x00,(byte)action,0x00,0x00);
}

public byte[] CameraTilt(uint deviceAddress,Tilt action, uint speed)
{
if(speed32)
throw new Exception("Protocol Pelco P support 32 devices only");

Address = Byte.Parse((address-1).ToString());
Data1 = data1;
Data2 = data2;
Data3 = data3;
Data4 = data4;

CheckSum = (byte)(STX ^ Address ^ Data1 ^ Data2 ^ Data3 ^ Data4 ^ ETX);

return new byte[]{STX,Address,Data1,Data2,Data3,Data4,ETX,CheckSum};
}

}
}


//}











Pelco-D (I did some update from author source code for bugs)
/*-------------------------------------------------------------------------------
* Author: Tamir Khason, 2004
* Email: tamir@khason.biz
* Web: http://www.dotnet.us/
*
* Freeware: Please do not remove this header
*
* File: P.cs
*
* Description: PELCO P Protocol Implementation dot.NET Way
* This is GPL software. Do with it as you want, but feed us back any improvements.
*
* This is a simple class to control a PELCO PTZ camera via RS422/485
* 'P' protocol. It supports all of the commands including UP, DOWN, IN, OUT, LEFT,
* RIGHT, NEAR, FAR, as well as all other extended commands.
*
* To use this, you need to put a RS232->RS422 adapter on the output
* of your desired serial port.
*
* The Pelco doesn't return ANY usefull info back, so you only really need 2-wire support
* (one way) communications out.
*
*
* Version: 1.4
* ------------------------------------------------------------------------------*/
using System;
using System.Collections;

//namespace Pelco
//{
///
/// dot.NET Implementation of Pelco P Protocol
///

public class P //: Pelco
{
private const byte STX = 0xA0;
private const byte ETX = 0xAF;

#region Pan and Tilt Commands
#region Data1
private const byte FocusFar = 0x01;
private const byte FocusNear = 0x02;
private const byte IrisOpen = 0x04;
private const byte IrisClose = 0x08;
private const byte CameraOnOff = 0x10;
private const byte AutoscanOn = 0x20;
private const byte CameraOn = 0x40;
#endregion

#region Data2
private const byte PanRight = 0x02;
private const byte PanLeft = 0x04;
private const byte TiltUp = 0x08;
private const byte TiltDown = 0x10;
private const byte ZoomTele = 0x20;
private const byte ZoomWide = 0x40;
#endregion

#region Data3
private const byte PanSpeedMin = 0x00;
private const byte PanSpeedMax = 0x40;
#endregion

#region Data4
private const byte TiltSpeedMin = 0x00;
private const byte TiltSpeedMax = 0x3F;
#endregion
#endregion

#region Enums
public enum PresetAction {Set,Clear,Goto}
public enum PatternAction {Start,Stop,Run}
public enum Action {Start,Stop}
public enum LensSpeed {Low=0x00,Medium=0x01,High=0x02,Turbo=0x03}
public enum Pan {Left = PanLeft,Right = PanRight}
public enum Tilt {Up = TiltUp,Down = TiltDown}
public enum Iris {Open = IrisOpen,Close = IrisClose}
public enum Zoom {Wide = ZoomWide,Tele = ZoomTele}
public enum Switch {On,Off}
public enum Focus {Near = FocusNear,Far = FocusFar}
#endregion

#region Extended Command Set
public byte[] Preset(uint deviceAddress, byte preset, PresetAction action)
{
byte m_action;
switch (action)
{
case PresetAction.Set:
m_action = 0x03;
break;
case PresetAction.Clear:
m_action = 0x05;
break;
case PresetAction.Goto:
m_action = 0x07;
break;
default:
m_action = 0x03;
break;
}
return Message.GetMessage(deviceAddress,0x00,m_action,0x00,preset);
}

public byte[] Flip(uint deviceAddress)
{
return Message.GetMessage(deviceAddress,0x00,0x07,0x00,0x21);
}

public byte[] ZeroPanPosition(uint deviceAddress)
{
return Message.GetMessage(deviceAddress,0x00,0x07,0x00,0x22);
}

public byte[] AutoScan(uint deviceAddress, Action action)
{
byte m_action;
if(action == Action.Start)
m_action = 0x09;
else
m_action = 0x0B;
return Message.GetMessage(deviceAddress,0x00,m_action,0x00,0x00);
}

public byte[] RemoteReset(uint deviceAddress)
{
return Message.GetMessage(deviceAddress,0x00,0x0F,0x00,0x00);
}

public byte[] Zone(uint deviceAddress,byte zone, Action action)
{
if(zone<0x01 & zone>0x08)
throw new Exception("Zone value should be between 0x01 and 0x08 include");
byte m_action;
if(action == Action.Start)
m_action = 0x11;
else
m_action = 0x13;

return Message.GetMessage(deviceAddress,0x00,m_action,0x00,zone);
}



public byte[] WriteToScreen(uint deviceAddress,string text)
{
if(text.Length > 40)
text = text.Remove(40,text.Length-40);
System.Text.Encoding encoding = System.Text.Encoding.ASCII;
byte[] m_bytes = new byte[encoding.GetByteCount(text)*8];
int i = 0;
byte m_scrPosition;
byte m_ASCIIchr;

foreach(char ch in text)
{
m_scrPosition = Convert.ToByte(i/8);
m_ASCIIchr = Convert.ToByte(ch);
Array.Copy(Message.GetMessage(deviceAddress,0x00,0x15,m_scrPosition,m_ASCIIchr),0,m_bytes,i,8);
i = i + 8;
}

return m_bytes;
}

public byte[] ClearScreen(uint deviceAddress)
{
return Message.GetMessage(deviceAddress,0x00,0x17,0x00,0x00);
}

public byte[] AlarmAcknowledge(uint deviceAddress, uint alarmID)
{
if(alarmID < 1 & alarmID>8)
throw new Exception("Only 8 alarms allowed for Pelco P implementation");
return Message.GetMessage(deviceAddress,0x00,0x19,0x00,Convert.ToByte(alarmID));
}

public byte[] ZoneScan(uint deviceAddress,Action action)
{
byte m_action;
if(action == Action.Start)
m_action = 0x1B;
else
m_action = 0x1D;
return Message.GetMessage(deviceAddress,0x00,m_action,0x00,0x00);
}

public byte[] Pattern(uint deviceAddress,PatternAction action)
{
byte m_action;
switch (action)
{
case PatternAction.Start:
m_action = 0x1F;
break;
case PatternAction.Stop:
m_action = 0x21;
break;
case PatternAction.Run:
m_action = 0x23;
break;
default:
m_action = 0x23;
break;
}
return Message.GetMessage(deviceAddress,0x00,m_action,0x00,0x00);
}

public byte[] SetZoomLensSpeed(uint deviceAddress, LensSpeed speed)
{
return Message.GetMessage(deviceAddress,0x00,0x25,0x00,(byte)speed);
}

public byte[] SetFocusLensSpeed(uint deviceAddress, LensSpeed speed)
{
return Message.GetMessage(deviceAddress,0x00,0x27,0x00,(byte)speed);
}

#endregion

#region Base Command Set

public byte[] CameraSwitch(uint deviceAddress,Switch action)
{
byte m_action = CameraOnOff;
if(action == Switch.On)
m_action += CameraOnOff; //Maybe wrong !!!
return Message.GetMessage(deviceAddress,m_action,0x00,0x00,0x00);

}

public byte[] CameraIrisSwitch(uint deviceAddress,Iris action)
{
return Message.GetMessage(deviceAddress,(byte)action,0x00,0x00,0x00);
}

public byte[] CameraFocus(uint deviceAddress,Focus action)
{
return Message.GetMessage(deviceAddress,(byte)action,0x00,0x00,0x00);
}

public byte[] CameraZoom(uint deviceAddress,Zoom action)
{
return Message.GetMessage(deviceAddress,0x00,(byte)action,0x00,0x00);
}

public byte[] CameraTilt(uint deviceAddress,Tilt action, uint speed)
{
if(speed32)
throw new Exception("Protocol Pelco P support 32 devices only");

Address = Byte.Parse((address-1).ToString());
Data1 = data1;
Data2 = data2;
Data3 = data3;
Data4 = data4;

CheckSum = (byte)(STX ^ Address ^ Data1 ^ Data2 ^ Data3 ^ Data4 ^ ETX);

return new byte[]{STX,Address,Data1,Data2,Data3,Data4,ETX,CheckSum};
}

}
}


//}

Tuesday, July 26, 2011

CyanogenMod cannot download google market apps



Platform: CyanogenMod 7 (Android)


Error: Trying to install market apps, it starts downloading for a second or so and then stops. It happen on large app (more than 5Mb) files.


Reason :
To download an app from google market, android required a cache.This cache folder is located in /cache partition (it's called /cache/download).
But this partition (with a size of about 40Mb on HTC Desire) contains also others caches, notably the dalvik-cache(used to accelerate the boot of android) which has a size of...35Mb !
That why "big" apps can't be downloaded using the market but small ones can be downloaded without any issues.
This also explain the "not enough space" message in logs which does not refer to the internal or external memory but to the space of /cache/download folder.
Concerning S2E, it's only works if your sdcard is mounted under /sd-ext. For 
users mounted on /sdcard, another solution is to create a symlink of /cache/download which point to a folder in your sdcard.



Solution
To clarify for anyone who isn't quite sure how to do this, enter these commands in the terminal emulator:
mkdir /mnt/sdcard/market-download-cache
su
cd /cache
mv download download.bak
ln -s /mnt/sdcard/market-download-cache download
ls -ahl .

the last step (ls -ahl .) is intended to verify that /cache/download points to /mnt/sdcard/market-download-cache; there should be an entry that should look somewhat like "lrwxrwxrwx 1 root root 33 Apr 14 03:35 download -> /mnt/sdcard/market-download-cache".

Thursday, November 18, 2010

MSSQL: the process could not execute 'sp_replcmds'

Platform:
Microsoft SQL server

Error:
While replications,  the Log Reader Agent status shown "the process could not execute 'sp_replcmds'...

Solution:
Change database owner to sa.

Step:
  1. Select "Databases", open "Object Explorer Details"(shortcut F7), you can see the current owner for every database.
  2. Change the owner to sa as script below:
    •  sp_changedbowner ''
  3. Repeat step 1, click refresh button to check the new database owner.
  4. Reinitialize the publications by click "Reinitialize All Subscriptions" .

Wednesday, June 2, 2010

How to empty Trash in Ubuntu (UNR)

Tested in Ubuntu Netbook Remix 10.04

Two ways to empty trash
1. Complete it manually in Terminal
     sudo rm -rf /home//.local/share/Trash/files/*

2. In "Files & folders", click any folder icon to open File browser. Click "Go" in the toolbar, then select Trash. Simply click the "Empty Trash", your Trash folder will be empty.