By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,426 Members | 2,928 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,426 IT Pros & Developers. It's quick & easy.

C# program: Gettign 126 error while send data to Serial Port .?

P: n/a

Hi all,
I have a problem to communicate with serial port(COM3:). I am able to open
the handle but cannot send any data.

1. I connected my motoroala handset to PC through datacable.
2. I installed valid driver to detec the motorla(V400) handset
3. I tested the handset through Hypertermal and succssfully sending any
4. I opened the Control Panel -> Phone and Model window and clicked the
modem tab and I saw that the Motorola handset( Motorola USB modem ) is
attached through COM3: port fo the PC
5. Then I created a sample C# program to communicate with handeset
through COM3 port . the code is like this:

handleName = "COM3:"
string text = "AT+CKPD=";
int byteCnt = oEnc.GetByteCount( text.ToCharArray(),0,text.Length,true);
byte[] Buffer = new byte[byteCnt];
int byteEncodeCount = oEnc.GetBytes(
text.ToCharArray ),0,text.Length,Buffer,0,true);
hSerialPort = Serial.CreateFile( handleName, Serial.GENERIC_READ |
Serial.GENERIC_WRITE, 0 ,IntPtr.Zero,
if( hSerialPort.ToString() == "-1" )

Console.WriteLine( "Un available");

int ch = 1;
if( ch == 1 )
Success = Serial.WriteFile( hSerialPort,Buffer,
Buffer.Length, out BytesWritten, IntPtr.Zero );

When i debug the code the Serial.WriteFile method is return false
value. and I got the system error code using Marshal.GetLastwin32Error(), it
is giving 126 error code. I searched in internet description of the 126
error , it says module not found.
I don't know what to do. I am imporing only Kernel32.dll in my sample
program. is anything i have to do..?
please help me on the problem..

Thanks & Regards
kiran kumar

| | V.V.P.C.K Kiran Kumar
| (o)(o)
c _)
Nov 17 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
should you be opening "COM3:" or just "COM3"?
Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.