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

K

kiran

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
(e-mail address removed)


--

|\/\/\/\/\/|
| | V.V.P.C.K Kiran Kumar
| (o)(o)
c _)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top