Welcome to %s forums

BrainModular Users Forum

Login Register

Need help for Get

Create your own modules in C++
Post Reply
hesspet
Member
Posts: 92
Location: Germany
Contact:

Unread post by hesspet » 01 Dec 2012, 15:17

Sorry for the incomplete posting header: "Need help for GetEvtPChar" :-)

I need an explanation for something I didn't understand.

I made this implementation (read a string from a pin and echo the result to a pin)

Code: Select all

if (Message->lParam == MSG_CHANGE) 
		{		
			PCHAR pcharTheInputString = pSerialInfoModule->GetEvtPChar( pSerialInfoModule->m_txtfExampleIn );
			int lengthOfInputString = pSerialInfoModule->GetEvtSize(pSerialInfoModule->m_txtfExampleIn);
			pSerialInfoModule->SetEvtSize(pSerialInfoModule->m_txtfExampleOut, lengthOfInputString);
			pSerialInfoModule->SetEvtPChar(pSerialInfoModule->m_txtfExampleOut, pcharTheInputString);
		}
I tested a little bit with my implementation and it failed. A problem occurs. I write a string to the text field "asdfasdf" and everything works fine. In the output textfield the text ist "asdfasdf". Then I write "asdf" into the text field and in the output "asdf" should be echoed, but it shows "2" or "3" or something like that. Tested it with "a", "as", "asd" and so on. The echoed string is correct after "asdff". What happens here? Something strange! After some tests, I found out, that the problem has something to do with the reading of the input pin (GetEvtPChar), not with the output pin. Here's the line which reads the string from the pin:

Code: Select all

PCHAR pcharTheInputString = pSerialInfoModule->GetEvtPChar( pSerialInfoModule->m_txtfExampleIn );
the definition of GetEvtPChar in the header is:

Code: Select all

PCHAR GetEvtPChar( TEVT* ev )
and PCHAR is defined as

Code: Select all

typedef CHAR *PCHAR, *LPCH, *PCH;
PCHAR! So this normally means, the we have here a terminated char array. But stop, Usine is developed in Delphi (don't know where I get this info :-) and Delphi uses the Pascal string type and in C++ there is also a Pascal like string type available. This could be a reason, cause in the first bytes of such a string the length of the string is coded and this can leads to troubles if you use the string as a C-String type. I tried:

Code: Select all

std::string strTheInputString = pSerialInfoModule->GetEvtPChar( pSerialInfoModule->m_txtfExampleIn );
            PCHAR pcharTheInputString = (PCHAR) strTheInputString.c_str();
and "wonder wonder..." the problems disapears and my code works fine. But using the std::string as input here

Code: Select all

pSerialInfoModule->SetEvtPChar(pSerialInfoModule->m_txtfExampleOut,  strTheInputString);
won't work. I must use

Code: Select all

PCHAR pcharTheInputString = (PCHAR) strTheInputString.c_str();
pSerialInfoModule->SetEvtPChar(pSerialInfoModule->m_txtfExampleOut, pcharTheInputString);
I get a Pascal string, but I must send a C-Type string???? Mmh... I didn't understand this. Looks like a not clear implementation of the interface or I'm on a wrong path. Can someone give me an hint :-)

Thanks.

Peter

P.S.: Yes, I know the simple way :-)

Code: Select all

pSerialInfoModule->CopyEvt( pSerialInfoModule->m_txtfExampleIn,pSerialInfoModule->m_txtfExampleOut );
but I try to understand the SDK...
+++ journeytounknownsoundscapes.blogspot.de +++
+++ DIY electronics +++ musical experiments +++ light experiments +++

martignasse
Site Admin
Posts: 611
Location: Lyon, FRANCE
Contact:

Unread post by martignasse » 02 Dec 2012, 14:16

hi hesspet,

i saw that you are working on a serial module communication, cool
and sorry for the delayed response

first of all, i tried to reproduce the problem with a test module, but it's working fine on my side

can you put a break point in the callback and inspect what you have from the GetEvtPChar() ?
the PCHAR pcharTheInputString should be a classic C char* string, not a pascal string
and the GetEvtSize() should return the size of the string without the terminal
Martin FLEURENT - Usine Developer - SDK maintainer

hesspet
Member
Posts: 92
Location: Germany
Contact:

Unread post by hesspet » 02 Dec 2012, 22:46

Hello Martin,

yes I'll make you a complete error report, but now I'm working fulltime on the serial module, so this must wait :-)

At the evening, the first data was send from Usine over Usb serial to the Ardino. Everything is in prototype state, but it looks, that I can realize the serial module until the end of the year. Today I found a nice way to have a plattform independent solution. I used the "boost" lib and I hope I finish with this, so a port to the Mac would be very simple.

I'll post the debug results here. The described "problem" is not a show stopper :-)

Peter
+++ journeytounknownsoundscapes.blogspot.de +++
+++ DIY electronics +++ musical experiments +++ light experiments +++

martignasse
Site Admin
Posts: 611
Location: Lyon, FRANCE
Contact:

Unread post by martignasse » 02 Dec 2012, 23:10

ok, cool

so good work, can't wait to see the result :P

and i'm interested in the way you use the boost lib, if you don't care
Martin FLEURENT - Usine Developer - SDK maintainer

hesspet
Member
Posts: 92
Location: Germany
Contact:

Unread post by hesspet » 03 Dec 2012, 22:39

It a nice lib. Follow my diary:

Exploration into the Usine SDK (Writing a Serial Communication Module - Part 8

This is the documentation of the work allready done. Also the first steps with boost. :-) and all the wrong pathes... my C++ knowledge is a little bit old. The last C++ I've made ist 10 or 15 years ago and many things are new for me. So don't laugh about my problems :-)
+++ journeytounknownsoundscapes.blogspot.de +++
+++ DIY electronics +++ musical experiments +++ light experiments +++

martignasse
Site Admin
Posts: 611
Location: Lyon, FRANCE
Contact:

Unread post by martignasse » 04 Dec 2012, 12:17

cool,

lots of reading and some precious feedback

and don't hesitate if you need some help or explanation

keep up the good work
Martin FLEURENT - Usine Developer - SDK maintainer

Post Reply

Who is online

Users browsing this forum: No registered users and 112 guests