Giriş
13 Eylül 2008; 15:56:26
merhaba arkadaşlar, open file ile com port için bir handle alıp işlemlerimi bu handle üzerinden yapabiliyorum. rs232 den veri alma ve gönderme konusunda bir sıkıntım yok fakat benim asıl amacım elimdeki GPS modülü için küçük bir program hazırlamak. takıldığım yer ise GPS modülünden rs232 portuna sürekli veri gelmesi ve gelen verileri bir Memo nesnesinde göstermek. sürekli gelen bir veri olduğu için, bende programa bir timer nesnesi ekleyip gelen veriyi memo ya yazmaya çalıştım fakat bir müddet sonra programın kasması durumuyla karşı karşıya kaldım. benim düşünceme göre bir zamanlama nesnesi kullanmadan, veri rs232 belleğini doldurduğunda programa nasıl yapıldığını bilmediğim bir kesme oluşturarak, veriyi memoya basabilirim hemde kasma olmadan ama nasıl? veya başka nasıl bir yöntem uygulayabilirim???
_____________________________Nous faisons confiance dans Dieu electronical engineer
14 Eylül 2008; 3:32:53
yanlis anlamadiysam "memory buffer" gibi bir nesne kullaniyorsun ve belli bir yerden sonra kullandigin memory nesnesi cok buyuyor? kullandigin datayi belli bir yerden sonra silmeyi denesen? mesela memset, malloc, free, vs gibi fonksiyonlari ile? yada new ve delete kullanarak dinamik nesneler kullansan ve nesneleri duzenli olarak delete etsen?
_____________________________ cout<<"imza yok"<<endl;
16 Eylül 2008; 10:30:25
mesela hyper terminal gelen datayı hiçde tıkanmadan çatır çatır ekrana yazıyor. dediğiniz gibi bir yöntem mi kullnılıyor ondada??? kod şöyle
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
HANDLE handlePort_;
DCB lpDCB;
BYTE bRun=FALSE;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::OpenComPortClick(TObject *Sender)
{
//HANDLE handlePort_;
handlePort_ = CreateFile("COM1", // Specify port device: default "COM1"
GENERIC_READ | GENERIC_WRITE, // Specify mode that open device.
0, // the devide isn't shared.
NULL, // the object gets a default security.
OPEN_EXISTING, // Specify which action to take on file.
0, // default.
NULL);
if (handlePort_ == INVALID_HANDLE_VALUE) MessageBox(handlePort_,"Unable to open COM port","Communication Error",MB_OK);
else MessageBox(handlePort_,"COM port ready","Communication",MB_OK);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ReadCurrentConfigClick(TObject *Sender)
{
//DCB lpDCB;
GetCommState(handlePort_,&lpDCB);
switch (lpDCB.BaudRate) {
case CBR_110: ComboBoxEx1->ItemIndex=1;
break;
case CBR_300: ComboBoxEx1->ItemIndex=2;
break;
case CBR_600: ComboBoxEx1->ItemIndex=3;
break;
case CBR_1200: ComboBoxEx1->ItemIndex=4;
break;
case CBR_2400: ComboBoxEx1->ItemIndex=5;
break;
case CBR_4800: ComboBoxEx1->ItemIndex=6;
break;
case CBR_9600: ComboBoxEx1->ItemIndex=7;
break;
case CBR_14400: ComboBoxEx1->ItemIndex=8;
break;
case CBR_19200: ComboBoxEx1->ItemIndex=9;
break;
case CBR_38400: ComboBoxEx1->ItemIndex=10;
break;
case CBR_57600: ComboBoxEx1->ItemIndex=11;
break;
case CBR_115200: ComboBoxEx1->ItemIndex=12;
break;
}
switch (lpDCB.ByteSize) {
case 4: ComboBoxEx2->ItemIndex=0;
break;
case 5: ComboBoxEx2->ItemIndex=1;
break;
case 6: ComboBoxEx2->ItemIndex=2;
break;
case 7: ComboBoxEx2->ItemIndex=3;
break;
case 8: ComboBoxEx2->ItemIndex=4;
break;
}
switch (lpDCB.fParity) {
case EVENPARITY: ComboBoxEx3->ItemIndex=0;
break;
case MARKPARITY: ComboBoxEx3->ItemIndex=3;
break;
case NOPARITY: ComboBoxEx3->ItemIndex=2;
break;
case ODDPARITY: ComboBoxEx3->ItemIndex=1;
break;
case SPACEPARITY: ComboBoxEx3->ItemIndex=4;
break;
}
switch (lpDCB.StopBits) {
case ONESTOPBIT: ComboBoxEx4->ItemIndex=0;
break;
case ONE5STOPBITS: ComboBoxEx4->ItemIndex=1;
break;
case TWOSTOPBITS: ComboBoxEx4->ItemIndex=2;
break;
}
//ComboBoxEx1->ItemIndex=3;
//lpDCB.ByteSize=8;
//SetCommState(handlePort_, &lpDCB);
//Label1->Caption=IntToStr(lpDCB.ByteSize);
//lpDCB.BaudRate = CBR_115200; // set the baud rate
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CloseCOMPortClick(TObject *Sender)
{
if(CloseHandle(handlePort_) == 0) MessageBox(handlePort_,"Unable to close COM port","Communication Error",MB_OK);
else MessageBox(handlePort_,"COM port is closed","Communication",MB_OK);
PurgeComm(handlePort_,PURGE_RXCLEAR);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SetCOMPortConfigClick(TObject *Sender)
{
switch (ComboBoxEx1->ItemIndex) {
case 1: lpDCB.BaudRate=CBR_110;
break;
case 2: lpDCB.BaudRate=CBR_300;
break;
case 3: lpDCB.BaudRate=CBR_600;
break;
case 4: lpDCB.BaudRate=CBR_1200;
break;
case 5: lpDCB.BaudRate=CBR_2400;
break;
case 6: lpDCB.BaudRate=CBR_4800;
break;
case 7: lpDCB.BaudRate=CBR_9600;
break;
case 8: lpDCB.BaudRate=CBR_14400;
break;
case 9: lpDCB.BaudRate=CBR_19200;
break;
case 10: lpDCB.BaudRate=CBR_38400;
break;
case 11: lpDCB.BaudRate=CBR_57600;
break;
case 12: lpDCB.BaudRate=CBR_115200;
break;
}
switch (ComboBoxEx2->ItemIndex) {
case 0: lpDCB.ByteSize=4;
break;
case 1: lpDCB.ByteSize=5;
break;
case 2: lpDCB.ByteSize=6;
break;
case 3: lpDCB.ByteSize=7;
break;
case 4: lpDCB.ByteSize=8;
break;
}
switch (ComboBoxEx3->ItemIndex) {
case 0: lpDCB.fParity=EVENPARITY;
break;
case 3: lpDCB.fParity=MARKPARITY;
break;
case 2: lpDCB.fParity=NOPARITY;
break;
case 1: lpDCB.fParity=ODDPARITY;
break;
case 4: lpDCB.fParity=SPACEPARITY;
break;
}
switch (ComboBoxEx4->ItemIndex) {
case 0: lpDCB.StopBits=ONESTOPBIT;
break;
case 1: lpDCB.StopBits=ONE5STOPBITS;
break;
case 2: lpDCB.StopBits=TWOSTOPBITS;
break;
}
//if(ComboBoxEx4->ItemIndex==2) ShowMessage("ok");
if (SetCommState(handlePort_,&lpDCB) == 0) MessageBox(handlePort_,"Unable to set COM port","Communication Error",MB_OK);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Memo1->Text="GPS";
//Memo1->
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
DWORD bytesRead,i;
char buffer[100];
char DateBuffer[100];
//if(ReadFile(handlePort_, buffer, 80, &bytesRead, NULL)) { if(bRun) Memo1->Lines->Add(buffer); }
ReadFile(handlePort_, buffer, 80, &bytesRead, NULL);
//-------------------
/*
for(i=0;i<80;i++) if(buffer[i]=='$') break;
if((buffer[i+1]=='G')&(buffer[i+2]=='P')&(buffer[i+3]=='R')&
(buffer[i+4]=='M')&(buffer[i+5]=='C')) Label6->Caption="RMC info";
else Label6->Caption="no RMC info";
*/
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if(bRun) { bRun=FALSE; Button1->Caption="Run"; Timer1->Enabled=TRUE; }
else { bRun=TRUE; Button1->Caption="Stop"; Timer1->Enabled=FALSE; }
}
//---------------------------------------------------------------------------
< Bu mesaj bu kişi tarafından değiştirildi r2d2droids -- 16 Eylül 2008; 10:28:05 >
_____________________________Nous faisons confiance dans Dieu electronical engineer
23 Eylül 2008; 16:55:11
yukarı...
_____________________________Nous faisons confiance dans Dieu electronical engineer
24 Eylül 2008; 0:34:18
C# Onersem :) ?
_____________________________
25 Eylül 2008; 16:44:23
C++ da derleyici değiştirince bile afallıyorum da C# olursa heralde iyice dellenirim. peki C# da nasıl bir program yazacaz belki ben C++ a uydurabilirim???
_____________________________Nous faisons confiance dans Dieu electronical engineer
25 Eylül 2008; 21:03:27
quote: Orjinalden alıntı: r2d2droids C++ da derleyici değiştirince bile afallıyorum da C# olursa heralde iyice dellenirim. peki C# da nasıl bir program yazacaz belki ben C++ a uydurabilirim??? C# da SerialPort Sinifini Olu$turup. DataReceive Eventina Uye Oldugunuzda Gerisi Textbox a Yazdirmaya kaliyor :)
_____________________________
6 Ekim 2008; 9:05:10
bu nesne yönelimli diller beni çıldırtacak. C++ da sınıf olayını çözmem gerekiyor anlaşılan yardımın için teşekkürler...
_____________________________Nous faisons confiance dans Dieu electronical engineer
9 Ekim 2008; 8:41:22
yukarıdaki koda göre nasıl sınıf oluşturup, event tanımlarım hala bulabilmiş değilim...
_____________________________Nous faisons confiance dans Dieu electronical engineer
9 Ekim 2008; 21:27:39
GPS de veriler satır satır yani her mesaj sonunda CRLF karakteri ile gelir. c# da gelen verileri ReadLine(); ile okursan problem yaşamazsın. ben bu şekilde kullanıyorum, sorun yok.
_____________________________ | ARM7 | ARM9 | CORTEX-M3 | PSOC | AVR | 8051 | PIC | FPGA | CPLD | C | VERILOG | RTOS | WIN CE |
9 Ekim 2008; 21:41:20
Basit Bi $ekilde Seri Porttan veri Almak Icin: Form1: 1 Adet Button 1 Adet Textbox 1 Adet SerialPort (Components tab inin Icinde) Koyup A$agidaki kodlari Inceleyin:
public Form1()
{
InitializeComponent();
serialPort1.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(serialPort1_DataReceived);
}
void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
textBox1.Text += e.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
serialPort1.PortName = "COM2";
serialPort1.Open();
}
_____________________________