Windows Forms, SerialPort

Mar 19, 2016 at 4:53pm
Hello
I need to read 13 bytes useing Serial Port.
Only funcion that i think can do this is "Read(..)"
https://msdn.microsoft.com/pl-pl/library/34t733fh%28v=vs.110%29.aspx

I'm trying to do this in this way:

1
2
3
4
5
6
7
8
9
10
array<wchar_t>^ shiit = gcnew array <wchar_t>(13);
 
try {
    this->serialPort1->Read(shiit, 0, 13);
    String^ aha = dynamic_cast<String^> (shiit);
    this->textBox1->Text = aha;
     }
    catch (TimeoutException^) {
    this->textBox1->Text = "Timeout Exception";
     }

And it does not work.
I think that the reason is wrong converting way (array^ of char -> String^)
But i really dont know how to do it correctly.
Can u help me, please?
Last edited on Mar 19, 2016 at 5:10pm
Mar 19, 2016 at 9:47pm
Try this:
1
2
3
4
5
int count = this->serialPort1->Read(shiit, 0, 13);
if (count > 0)
   this->textBox1->Text = gcnew String(shiit);
else
   this->textBox1->Text = "No bytes read";
Mar 19, 2016 at 10:24pm
yep, it works.
i got it few minutes ago ^^

Topic archived. No new replies allowed.