PDA

View Full Version : خواندن از پورت سریال



slashslash2009
شنبه 27 آبان 1391, 21:27 عصر
سلام خسته نباشید
من یه کد از vb6 دارم (که اصلا vb بلد نیستم) میخاستم اگه دوستان میدونن اونو به c تغییر بدن و یا راهنمییم کنن البته کدش زیاد سخت نیست


MSComm1.PortOpen =
True

MSComm1.InputLen = 1


MSComm1.Output = Chr$(24)



MSComm1.Output ="180!1@"


MSComm1.Output = "182!1@"


MSComm1.Output = "184!1@"


MSComm1.Output = "186!1@"


MSComm1.Output = "188!1@"


MSComm1.Output = "190!1@"


MSComm1.Output = "192!1@"


MSComm1.Output = "194!1@"


MSComm1.Output = "196!1@"
MSComm1.Output = "198!1@"
MSComm1.Output =
"#?"

Sleep 800

For i = 1 To 250

bufcard = MSComm1.Input


If bufcard = "$"Then'

Text121.Text = readcard

readcard =
""

bufcard =
""


ExitFor


EndIf

readcard = readcard + bufcard


Next i


بافر چند قسمت هست که در اینجا فقط یک قسمت رو از بافر میگیره خودم ازین کد استفاده میکنم ولی پیغام خطا timeout exeption میده




byte[] read_buffer = new byte[250];

serialPort1.ReadTimeout =500;

serialPort1.Open();

textBox1.Text = serialPort1.Read(read_buffer, 1, 177).ToString();

serialPort1.Close();

slashslash2009
یک شنبه 28 آبان 1391, 21:00 عصر
دوستان کمک کنید به دادم برسید