I am having an issue with the following code:

SerialPort^ com = gcnew SerialPort("COM1", 9600);
array<unsigned char>^ messageBuf = gcnew array<unsigned char>(512);

com->Open();
com->Read(messageBuf, 0, 512);
com->Close();

messageBuf is not being filled with anything. I know the port is open cause writing works fine. Any ideas why this is?

hi,
maybe reading from serial port needs special configuration first, as for example:

port->DataBits = 8;
port->Parity = Parity::None;
port->StopBits = StopBits::One;

krs,
tesu

I've tried that and it didnt fix it, but thanks anyways. Im just so confused, ive tried ReadExisting(), I dont know how to get this to work.

messageBuf is not being filled with anything. I know the port is open cause writing works fine. Any ideas why this is?

What do you have attached to the COM1 port that will transmit data to your computer ?

I have a usb (with serial emulated through driver) to serial cable with a null rs232 cable attached. I just decided to read in one char at a time using an index (using com->ReadChar()) and it works. It still annoys me that this does not work, because I think it should, if anyone knows why. Thanks.

This article has been dead for over six months. Start a new discussion instead.