# I have a trouble with new types in python!

**URL:** <https://www.ruby-forum.com/t/i-have-a-trouble-with-new-types-in-python/240953>\
**Category:** GNU Radio\
**Created:** [May 7, 2014, 3:02pm UTC](https://www.ruby-forum.com/t/i-have-a-trouble-with-new-types-in-python/240953 "2014-05-07T15:02:03Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [May 7, 2014, 3:02pm UTC](https://www.ruby-forum.com/t/i-have-a-trouble-with-new-types-in-python/240953/1 "2014-05-07T15:02:03Z")

</div>

Hello everybody,  
I have a new type in my gnuradio blocks which are defined in c++.  
However,  
the GRC don’t know them.  
\*The first question is how I could make GRC of such blocks? \*

I think if I could be able to define them in python I could add new  
types  
to the GRC of the block.  
Although I’m not so familiar with python, I want to define new type as  
it  
was previously defined in c++ as :

\*typedef unsigned char bit; \*

\*how could I define such variable in python!!!? \*(may it helps me to  
make  
my GRC block)

Thank,

---

<div class="post-metadata">

**Author:** ![mostafa\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mostafa\_a](https://www.ruby-forum.com/u/mostafa_a)\
**Post date:** [May 8, 2014, 9:38am UTC](https://www.ruby-forum.com/t/i-have-a-trouble-with-new-types-in-python/240953/2 "2014-05-08T09:38:49Z")

</div>

Hi Marcus,  
Thank you very much for your explicit explanations. Yeah, I found it so  
hard to do what I thought. As you said I determined the type as “byte”  
and  
there is no problem. But there is another problem! I have defined  
something  
like this in c++:

#define X 0x01864CFB

and I should pass X, instead of this 0x01864CFB which is 32 bits number  
to  
my “make” function of my block.

What do you prefer for making a GRC xml file for this block?

best,

---

<div class="post-metadata">

**Author:** ![mostafa\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mostafa\_a](https://www.ruby-forum.com/u/mostafa_a)\
**Post date:** [May 8, 2014, 10:34am UTC](https://www.ruby-forum.com/t/i-have-a-trouble-with-new-types-in-python/240953/3 "2014-05-08T10:34:47Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

Hi Mostafa,

On 07.05.2014 16:34, Mostafa A. wrote:

> #define X 0x01864CFB

Attention! This is a preprocessing define. This means that /prior/ to  
compilation, all occurences of X will be replaced by 0x01…, so your  
compiler will never see X.

Is it possible that you want to define a default option for your make  
function? That works! you can just have a make function with a  
function stub like  
…::make(int param1, float param2, unsigned char param3, int param4 =  
0x0186);

Again, XML files are only useful for defining the graphical  
representation of a GNU Radio block in GRC, it’s not meant to define  
constants. There are ways to do that, but most of the time it’s not  
what you want.  
You can set default values for input fields in the block options, you  
can also do dropdown menus. I don’t know what you’re really trying to  
do, so you might be best of to look at different blocks in GRC and  
find one that fits your problem best, and copy that block’s XML.

Greetings,  
Marcus

> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:
> 
> > SWIG will generate wrapper code to make these classes (which are  
> > neither python, nor GNU Radio care about the type; they just care
> > 
> > > Hello everybody, I have a new type in my gnuradio blocks which  
> > > \*how could I define such variable in python!!!? \*(may it helps
> 
> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ Discuss-gnuradio  
> mailing list [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [Discuss-gnuradio Info Page](https://lists.gnu.org/mailman/listinfo/discuss-gnuradio)

-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1  
Comment: Using GnuPG with Thunderbird - [http://www.enigmail.net/](http://www.enigmail.net/)

iQEcBAEBAgAGBQJTalFKAAoJEBQ6EdjyzlHtRHwIAJnlorrctCzyARolZl4gc6mJ  
7gTeGZc43oGj/1Ise3I7lqcY7lmBMkErGDLiKWsyWYOW0HTSHobDQr9xOY/UK5j+  
HtaFAec2WeX9spTLNUBg87ZLTJlWBjoEvl6nT9xvbJSXDvoIBzF1cQ7EY1TkVU5V  
zLWRxwMA1G6LeP9JGCuxlA1t92hP7gLR+UOoff1EmWx2HbwF4Jin8frn6irrzqpi  
SCQ3X5VoMT2/vX10lFgbumEUhijTr5q9m3JvMIA2n7CBdq5SrLEpqjgZIHUPUxOs  
nAN9h6UZ8mSfAvxjik8X1frDpp0rJxl2iZH+r69OILBAt+nQQJzb88LHyRh7UyQ=  
=bJMO  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![mostafa\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mostafa\_a](https://www.ruby-forum.com/u/mostafa_a)\
**Post date:** [May 8, 2014, 10:49am UTC](https://www.ruby-forum.com/t/i-have-a-trouble-with-new-types-in-python/240953/4 "2014-05-08T10:49:33Z")

</div>

Hello  
Thank you so much.I have already read all the wiki somedays  
before.But i find it’s difficult to write my own application.Have you  
some tutorials?And how do you be familiar with this area?Any advices  
will be appreciated.So many people want to learn it but no good ways to  
touch it.  
Best regards,  
Xianda Wang

---

<div class="post-metadata">

**Author:** ![mostafa\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mostafa\_a](https://www.ruby-forum.com/u/mostafa_a)\
**Post date:** [May 8, 2014, 11:59am UTC](https://www.ruby-forum.com/t/i-have-a-trouble-with-new-types-in-python/240953/5 "2014-05-08T11:59:05Z")

</div>

Hi Marcus,  
I actually have a deep, really deep, problem with data types!!! As you  
see I have a preprocessor definition which is 32 bit number. I wanna  
pass  
it to the make!!! how could I? If I use the gnuradio type " gr\_uint32",  
after turning my c+±written blocks, the GRC tells me:

_TypeError: in method ‘xxxx\_make’, argument 1 of type ‘gr\_uint32’_

I put an option to the xml file :

- 

```
   <name>CRC16</name>*

```

- 

```
   <key>gr_uint32</key>*

```

- 

```
   <opt>CRC_type:0x00011021</opt>*

```

I know that this is not true, but I want to pass a 32-bit number to the  
“make”. How could I do?

please help me,

best,

---

<div class="post-metadata">

**Author:** ![mostafa\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mostafa\_a](https://www.ruby-forum.com/u/mostafa_a)\
**Post date:** [May 8, 2014, 2:50pm UTC](https://www.ruby-forum.com/t/i-have-a-trouble-with-new-types-in-python/240953/6 "2014-05-08T14:50:07Z")

</div>

Hi Activecat,  
On 08.05.2014 14:14, Activecat wrote:

> Anyone correct me if I am wrong.
> 
> In xml file we use the Python data types.  
> well, kind of. The XML is just being parsed by GRC to validate the input  
> of a field, color things etc.  
> However, there are only mappings in grc/python/Param.py for the  
> correctly wrappable python types.  
> You won’t be able to have a let’s say some Python class as param type in  
> GRC.

Greetings,  
Marcus

---

<div class="post-metadata">

**Author:** ![mostafa\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mostafa\_a](https://www.ruby-forum.com/u/mostafa_a)\
**Post date:** [May 8, 2014, 2:16pm UTC](https://www.ruby-forum.com/t/i-have-a-trouble-with-new-types-in-python/240953/7 "2014-05-08T14:16:52Z")

</div>

On Thu, May 8, 2014 at 12:53 AM, Mostafa A.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> - 
> 
> ```
> <name>CRC16</name>*
> 
> ```
> 
> - 
> 
> ```
> <key>gr_uint32</key>*
> 
> ```
> 
> - 
> 
> ```
> <opt>CRC_type:0x00011021</opt>*
> 
> ```
> 
> I know that this is not true, but I want to pass a 32-bit number to the  
> “make”. How could I do?

Anyone correct me if I am wrong.

In xml file we use the Python data types.  
In usual case Python doesn’t distinguish among “unsigned” or “signed”  
integer, this is different from c++.  
The casting will be intelligently handled by swig.

Hence, for your case, just pass “gr\_uint32” to the make() assuming your  
block is coded in c++. Then use “int” in the xml file.  
This  
solves your problem.

Meanwhile, C preprocessor does not know types or C keywords.

---

<div class="post-metadata">

**Author:** ![mostafa\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mostafa\_a](https://www.ruby-forum.com/u/mostafa_a)\
**Post date:** [May 8, 2014, 3:55pm UTC](https://www.ruby-forum.com/t/i-have-a-trouble-with-new-types-in-python/240953/8 "2014-05-08T15:55:21Z")

</div>

On Thu, May 8, 2014 at 9:33 PM, Tom R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > correctly wrappable python types.  
> > builds for you, including a list of all possible data types.
> 
> Tom

That is very clear.  
Thank you very much.

---

<div class="post-metadata">

**Author:** ![mostafa\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mostafa\_a](https://www.ruby-forum.com/u/mostafa_a)\
**Post date:** [May 8, 2014, 3:35pm UTC](https://www.ruby-forum.com/t/i-have-a-trouble-with-new-types-in-python/240953/9 "2014-05-08T15:35:37Z")

</div>

On Thu, May 8, 2014 at 8:48 AM, Marcus Müller  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> GRC.
> 
> Greetings,  
> Marcus

Yes, GRC isn’t a complete language and doesn’t implement things like it  
is.  
There are only a subset of possible data types. Using “gr\_modtool add”  
to  
create a new block nicely gives you a lot of hints in the XML file it  
builds for you, including a list of all possible data types.

Tom

---

<div class="post-metadata">

**Author:** ![mostafa\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5e9695/32.png) [@mostafa\_a](https://www.ruby-forum.com/u/mostafa_a)\
**Post date:** [May 9, 2014, 7:43am UTC](https://www.ruby-forum.com/t/i-have-a-trouble-with-new-types-in-python/240953/10 "2014-05-09T07:43:37Z")

</div>

On Thu, May 8, 2014 at 8:24 PM, Mostafa A.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> Activecat your right,  
> I finally got what you said. Types in Python are so different than that of  
> c++.  
> For example, Python doesn’t care the data is int or usigned int !

Pls stay on the list so that others know your problem has been solved.
