Principales respuestas
SerialPort

Pregunta
-
Respuestas
-
Es exactamente lo mismo...
cambian son puros detalles pero debes utilizar los mismos componentes y funciones.
Juan Carlos Ruiz - http://juank.black-byte.com- Marcado como respuesta jose-111 miércoles, 4 de marzo de 2009 9:53
-
Con esta ventana tengo una ventana para enviar y otra pararecibir, si al pulsar introduzco lo siguiente:
#pragma
once
namespace
comunicacion { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; /// <summary> /// Summary for Form1 /// /// WARNING: If you change the name of this class, you will need to change the /// 'Resource File Name' property for the managed resource compiler tool /// associated with all .resx files this class depends on. Otherwise, /// the designers will not be able to interact properly with localized /// resources associated with this form. /// </summary> public ref class Form1 : public System::Windows::Forms::Form{
public:Form1(
void){
InitializeComponent();
// //TODO: Add the constructor code here //}
protected: /// <summary> /// Clean up any resources being used. /// </summary>~Form1()
{
if (components){
delete components;}
}
private: System::Windows::Forms::TextBox^ textBox_Enviar; protected: private: System::Windows::Forms::TextBox^ textBoxRecibir; private: System::Windows::Forms::Button^ buttonEnviar; private: System::IO::Ports::SerialPort^ serialPort1; private: System::ComponentModel::IContainer^ components; private: /// <summary> /// Required designer variable. /// </summary>
#pragma
region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> void InitializeComponent(void){
this->components = (gcnew System::ComponentModel::Container()); this->textBox_Enviar = (gcnew System::Windows::Forms::TextBox()); this->textBoxRecibir = (gcnew System::Windows::Forms::TextBox()); this->buttonEnviar = (gcnew System::Windows::Forms::Button()); this->serialPort1 = (gcnew System::IO::Ports::SerialPort(this->components)); this->SuspendLayout(); // // textBox_Enviar // this->textBox_Enviar->Location = System::Drawing::Point(78, 37); this->textBox_Enviar->Name = L"textBox_Enviar"; this->textBox_Enviar->Size = System::Drawing::Size(95, 20); this->textBox_Enviar->TabIndex = 0; // // textBoxRecibir // this->textBoxRecibir->Location = System::Drawing::Point(80, 117); this->textBoxRecibir->Name = L"textBoxRecibir"; this->textBoxRecibir->Size = System::Drawing::Size(92, 20); this->textBoxRecibir->TabIndex = 1; // // buttonEnviar // this->buttonEnviar->Location = System::Drawing::Point(203, 37); this->buttonEnviar->Name = L"buttonEnviar"; this->buttonEnviar->Size = System::Drawing::Size(99, 20); this->buttonEnviar->TabIndex = 2; this->buttonEnviar->Text = L"button1"; this->buttonEnviar->UseVisualStyleBackColor = true; this->buttonEnviar->Click += gcnew System::EventHandler(this, &Form1::buttonEnviar_Click); // // serialPort1 // this->serialPort1->BaudRate = 152000; this->serialPort1->PortName = L"COM6"; // // Form1 // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(498, 335); this->Controls->Add(this->buttonEnviar); this->Controls->Add(this->textBoxRecibir); this->Controls->Add(this->textBox_Enviar); this->Name = L"Form1"; this->Text = L"Form1"; this->ResumeLayout(false); this->PerformLayout();}
#pragma
endregion private: System::Void buttonEnviar_Click(System::Object^ sender, System::EventArgs^ e) { //Se ha pulsado click // Open the port for communicationsthis
->serialPort1->Open(); // Write a string this->serialPort1->Write("Hello World"); // Write a set of bytes this->serialPort1->Write(new byte[] {0x0A, 0xE2, 0xFF}, 0, 3);//Aqui me sale error que sera por el new byte // Close the port this->serialPort1->Close();
}
};
}
Perdona pero es que de C# ni idea.
¿Como puedo yo leer del COM6?- Marcado como respuesta jose-111 miércoles, 4 de marzo de 2009 9:53
-
bytes
this->serialPort1->Write(new byte[] {0x0A, 0xE2, 0xFF}, 0, 3);//Aqui me sale error que sera por el new byte En C++/CLI los arrays se definen como
array<unsigned char>, entonces, tu código quedaría como:
this->serialPort1->Write(gcnew array<unsigned char>() {0x0A, 0xE2, 0xFF}, 0, 3);- Marcado como respuesta jose-111 miércoles, 4 de marzo de 2009 9:53
-
Ya me funciona, es muy fácil una vez se sabe, jejeje.
Gracias a todos. El código me queda así:
private: System::Void button_Espacio_Click(System::Object^ sender, System::EventArgs^ e) {cli::
array<unsigned char> ^uno = gcnew cli::array<unsigned char>(1);cli::
array<unsigned char> ^dos = gcnew cli::array<unsigned char>(1); uno[0] = 0x20; //ASCII letra "Espacio".serialPort1->Write(uno, 0, 1);
serialPort1->Read(dos, 0, 1);
if (dos[0] == 0x21)//dos es una variable que recibe 0x21 de esta manera se que leo{
MessageBox::Show (
"Hola20");}
- Marcado como respuesta jose-111 miércoles, 4 de marzo de 2009 9:52
Todas las respuestas
-
si utilizas c++/CLI (es decir C++.net) puedes usar la clase SerialPort,
aca puedes ver como usarla, es muy sencillo.
http://msmvps.com/blogs/coad/archive/2005/03/23/SerialPort-_2800_RS_2D00_232-Serial-COM-Port_2900_-in-C_2300_-.NET.aspx
Juan Carlos Ruiz - http://juank.black-byte.com -
-
Es exactamente lo mismo...
cambian son puros detalles pero debes utilizar los mismos componentes y funciones.
Juan Carlos Ruiz - http://juank.black-byte.com- Marcado como respuesta jose-111 miércoles, 4 de marzo de 2009 9:53
-
Con esta ventana tengo una ventana para enviar y otra pararecibir, si al pulsar introduzco lo siguiente:
#pragma
once
namespace
comunicacion { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; /// <summary> /// Summary for Form1 /// /// WARNING: If you change the name of this class, you will need to change the /// 'Resource File Name' property for the managed resource compiler tool /// associated with all .resx files this class depends on. Otherwise, /// the designers will not be able to interact properly with localized /// resources associated with this form. /// </summary> public ref class Form1 : public System::Windows::Forms::Form{
public:Form1(
void){
InitializeComponent();
// //TODO: Add the constructor code here //}
protected: /// <summary> /// Clean up any resources being used. /// </summary>~Form1()
{
if (components){
delete components;}
}
private: System::Windows::Forms::TextBox^ textBox_Enviar; protected: private: System::Windows::Forms::TextBox^ textBoxRecibir; private: System::Windows::Forms::Button^ buttonEnviar; private: System::IO::Ports::SerialPort^ serialPort1; private: System::ComponentModel::IContainer^ components; private: /// <summary> /// Required designer variable. /// </summary>
#pragma
region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> void InitializeComponent(void){
this->components = (gcnew System::ComponentModel::Container()); this->textBox_Enviar = (gcnew System::Windows::Forms::TextBox()); this->textBoxRecibir = (gcnew System::Windows::Forms::TextBox()); this->buttonEnviar = (gcnew System::Windows::Forms::Button()); this->serialPort1 = (gcnew System::IO::Ports::SerialPort(this->components)); this->SuspendLayout(); // // textBox_Enviar // this->textBox_Enviar->Location = System::Drawing::Point(78, 37); this->textBox_Enviar->Name = L"textBox_Enviar"; this->textBox_Enviar->Size = System::Drawing::Size(95, 20); this->textBox_Enviar->TabIndex = 0; // // textBoxRecibir // this->textBoxRecibir->Location = System::Drawing::Point(80, 117); this->textBoxRecibir->Name = L"textBoxRecibir"; this->textBoxRecibir->Size = System::Drawing::Size(92, 20); this->textBoxRecibir->TabIndex = 1; // // buttonEnviar // this->buttonEnviar->Location = System::Drawing::Point(203, 37); this->buttonEnviar->Name = L"buttonEnviar"; this->buttonEnviar->Size = System::Drawing::Size(99, 20); this->buttonEnviar->TabIndex = 2; this->buttonEnviar->Text = L"button1"; this->buttonEnviar->UseVisualStyleBackColor = true; this->buttonEnviar->Click += gcnew System::EventHandler(this, &Form1::buttonEnviar_Click); // // serialPort1 // this->serialPort1->BaudRate = 152000; this->serialPort1->PortName = L"COM6"; // // Form1 // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(498, 335); this->Controls->Add(this->buttonEnviar); this->Controls->Add(this->textBoxRecibir); this->Controls->Add(this->textBox_Enviar); this->Name = L"Form1"; this->Text = L"Form1"; this->ResumeLayout(false); this->PerformLayout();}
#pragma
endregion private: System::Void buttonEnviar_Click(System::Object^ sender, System::EventArgs^ e) { //Se ha pulsado click // Open the port for communicationsthis
->serialPort1->Open(); // Write a string this->serialPort1->Write("Hello World"); // Write a set of bytes this->serialPort1->Write(new byte[] {0x0A, 0xE2, 0xFF}, 0, 3);//Aqui me sale error que sera por el new byte // Close the port this->serialPort1->Close();
}
};
}
Perdona pero es que de C# ni idea.
¿Como puedo yo leer del COM6?- Marcado como respuesta jose-111 miércoles, 4 de marzo de 2009 9:53
-
bytes
this->serialPort1->Write(new byte[] {0x0A, 0xE2, 0xFF}, 0, 3);//Aqui me sale error que sera por el new byte En C++/CLI los arrays se definen como
array<unsigned char>, entonces, tu código quedaría como:
this->serialPort1->Write(gcnew array<unsigned char>() {0x0A, 0xE2, 0xFF}, 0, 3);- Marcado como respuesta jose-111 miércoles, 4 de marzo de 2009 9:53
-
Ya me funciona, es muy fácil una vez se sabe, jejeje.
Gracias a todos. El código me queda así:
private: System::Void button_Espacio_Click(System::Object^ sender, System::EventArgs^ e) {cli::
array<unsigned char> ^uno = gcnew cli::array<unsigned char>(1);cli::
array<unsigned char> ^dos = gcnew cli::array<unsigned char>(1); uno[0] = 0x20; //ASCII letra "Espacio".serialPort1->Write(uno, 0, 1);
serialPort1->Read(dos, 0, 1);
if (dos[0] == 0x21)//dos es una variable que recibe 0x21 de esta manera se que leo{
MessageBox::Show (
"Hola20");}
- Marcado como respuesta jose-111 miércoles, 4 de marzo de 2009 9:52
-
Hola:Te puedes bajar el manual del control del puerto serie para Visual C++ y Visual Basic .net que hice en PDF hade tiempo.Saludo.
http://electronica-pic.blogspot.com -