12-17-2013 01:52 PM
I need some help converting this c Stuct into labVIEW so that I can send a UDP packet to a BiRA power supply controller model # 1253.
The specific struct is this...from documents sent from BiRA
Set Power Supply Current Ramp (0xC1 and 0xC2)
The 0xC1 and 0xC2 commands set the power supply current and return status bytes 0 and 1. For the message to be processed successfully, the power supply must be turned on in remote mode and not presently ramping. If the ramp state is hold, the current ramp is aborted and the new request is processed.
The 0xC1 and 0xC2 commands are the same except that the 0xC1 command starts ramping immediately while the 0xC2 puts the ramp in the hold state waiting for a hardware ramp signal.
Each command can specifiy from 1 to 5 individual ramp setpoints. The setpoint defines the current at the end of the ramp and the time of the ramp.
The ramp time is specified by an unsigned 16 bit word. The units are 0.01 seconds for normal ramping or 0.05 for slow ramping, configured by the Daughter board EEPROM. Commands with zero ramp time(s) are rejected.
typedef struct // setpoint
{
float Cur; // Power supply current **
WORD Time; // time in 1/100 second or 1/20 second (slow ramp)
} __attribute__ ((packed)) setp;
typedef struct // 0xC1 and 0xC2 command structure
{
BYTE Ctype; // 00 command type 0xC1 or 0xC2
BYTE Rsp; // 01 response code
BYTE Tid; // 02 Task ID
BYTE Num; // 03 Number of setpoints (1 to 5)
BYTE Chan; // 04 Channel number (must be zero)
setp Setpoint[5]; // 05-10, 16, 22, 26, 32, Setpoint 1 to 5
} __attribute__ ((packed)) Cmd_C1;
#define CMD_LEN_C1 5 // expected length of command message without setpoints
#define CMD_LEN_SP 6 // length of each setpoint
typedef struct // 0xC1 and 0xC2 response structure
{
BYTE Ctype; // 00 command type, returned unchanged
BYTE Rsp; // 01 response code
BYTE Tid; // 02 Task ID, returned unchanged
BYTE Chan; // 03 Channel, returned unchanged
WORD Status01; // 04-05 Status bytes 0 and 1
} __attribute__ ((packed)) Rsp_C1;
#define RSP_LEN_C1 6 // length of response message
** Negated when in reverse polarity
When I use their utility to send the packet, using wireshark this is what I get.c1:ff:6c:01:00:00:00:c8:42:01:00 This sends a command of C1 with a current setting of 100 and a ramp time of .01.
What I would like to do is leave everything as is and only change the current setting. Just not sure how to build this into a packet and send it over UDP.
Attached is the full command file sent from BiRA.
Note: BiRA does not know how to do this either, nor will they give us source code to look at their utility.
Thanks for any help
12-17-2013 02:10 PM - edited 12-17-2013 02:11 PM
Hi Joe,
you can "translate" by this scheme:
struct = Cluster
byte = U8
word = U16
float = SGL (AFAIK, never coded in C a lot - but it is in line with the size numbers given in your message)
So a "setpoint" is a cluster of (SGL, U16).
A Command is a cluster of (5*U8, 5*setpoint).
A response is a cluster of (4*U8, U16).
Just start with that apporach...
12-17-2013 02:18 PM
Also, based on your wireshark sample line, your transmission is little endian for the float current and the U16 time. Keep that in mind when you're packing your UDP string.
12-17-2013 03:02 PM
GerdW how do i send a cluster over UDP. Do i just wire the cluster straight in to the UDP Write command. or do i need to do a flatten to string? how do I tell LabVIEW to switch from little endian to big endian or vice versa.
i appreciate all the help so far.
another thing, for the setpoints wouldnt I have to do an array of cluster of two elements?
12-17-2013 03:25 PM
@Joe_H wrote:
how do I tell LabVIEW to switch from little endian to big endian or vice versa.
flatten to string has an input for byte order.
12-17-2013 03:30 PM
You'll need to flatten to string before UDP Write.
Flatten to String has an input for selecting endianness.
An array of setpoints might not flatten the way you'd expect it too. (See LabVIEW Help for Flatten to String about size information)
A cluster of clusters would probably flatten correctly. In that case you would always be sending exactly 5 setpoints though.
For your use case, will you be sending variable number of setpoints? If so, you might want to consider writing your own string generator instead of using Flatten to String.
12-18-2013 12:11 PM
Taki1999 wrote:
An array of setpoints might not flatten the way you'd expect it too. (See LabVIEW Help for Flatten to String about size information)
A cluster of clusters would probably flatten correctly. In that case you would always be sending exactly 5 setpoints though.
For your use case, will you be sending variable number of setpoints? If so, you might want to consider writing your own string generator instead of using Flatten to String.
That is why there is also an input on the Flatten to String to prepend the Array/String size. It is a Boolean input. Otherwise it will be just fine.
12-18-2013 12:19 PM - edited 12-18-2013 12:32 PM
@crossrulz wrote:
Taki1999 wrote:
An array of setpoints might not flatten the way you'd expect it too. (See LabVIEW Help for Flatten to String about size information)
A cluster of clusters would probably flatten correctly. In that case you would always be sending exactly 5 setpoints though.
For your use case, will you be sending variable number of setpoints? If so, you might want to consider writing your own string generator instead of using Flatten to String.
That is why there is also an input on the Flatten to String to prepend the Array/String size. It is a Boolean input. Otherwise it will be just fine.
There's a caveat in the help.
If you are using a cluster with an array inside of it, the Boolean input for prepend Array/String size doesn't strip the size information.
From the LabVIEW help on using the prepend Array/String size option: "Arrays and strings in hierarchical data types such as clusters always include size information"
I didn't test it, but I suspect passing the cluster into flatten to string will suffer from this exception.
EDIT: Ran a quick test with an array inside of a cluster. The Boolean for prepend Array/String behaves as described in the help. Size information is always included.
If you put a fixed number of clusters inside of the cluster, flattening works fine.
12-19-2013 09:56 AM
@crossrulz wrote:
That is why there is also an input on the Flatten to String to prepend the Array/String size. It is a Boolean input. Otherwise it will be just fine.
That is not true! The boolean only influences if the size is prepended when the most outer datatype is a string or array. Any embedded strings or arrays are ALWAYS prepended with the size integer.