I am having trouble communicating with an older RS-232 device. I am using Visual C++ 2008 and the serialPort resource. I can setup and open the port no problem. But certain characters will transmit and receive others will not. I first thought it was a parity or comm set up issue, but I have no problems communicating using HyperTerminal (9600-7-E-1). I have tried several combinations of parity and stop bit but nothing works 100%. Characters "0,3,5,6,9,H,D" transmit and receive but characters "1,2,4,7,8" are received as "?". I would appreciate any advice or sugestions.
// Init and Open Port------------------------------------
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
this->textBox2->Text=String::Empty;
if(this->comboBox1->Text==String::Empty || this->comboBox2->Text==String::Empty);
this->textBox1->Text="Please Select Port Settings";
else {
try{
// make sure port isn't open
if(!this->LaserPort->IsOpen){
this->LaserPort->PortName=this->comboBox1->Text;
this->LaserPort->BaudRate=Int32::Parse(this->comboBox2->Text);
this->textBox1->Text="Enter Message Here";
String^ parity;
parity = comboBox3->Text ;
LaserPort->Parity = (Parity)Enum::Parse(Parity::typeid, parity);
this->LaserPort->Open();//open serial port
}
else
this->textBox1->Text="Port isn't openned";
}
catch(UnauthorizedAccessException^){
this->textBox1->Text="UnauthorizedAccess";
}
}
}
// send button
private
: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
String^ message = this->textBox1->Text;
// write to serial
if(this->LaserPort->IsOpen)
{
LaserPort->Write(message);
}
else
this->textBox1->Text="Port Not Opened";
}
// Read button --------------------------------------
private
: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
// check if port is ready for reading
if(this->LaserPort->IsOpen){
// Reset the text in the result label.
this->textBox2->Text = String::Empty;
textBox3->Text = "";
// this will read manually
try{
textBox2->Text=this->LaserPort->ReadLine();
textBox3->Text= this->LaserPort->ReadExisting();
}
catch(TimeoutException^){this->textBox2->Text="Read Timeout Exception";}
}
elsethis->textBox2->Text="Port Not Opened";
}
String^ name = this->LaserPort->PortName;