Mac OS X Lion seams disable OpenGL screen. So, glReadPixel can’t get screen shot.
The solution to grab the screen:
CGImageRef image = CGDisplayCreateImage(kCGDirectMainDisplay);
Grab Screen from Mac OS X Lion(10.7)
發文作者 cotton5415 於 十二月 29, 2011
發表於 MAC OS X's Road | 已加上的標籤: 10.7 capture, 10.7 grab, cotton5415 10.7 capture, cotton5415 10.7 screen capture, cotton5415 lion, cotton5415 Lion capture, cotton5415 Mac OS X, grab, Lion capture, Lion grab, Mac OS X capture. | 張貼留言 »
iOS 5 storyboard tutorial reference.
發文作者 cotton5415 於 十一月 11, 2011
http://kurrytran.blogspot.com/2011/07/simple-ios-5-tutorial-using-storyboard.html
發表於 MAC OS X's Road | 已加上的標籤: cotton5415, iOS, iOS 5, storyboard | 張貼留言 »
cow, 改什麼storyboard…..xib 沒得用了。maintain 很麻煩。
發文作者 cotton5415 於 十月 17, 2011
http://chrislee.kr/wp/2011/07/24/mainwindow-xib-absence-in-xcode-4-2-beta-4-with-ios-5-sdk/
發表於 MAC OS X's Road | 已加上的標籤: cotton5415, ib, iOS, iOS 5, storyboard, xib | 張貼留言 »
TCP 常見問題 1 : 如何知道對方不正常斷線?
發文作者 cotton5415 於 七月 13, 2011
問題: Peer A & Peer B 已經建立連線。但是Peer B突然電源線被拉掉,也沒電池撐著,或是突然B端的網路線被拉掉。這時候Peer A 的應用程式也沒有對B進行資料的收送。等到下次要搜送資料的時候,卻卡在send recv or read/write 當中。怎辦?
解法;利用 tcp keep alive.在socket 建立的時候 加上
int optval = 1 ;
setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, (const S8 *)&optval, sizeof(optval))
optval = 10 ; // seconds
setsockopt(sockfd, IPPROTO_TCP, TCP_KEEPALIVE, (const S8 *)&optval, sizeof(optval))
optval 設定成 timeout 的時間。這個timeout發生的時候, tcp 會送一個 SYN 給對方。
http://tldp.org/HOWTO/TCP-Keepalive-HOWTO/programming.html#setsockopt
發表於 MAC OS X's Road | 張貼留言 »
windows mysql reset root
發文作者 cotton5415 於 四月 28, 2011
http://dev.mysql.com/doc/mysql-windows-excerpt/5.0/en/resetting-permissions-windows.html
1. stop mysql service.
2. edit a file abcd.sql
UPDATE mysql.user SET Password=PASSWORD(‘MyNewPass’) WHERE User=’root’;
FLUSH PRIVILEGES;
3. mysqld.exe –console –init-file=abcd.sql
4. new root password = MyNewPass
發表於 mysql's Road, web programming, Win32's Road | 已加上的標籤: mysql root, mysql windows, windows mysql, windows mysql root | 張貼留言 »
VC++ MFC using STL, operator new: ono of the 5 overloads
發文作者 cotton5415 於 四月 28, 2011
http://social.msdn.microsoft.com/Forums/zh-CN/visualcpluszhchs/thread/b93ed7fe-c328-4901-bd3a-7e742e499775/
http://support.microsoft.com/kb/317799
發表於 Win32's Road | 已加上的標籤: MFC STL, MFC STL operator new, VC++ MFC STL, VC++ STL | 張貼留言 »
Power Point VBA Runtime Error
發文作者 cotton5415 於 四月 7, 2011
http://blogs.msdn.com/b/larryosterman/archive/2005/08/25/456344.aspx
發表於 MAC OS X's Road | 已加上的標籤: com, power point com, power point VBA, ppt, runtime error, vc run time error. | 張貼留言 »
to minimize Javascript codes
發文作者 cotton5415 於 四月 1, 2011
1.YUI Compressor (from Yahoo)
2.JSMin (by Douglas Crockford)
3.ShrinkSafe (from Dojo library)
4.Packer (by Dean Edwards)
發表於 MAC OS X's Road | 已加上的標籤: javascript, minimize javascript, minimize js | 張貼留言 »
386 ppc to universal binary
發文作者 cotton5415 於 三月 29, 2011
LIPO(1) LIPO(1)
NAME
lipo – create or operate on universal files
SYNOPSIS
lipo [-info] [-detailed_info] [-arch arch_type input_file] … [ input_file] … [-arch_blank arch_type]
[-create] [-thin arch_type] [-replace arch_type filename] … [-remove arch_type] … [-extract arch_type]
… [-extract_family arch_type] … [-verify_arch arch_type ...] [-output output_file] [-segalign
arch_type value] …
發表於 MAC OS X's Road | 張貼留言 »
iPhone serial port communication
發文作者 cotton5415 於 三月 17, 2011
http://devdot.wikispaces.com/Iphone+Serial+Port+Tutorial
Requirement:
1.Jailbroken Iphone with BSD Subsystem installed (Search the web for jailbreak tutorials)
2.Iphone development toolchain for Mac OSX, Linux, Windows (Cygwin) or other OS. I use this http://code.google.com/p/winchain/ in Windows.
3.Sparkfun Ipod connector or breakout board see http://www.sparkfun.com/commerce/product_info.php?products_id=633 or http://www.sparkfun.com/commerce/product_info.php?products_id=8295
4.PC USB UART – optional, but used in this tutorial. You will need either a 3.3V level UART for PC (see http://www.sparkfun.com/commerce/product_info.php?products_id=718) or you will need an old style 12V level serial cable with a level converter like this one http://www.compsys1.com/workbench/On_top_of_the_Bench/Max233_Adapter/max233_adapter.html (see warning below)
5.A soldering iron will help you out ![]()
6.Microsoft Visual Studio – optional, but used in the source code examples for the PC serial port communication.
WARNING! Do not try to use a 12V level RS232 port for this without a level converter to ~3V, it will severely damage your Iphone or render it non-functional.
Hardware:
The Dock Port
In the Ipod/Iphone dock port, the pins we are concerned with are as follows
Pin 1
Ground
Pin 18
3.3V Power (+)
Pin 12
TX also known as Serial Transmit
Pin 13
RX also known as Serial Receive
To see a full description of all of the pins in the dock connector, see here: http://pinouts.ru/Devices/ipod_pinout.shtml
Connections: iPhone/iPod Touch RX should connect to TX of the connected device, TX to RX of the connected device, and Ground to the Ground of the connected device. If your device can be powered by a low amperage, 3.3V power source you may chose to connect PIN 18 as well and power your device directly from the iPhone/iPod Touch.
Sample Codes:
#include <stdio.h> /* Standard input/output definitions */
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include <fcntl.h> /* File control definitions */
#include <errno.h> /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */
static struct termios gOriginalTTYAttrs;
static int OpenSerialPort()
{
int fileDescriptor = -1;
int handshake;
struct termios options;
// Open the serial port read/write, with no controlling terminal, and don't wait for a connection.
// The O_NONBLOCK flag also causes subsequent I/O on the device to be non-blocking.
// See open(2) ("man 2 open") for details.
fileDescriptor = open("/dev/tty.iap", O_RDWR | O_NOCTTY | O_NONBLOCK);
if (fileDescriptor == -1)
{
printf("Error opening serial port %s - %s(%d).\n",
"/dev/tty.iap", strerror(errno), errno);
goto error;
}
// Note that open() follows POSIX semantics: multiple open() calls to the same file will succeed
// unless the TIOCEXCL ioctl is issued. This will prevent additional opens except by root-owned
// processes.
// See tty(4) ("man 4 tty") and ioctl(2) ("man 2 ioctl") for details.
if (ioctl(fileDescriptor, TIOCEXCL) == -1)
{
printf("Error setting TIOCEXCL on %s - %s(%d).\n",
"/dev/tty.iap", strerror(errno), errno);
goto error;
}
// Now that the device is open, clear the O_NONBLOCK flag so subsequent I/O will block.
// See fcntl(2) ("man 2 fcntl") for details.
if (fcntl(fileDescriptor, F_SETFL, 0) == -1)
{
printf("Error clearing O_NONBLOCK %s - %s(%d).\n",
"/dev/tty.iap", strerror(errno), errno);
goto error;
}
// Get the current options and save them so we can restore the default settings later.
if (tcgetattr(fileDescriptor, &gOriginalTTYAttrs) == -1)
{
printf("Error getting tty attributes %s - %s(%d).\n",
"/dev/tty.iap", strerror(errno), errno);
goto error;
}
// The serial port attributes such as timeouts and baud rate are set by modifying the termios
// structure and then calling tcsetattr() to cause the changes to take effect. Note that the
// changes will not become effective without the tcsetattr() call.
// See tcsetattr(4) ("man 4 tcsetattr") for details.
options = gOriginalTTYAttrs;
// Print the current input and output baud rates.
// See tcsetattr(4) ("man 4 tcsetattr") for details.
printf("Current input baud rate is %d\n", (int) cfgetispeed(&options));
printf("Current output baud rate is %d\n", (int) cfgetospeed(&options));
// Set raw input (non-canonical) mode, with reads blocking until either a single character
// has been received or a one second timeout expires.
// See tcsetattr(4) ("man 4 tcsetattr") and termios(4) ("man 4 termios") for details.
cfmakeraw(&options);
options.c_cc[VMIN] = 1;
options.c_cc[VTIME] = 10;
// The baud rate, word length, and handshake options can be set as follows:
cfsetspeed(&options, B19200); // Set 19200 baud
options.c_cflag |= (CS8); // RTS flow control of input
printf("Input baud rate changed to %d\n", (int) cfgetispeed(&options));
printf("Output baud rate changed to %d\n", (int) cfgetospeed(&options));
// Cause the new options to take effect immediately.
if (tcsetattr(fileDescriptor, TCSANOW, &options) == -1)
{
printf("Error setting tty attributes %s - %s(%d).\n",
"/dev/tty.iap", strerror(errno), errno);
goto error;
}
// Success
return fileDescriptor;
// Failure "/dev/tty.iap"
error:
if (fileDescriptor != -1)
{
close(fileDescriptor);
}
return -1;
}
發表於 iPhone's Road | 已加上的標籤: iPhone, rs232, serial port | 張貼留言 »