Tango::DEV_CHAR is missing

I'm trying to find unsigned char type for the argument type.

There's nothing like DEV_CHAR.
I can find DEV_UCHAR, though.

Please somebody explains why this type is missing?


I'm trying to do something like

if(!myevent->err){
    switch(myevent->attr_value->get_type()){
	case Tango::DEV_BOOLEAN:
	{
	    *myevent->attr_value >> boolean_value[index]; 
	    break;
	}
	case Tango::DEV_UCHAR:
	{
	    *myevent->attr_value >> unsignedchar_value[index]; 
	    break;
	}
	case Tango::DEV_CHAR: => missing
	{

Edited 8 years ago
This type is not supported, I cannot really give a strong reason for that. It is of little usage since you will never receive any event with this type, you have just to skip this case in your statement.

Cheers
Jean-Michel
I think the reason is that DEV_CHAR is a subset of DEV_UCHAR. DEV_UCHAR is a string of bytes of known length (array of bytes) while DEV_CHAR is a string of bytes terminated by a null character (a string). Therefore DEV_CHAR can be passed via DEV_UCHAR.

Andy

Actually what I want is not parsing the event.
What I want is filling the protocol frame passed by CORBA::Any value.


bool fillFrame(char* pDataPtr, Tango::CmdArgType dataType, const CORBA::Any& newValue)
{
    switch(dataType)
    {
    case Tango::DEV_SHORT:
    case Tango::DEV_USHORT:
        {
        Tango::DevUShort argin;
        newValue >>= argin;
        *pDataPtr = HIBYTE(argin);
        *(pDataPtr+1) = LOBYTE(argin);
        }
        break;
    case Tango::DEV_BOOLEAN:
        {
        Tango::DevBoolean argin;
        newValue >>= argin;
        *pDataPtr = (argin == 0x1) ? '1' : '0';    // Bit Value (ASCII, Set=’1’, Reset=’0’)
        }
        break;

    case Tango::DEV_CHAR:    // this is OK
    case Tango::DEV_UCHAR:    // this leads to error
        {
        Tango::DevUChar argin;
        newValue >>= argin;
        *pDataPtr = argin;
        }
        break;

    case Tango::DEV_FLOAT:
        {
            Tango::DevFloat argin;
            newValue >>= argin;
            char* pTmp = (char*)(&argin);
            *pDataPtr = *pTmp++;
            *(pDataPtr+1) = *pTmp++;
            *(pDataPtr+2) = *pTmp++;
            *(pDataPtr+3) = *pTmp++;
        }
        break;
    case Tango::DEV_ULONG:
    case Tango::DEV_LONG:
        {
        Tango::DevULong argin;
        newValue >>= argin;
        *pDataPtr = HIBYTE(HIWORD(argin));
        *(pDataPtr+1) = LOBYTE(HIWORD(argin));
        *(pDataPtr+2) = HIBYTE(LOWORD(argin));
        *(pDataPtr+3) = LOBYTE(LOWORD(argin));
        }
        break;
    default:
        assert(FALSE);
        return false;
    }

    return true;
}
Edited 8 years ago
I'm looking forward to know in which context you need to do that.
Just curious, what 'pDataPtr' is supposed to be used for?
Edited 8 years ago
I correct my previous post - I thought you were referring to arrays of char but in fact you were referring to a single char. I also do not know why we have not defined DevChar. Maybe there is a reason but I don't know it …

nleclercq
I'm looking forward to know in which context you need to do that.
Just curious, what 'pDataPtr' is supposed to be used for?

I was trying to change my original code using Tanggo::CmdArgType.

The original code was

enum _DATATYPE
{
  _DATA_BOOL,
  _DATA_CHAR,
  _DATA_BYTE,
  _DATA_SHORT,
  _DATA_WORD,
  _DATA_LONG,
  _DATA_DWORD,
  _DATA_FLOAT,
  _DATA_DOUBLE,
  _DATA_STRING_HANDLE,
  _DATA_STRING,
  _DATA_FIXEDLENGTH_STRING,
  _DATA_ARRAY_BOOL,
  _DATA_ARRAY_CHAR,
  _DATA_ARRAY_BYTE,
  _DATA_ARRAY_SHORT,
  _DATA_ARRAY_WORD,
  _DATA_ARRAY_LONG,
  _DATA_ARRAY_DWORD,
  _DATA_ARRAY_FLOAT,
  _DATA_ARRAY_DOUBLE,
  _DATA_ARRAY_STRING,
  _DATA_ARRAY_FIXEDLENGTH_STRING,
};

typedef union _DATAVALUE
{
  WORD                onoff;
  char                c;
  BYTE                b;
  short               s;
  WORD                w;
  LONG                l;
  DWORD               dw;
  float               f;
  double              db;
  LPSTR               h_str;
  LP_FIXEDLENGTH h_flstr;
  HANDLE              handle_str;
  void FAR            *ptr;

} DATAVALUE;

And the original function was
bool fillFrame(char* pDataPtr, _DATATYPE dataType, const DATAVALUE& newValue)


The usage samples are;

char frame[MAX_FRAME_LEN];
DATAVALUE value;

value.onoff = TRUE;
filFrame(frame, _DATA_BOOL, value);
sendToDevice(frame);

value.f = 15.345;
fillFrame(frame, _DATA_FLOAT, value);
sendToDevice(frame);

value.c = 'a';
fillFrame(frame, _DATA_CHAR, value);  // I can do this
sendToDevice(frame);

value.b = 0xFC;
fillFrame(frame, _DATA_BYTE, value);  // I cannot do this
sendToDevice(frame);




Jean-Michel
This type is not supported, I cannot really give a strong reason for that. It is of little usage since you will never receive any event with this type, you have just to skip this case in your statement.

As Jean-Michel said, this type is not useful in real fields.
This question is just from my curiosity smile
Edited 8 years ago
I thought using tango DeviceAttribute is only for my own internal purpose.
But when I see one of the devices called ModbusComposer under Calculation, I found similar switch/case samples like below;

double ModbusComposer::read_self_attribute(char *attName) {

  Tango::DeviceAttribute da;
  da = selfDS->read_attribute(attName);

  switch(da.get_type()) {

    case Tango::DEV_BOOLEAN:
    {
      Tango::DevBoolean v;
      da >> v;
      return (double)v;
    }
    break;
    case Tango::DEV_SHORT:
    {
      Tango::DevShort v;
      da >> v;
      return (double)v;
    }
    break;
    case Tango::DEV_LONG:
    {
      Tango::DevLong v;
      da >> v;
      return (double)v;
    }
    break;
    case Tango::DEV_DOUBLE:
    {
      Tango::DevDouble v;
      da >> v;
      return v;
    }
    break;   
    default:
       Tango::Except::throw_exception(
         (const char *)"ModbusComposer::error_read",
         (const char *)"Cannot read attribute (type not supported)",
         (const char *)"ModbusComposer::read_self_attribute");

  }

  return 0.0;

}

In my opinion, the initial designers do not see any necessity for the DEV_CHAR.
But it is still not clear why DEV_USHORT and DEV_SHORT, or DEV_LONG and DEV_ULONG then.

BTW, somebody let me know how to post code lines.
They looks ugly not supporting indent chars(such as tab char). smile

Edited 8 years ago
naver
They looks ugly not supporting indent chars(such as tab char). smile
There's a "code" icon the message editor tool bar.

for (;;;) dance("tango");

Edited 8 years ago
 
Register or login to create to post a reply.