467,175 Members | 1,323 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,175 developers. It's quick & easy.

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


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
data.
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,
Serial.OPEN_EXISTING, Serial.FILE_FLAG_OVERLAPPED, 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
ve*********@gmail.com
--

|\/\/\/\/\/|
| | V.V.P.C.K Kiran Kumar
| (o)(o)
c _)
----------------------------------------------------------------------------
----
Nov 17 '05 #1
  • viewed: 2238
Share:
1 Reply
should you be opening "COM3:" or just "COM3"?
Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Dan | last post: by
1 post views Thread by verge | last post: by
3 posts views Thread by John Dann | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.