free form msgs and negative values

Discuss issues and ideas you have to configuring displays with PowerVision
asadilan
Posts: 8
Joined: Fri Aug 02, 2013 12:38 pm

free form msgs and negative values

Post by asadilan » Wed Aug 14, 2013 2:47 pm

Hi All,

thanks for the help so far.
free form msgs, how is that sent by the device? is that in the blanket of PDO messages or SDO?

if i linked a variable with free form messages, when the variable is negative, how do i send this negative value?
usually, the MSB is the indicator if it is a positive or negative values. How can i do this? as of now, when the variable is positive, it sends with the correct value, when it is negative, it is stuck sending 0.

TIA
Asadilan
asadilan
Posts: 8
Joined: Fri Aug 02, 2013 12:38 pm

Re: free form msgs and negative values

Post by asadilan » Wed Aug 14, 2013 4:55 pm

can the device interpret data coming in as signed variable?
vtaylor
Posts: 13
Joined: Fri Jul 27, 2012 7:33 am

Re: free form msgs and negative values

Post by vtaylor » Wed Aug 14, 2013 5:42 pm

As I understand it, PDO or SDO messages in CANOpen are determined by the upper 4 bits of the CAN ID so the device can send either one depending on what you set the Frame ID to.

If you need to send negative values using the MSb as a sign bit, you could script it - if the value is negative, take the absolute value then bitwise or (|) with a bitmask that sets the MSb. (You could also do it with a state machine but it would be fairly complicated)

Code: Select all

int8 localValue;     //for 8 bit value
smRead(VariableIDs.databaseValue, localValue);
if (localValue < 0)
{
     //take the 2's complement
     localValue = (~localValue) + 1;    //you could also use abs(localValue)
     //bitmask
     localValue |= 0x80;    //for 8 bit value
}
smWrite(VariableIDs.databaseValue, localValue);
Another way to represent negative is by taking the 2's complement (this is the generally accepted way to represent negative integers). I really depends on what the device on the other end of the bus is expecting and/or what you're expecting to receive from it.

The way J1939 handles negative values is by defining an offset value in the SPN definition (e.g. temperatures are typically interpreted to be offset by -40°C so a received value of 30 would indicate -10°C).
Last edited by vtaylor on Wed Aug 14, 2013 6:37 pm, edited 1 time in total.
asadilan
Posts: 8
Joined: Fri Aug 02, 2013 12:38 pm

Re: free form msgs and negative values

Post by asadilan » Wed Aug 14, 2013 5:52 pm

Hi Vtaylor,

Thanks for replying.
I ll definietely look at the scripting side of PV450.

Thanks
Asadilan
vtaylor
Posts: 13
Joined: Fri Jul 27, 2012 7:33 am

Re: free form msgs and negative values

Post by vtaylor » Wed Aug 14, 2013 6:33 pm

asadilan wrote:can the device interpret data coming in as signed variable?
I don't think it can do that implicitly, but again if you know the data format you're expecting (bit length and how negative numbers are represented) you can use some manipulation in a script to turn it into whatever representation you need. The smRead and smWrite functions have some pretty slick type conversion abilities that can make it pretty easy if you use 2's complement format for negatives.
asadilan
Posts: 8
Joined: Fri Aug 02, 2013 12:38 pm

Re: free form msgs and negative values

Post by asadilan » Thu Aug 15, 2013 11:12 am

Hi VTaylor,

would it be something like this?
void $ConvertSignedToUnsigned32$ ()
{
uint localValue =0;
int value =0;
smRead(VariableIDs.CurrentPortManual,localValue);
smRead(VariableIDs.CurrentPortManual,value);

smWrite(VariableIDs.temp,int(VariableIDs.CurrentPortManual));
smWrite(VariableIDs.temp2,value);
processScreenApi();

}

where am i wrong here?
ksaenz
Enovation Controls Development
Enovation Controls Development
Posts: 263
Joined: Thu Aug 19, 2010 7:53 am

Re: free form msgs and negative values

Post by ksaenz » Thu Aug 15, 2013 2:49 pm

Here is what I use:

Code: Select all

double utos( double x )
{
	uint16 u;
	int16 s;	

	u = x;
	s = u & 0xFFFF;
	x = s;	

	return x;
}

Code: Select all

double stou( double x )
{
	uint16 u;
	int16 s;	

	s = x;
	u = s & 0xFFFF;
	x = u;	

	return x;
}
asadilan
Posts: 8
Joined: Fri Aug 02, 2013 12:38 pm

Re: free form msgs and negative values

Post by asadilan » Mon Aug 19, 2013 12:09 pm

vtaylor wrote:As I understand it, PDO or SDO messages in CANOpen are determined by the upper 4 bits of the CAN ID so the device can send either one depending on what you set the Frame ID to.
free form msg for Standard Frame Send allows me to send packet with id between 0 - 0x7FF.
according to CANopen specs, PDO is packet with id above 0x1400, hence my question.

i don't have a protocol analyser that would tell me how this free form msgs sent in the data from pv450.
if anyone can tell me, that will be great.

Thanks in advance,
Asadilan
mbowdich
Posts: 209
Joined: Tue Oct 05, 2010 10:54 am

Re: free form msgs and negative values

Post by mbowdich » Wed Aug 21, 2013 8:49 am

It is not possible to have a CANOpen Id above 0x7FF. CANOpen is implemented using 11 bit identifiers, which means the upper limit is 0x7FF (all 11 bits are 1s). If you look at the specification more carefully, you will see that it states that the PDO Index is >0x1800 for producers and >0x1400 for consumers. The index is not the CANId.