Click here to Skip to main content
15,508,644 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
GeneralRe: How to pass a function pointer an argument in managed C++ Pin
yehiga146724-May-21 17:44
yehiga146724-May-21 17:44 
AnswerRe: How to pass a function pointer an argument in managed C++ Pin
Richard Andrew x6424-May-21 5:28
professionalRichard Andrew x6424-May-21 5:28 
QuestionConvert Native Pointer to IntPtr Pin
Richard Andrew x6422-May-21 5:44
professionalRichard Andrew x6422-May-21 5:44 
AnswerRe: Convert Native Pointer to IntPtr Pin
Richard MacCutchan22-May-21 5:47
mveRichard MacCutchan22-May-21 5:47 
GeneralRe: Convert Native Pointer to IntPtr Pin
Richard Andrew x6422-May-21 5:51
professionalRichard Andrew x6422-May-21 5:51 
QuestionBackgammon Game Pin
basel3322-May-21 3:25
basel3322-May-21 3:25 
AnswerRe: Backgammon Game Pin
Richard MacCutchan22-May-21 4:13
mveRichard MacCutchan22-May-21 4:13 
QuestionSerial Port BytesToRead always 0 Pin
yehiga146721-May-21 1:16
yehiga146721-May-21 1:16 
Hello everyone,

I made a class that will do some additional configuration to the serial port. (Mainly to handle received data).
My issue is that SerialPort_DataReceived() is successfully triggered when it received data from device, however the BytesToRead is always 0. What could the reason be? I am sure the device is sending data because when I haven't use this ConfigSerialPort, everything works fine.


ConfigSerialPort.h
#pragma once
using namespace System::Windows::Forms;

ref class ConfigSerialPort: public System::Windows::Forms::Control
{

	private: System::IO::Ports::SerialPort^ _serialPort;
	
	public:
		ConfigSerialPort(System::IO::Ports::SerialPort^ serialPort) {
			_serialPort = serialPort;
			
        //handle received data
			_serialPort->DataReceived += gcnew System::IO::Ports::SerialDataReceivedEventHandler(this, &ConfigSerialPort::SerialPort_DataReceived);
		
		}
		
	private: 	System::Void SerialPort_DataReceived(System::Object^ sender, System::IO::Ports::SerialDataReceivedEventArgs^ e)
    {
        unsigned int test = 0;

        test = _serialPort->BytesToRead; // BytesToRead is ALWAYS Zero
    }

}



MyForm.h
#pragma once

#include <stdlib.h>
#include <string.h>
#include <cstdint>
#include <stdio.h>
#include "ConfigSerialPort.h"



namespace SerialPortGUI {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	using namespace System::IO;
	using namespace System::Runtime::Serialization::Formatters::Binary;






	/// <summary>
	/// Summary for MyForm
	/// </summary>
	public ref class MyForm : public System::Windows::Forms::Form
	{
		public:
			MyForm(void)
			{
				InitializeComponent();
				//
				//TODO: Add the constructor code here
				//
			}
			.
			.
			.
			
			
			void InitializeComponent(void)
			{
				.
				.
				.
				this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
			   this->MyForm_SerialPort = (gcnew System::IO::Ports::SerialPort(this->components));
			   
				.
				.
				.

			}
		private: ConfigSerialPort^ test;
		private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e) {
		
		// initialize Serial port (already done via the designer)
		test = gcnew ConfigSerialPort(MyForm_SerialPort);
		
		}
	}
			
}

QuestionRe: Serial Port BytesToRead always 0 Pin
Richard MacCutchan21-May-21 1:59
mveRichard MacCutchan21-May-21 1:59 
AnswerRe: Serial Port BytesToRead always 0 Pin
cibec75455@frnla.com21-May-21 2:29
cibec75455@frnla.com21-May-21 2:29 
GeneralRe: Serial Port BytesToRead always 0 Pin
Richard MacCutchan21-May-21 2:38
mveRichard MacCutchan21-May-21 2:38 
GeneralRe: Serial Port BytesToRead always 0 Pin
cibec75455@frnla.com21-May-21 2:47
cibec75455@frnla.com21-May-21 2:47 
QuestionHow to call System::Windows::Forms::Controls "invoke" method? Pin
Member 1515077819-May-21 20:48
Member 1515077819-May-21 20:48 
AnswerRe: How to call System::Windows::Forms::Controls "invoke" method? Pin
Victor Nijegorodov19-May-21 21:28
Victor Nijegorodov19-May-21 21:28 
GeneralRe: How to call System::Windows::Forms::Controls "invoke" method? Pin
Member 1515077819-May-21 21:35
Member 1515077819-May-21 21:35 
GeneralRe: How to call System::Windows::Forms::Controls "invoke" method? Pin
Richard MacCutchan19-May-21 22:09
mveRichard MacCutchan19-May-21 22:09 
GeneralRe: How to call System::Windows::Forms::Controls "invoke" method? Pin
Member 1515077819-May-21 22:20
Member 1515077819-May-21 22:20 
QuestionWhat is a preferable approach to develop a common class that handles multiple identical groupbox? Pin
Member 1515077818-May-21 1:41
Member 1515077818-May-21 1:41 
QuestionHow to convert array<System::Byte^>^ to array<unsigned char>^ Pin
Member 1515077812-May-21 19:19
Member 1515077812-May-21 19:19 
QuestionRe: How to convert array<System::Byte^>^ to array<unsigned char>^ Pin
Richard MacCutchan12-May-21 22:05
mveRichard MacCutchan12-May-21 22:05 
AnswerRe: How to convert array<System::Byte^>^ to array<unsigned char>^ Pin
Member 1515077817-May-21 1:06
Member 1515077817-May-21 1:06 
QuestionHow to implement a global variable if C++/CLI doesn't support it at all? Pin
Member 1515077812-May-21 0:29
Member 1515077812-May-21 0:29 
AnswerRe: How to implement a global variable if C++/CLI doesn't support it at all? Pin
Richard MacCutchan12-May-21 0:47
mveRichard MacCutchan12-May-21 0:47 
GeneralRe: How to implement a global variable if C++/CLI doesn't support it at all? Pin
Member 1515077812-May-21 19:30
Member 1515077812-May-21 19:30 
Questioncpp Pin
likith adithya22-Feb-21 0:39
likith adithya22-Feb-21 0:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.