ERROR 1359 / raw ir on pocket pc

system error 1359 => ERROR_INTERNAL_ERROR => An internal error occurred
Got this error while working with COMM programming. The reason was I was trying raw read/write on a wrong com port (IrCOMM port).

background
Was working with building science project “Remote on Pocket PC”.

Goal => Read IR signals of a remote, learn them, and be able to generate the same signal.

Conclusion => windows sux or i am not good enough to appreciate the beauty of it.

Yes, unfortunately I was working on windows sad. Coz the pocket pc was windows based. I couldnt help it out.

The problem was simple. Some sockets programming, to read ir from some port, see the singal and send same data out. But the simple problem screwed me totally. I never worked so much on any project like i did for this. Coz a small 50 lines of code was not working. And the people at M$ have made things so much complicated, i dont know why. there are some 15999 error codes mentined at msdn site. Why cant they keep things as simple as they are in GNU/linux. When i work in GNU i understand what is happening, even to the level of kernel. Coz its simple. I guess in M$ no one knows how does windows work. millions of lines of code. sad

We had to install things ( EVC, pocket ps sdk, active synk etc) some 15 times, on 5 different pcs. ( Every installations is more than an hour. sad ) Coz if they are not installed in a fixed order, and with fixed versions and patches they just dont work. And if you have installed it even once wrongly in a system, it will never work again. Can something suck more than this.

Coming back to the problem, read/write IR on pocket pc.

Started with socket programming, but soon figured out that its based on IrDA protocol. That means it does handshake, headers etc stuff. That was not required for me. I just wanted to read and write a simple beam of data without any header stuff. And handshake etc was not at possible. So i had to look for something called “raw IR”.

raw IR

“raw IR” in simple words is reading all that is received by the IR sensor and sends a beam of exactly what you have written. No more no less. Figured out that IR is mapped to a serial port, which can be programmed using COMM programming in windows. com port behaves like a device file of GNU/Linux. Open a file, do read/write and close the file. Looked simple.

I wrote a simple code that opens a COMM port, tries read/write on it. But nothing worked. And this simple thing troubled me for days. I became an expert of serial port aka COMM programming and learnt lots of other fundas of windows but nothing helped me out. The error I was getting was 120 => ERROR_CALL_NOT_IMPLEMENTED (This function is not supported on this system), which i figured out is not the actual error and was randomly being generated somewhere. After ignoring this error the next error was 1359 aka ERROR_INTERNAL_ERROR, which doesnt give any information to me. and neither did google.

raw IR on Pocket PC

My PPC had 2 ports for ir. COM3 and COM4.
The registry of PPC has following enteries for IR -

1. HKLM/Comm/IrDA [ people generally use it to get the port, but i had nothing here ]
2. HKLM/Comm/XSC1_IrDA1/Parms [ port = 4 ]
the path XSC1_IrDA1 used above is written at HKLM/Comm/XSC1_IrDA/Linkage/Route or HKLM/Comm/IrDA/Linkage/Bind
3. HKLM/Drivers/BuiltIn/IrCOMM [ Index = 3, Unimodem/FriendlyName = Infrared Port ]
4. HKLM/Drivers/BuiltIn/IrDA [ Index = 4, FriendlyName = Native IR: ]
* [ HKLM = HKEY_LOCAL_MACHINE ]

From this i could figure out that my ports for IR were
COM3 aka IrCOMM
COM4 aka Native IR (its connection to IrDA looks confusig)

This means that COM3 uses a special (low level) IrDA protocol, called IrCOMM.
Raw IR will not work with IrCOMM.
So i have to use COM4 for raw ir. It worked fine.

Another important thing to note -
your PPC might be blocking Native IR port for its own ir use.
Uncheck Start -> Settings -> Connections[tab] -> Beam -> Receive all incoming beams.
The path may differ for you. Coz of it CreateFile failed on COM4 for me and I thought its not the right port. and I kept fighting with the COM3 port and some INTERNAL error.

A simple code to read/write ir -

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPTSTR lpCmdLine,int nCmdShow){	// OPEN 	HANDLE port;	port = CreateFile( _T(”COM4:”), GENERIC_READ | GENERIC_WRITE, 0, 			NULL, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL , NULL);

	// FREE		EscapeCommFunction( port, SETIR);

	// SETUP : BUFFER	SetupComm(port, 2048, 2048);	PurgeComm(port, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR);	// SETUP : IRDA port settings	DCB dcb;	dcb.DCBlength = sizeof(DCB);	GetCommState(port, &dcb);	dcb.BaudRate          = CBR_115200;	dcb.fBinary           = TRUE;	dcb.fParity           = TRUE ; 	dcb.fOutxCtsFlow      = FALSE;	dcb.fOutxDsrFlow      = FALSE;	dcb.fDtrControl       = DTR_CONTROL_DISABLE;	dcb.fDsrSensitivity   = FALSE;	dcb.fTXContinueOnXoff = FALSE;	dcb.fOutX             = FALSE;	dcb.fInX              = FALSE;	dcb.fErrorChar        = FALSE;  	dcb.fNull             = FALSE;	dcb.fRtsControl       = RTS_CONTROL_DISABLE;	dcb.fAbortOnError     = TRUE;	dcb.ByteSize          = 8; 	dcb.Parity            = EVENPARITY; 	dcb.StopBits          = TWOSTOPBITS;	dcb.Parity            = EVENPARITY;	SetCommState(port, &dcb);

	// SETUP : TIMEOUT	COMMTIMEOUTS timeouts;	GetCommTimeouts(port, &timeouts);	timeouts.ReadIntervalTimeout         = MAXDWORD;	timeouts.ReadTotalTimeoutMultiplier  = 0;	timeouts.ReadTotalTimeoutConstant    = 0;	timeouts.WriteTotalTimeoutMultiplier = 0;	timeouts.WriteTotalTimeoutConstant   = 0;	SetCommTimeouts(port, &timeouts);

	// READ/WRITE	// Using ReadFile and WriteFile

	// Read	BYTE buf[256];	unsigned long b;	int a;	for( int n=0; n<20; n++){ // 20 tries		a = ReadFile( port, buf, 255, &b, 0 );		if( b >0 ){			// b bytes read… display them			/*			sprintf(mesg,”Yahooo %d bytes read\r\n[%s]”, b, buf );			MessageBox( NULL, s3 , _T( “check” ), MB_OKCANCEL ) 			*/		}	}

	// Write	/*	unsigned long b;	int a = WriteFile(port, “1234567890″, 8, &b, NULL);	*/

	// END	PurgeComm(port, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR);	CloseHandle(port);	return 0;}

download a simple code to read/write raw IR from here

refrences
* Code Project / Pocket PC TV Remote Control By Nick Deacon
* Raw IR on Pocket PC
* Vito Remote and Oscilloscope
* ePanorama / Infrared remote control technology
* Lists the 15999 system error codes
* and now this page too

Updated May 18th ‘05: Code added. Made more readable seeing large no of hits.

3 Responses to “ERROR 1359 / raw ir on pocket pc”

  1. Mobi Says:

    where is it?
    A simple code to read/write ir

  2. vishal Says:

    Re:
    So are you ready with the project?

  3. Tom Says:

    raw ir on pocket pc
    I read your article regarding the raw IR on Pocket PC. In my iPAQ, COM2 is for native IR. With reference to your codes, I successfully can detect the IR signal. However, I can’t detect which buttons of SONY remote is being pressed. Do you have any idea on how to decode the IR signals?

    I am looking for your reply. Thanks.

    Tom

Leave a Reply