Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

PCI-CAN - Channel API - write to one channel from message

Hello,
I have the first project using CAN and I don't know if I use it correctly.
 
I use Channel API. In one message I have 8 channels DI or DO; 
1. I want to change only one channel at a time (one bit) but It change the whole byte;
2. Is it possible to read DO channel state?
3. After the application start I get the default values defined in MAX. They change only when the event (state change) occure;
 
I don't know if this is normal when using channel API.
 
Thanks for any answer.
 
INFO: NI-PCI CAN2/ LV7.1/Driver 2.3
0 Kudos
Message 1 of 6
(4,030 Views)

Hi Wpar,

If you use single Bits with a channel it doesn't matter whether you put all the 8 bits in one Byte of the message or every single bit in his own byte in one message. The driver takes CARE of writing the right number during the database conversion.

See the attached example which uses 4 bits in different bytes and 2 bytes of them in the first byte together.

1. yes it writes the whole byte but updates only the Bit (Channel you changed

2. the only way to get the state of the bit is to read the bit (channel)

3. Yes the read function starts reading immediately if you use the input mode and if no data is available because the write function has not completed yet, it reads the default value from your database. Use the timestamped mode instead which reads only the real message and therefore the sample rate is ignored. See the attached example for more info.

Hope that helps

0 Kudos
Message 2 of 6
(4,014 Views)

Hi DirkW

In this case writing and changing only one channel sate works ok. My application include several test steps (different vi's). They run one after another. I would like to change one channel in one vi and another in the next vi. When I do it in this way I reset the previous setting.

Also in the example I can change the channel state but I can't read the status of this changed channel. Maybe this is problem with Arbitration ID (it is different in DI and DO).

I will send you my channel configuration. Maybe I make some mistake.

 

0 Kudos
Message 3 of 6
(4,003 Views)

Hi Wpar,

The key to overcome this problem is using a Task. All channels initialized in one Task belong  together.  Then you need a global variable for the state of each channel. With every write you use, you have to read first the global, to get the last state, change the state of the channel you want to change and write the whole array to the write then.

If you change a Output state, there is no way to read the state again, because the communication is CAN BUS based, you would need to request a message from the node which belongs to the channel. The only chance is to store the written Value to the globel and read from this global instead id you need the status again.

DirkW

0 Kudos
Message 4 of 6
(3,993 Views)
Hi DirkW,
 
Thank you for help. This solution with storing the written values works. I was thinking about this before, but I was hope that there is another solution. I will have to do this in this way...
 
I have still problems with reading the values from digital INPUTS. What value should I write to get the actual state of the channels?
Still at the beginning I have the default values from MAX.
 
Regards
Wpar
0 Kudos
Message 5 of 6
(3,985 Views)

Hi Wpar,

Well it depends on your Hardware System, you are writing to. Normaly there is a way to send a special Status ID to get the status for all Inputs.

Or the Modules send it periodically, but you have to enable it first. Refer to the Manual for the Hardware or contact their Support.

DirkW

0 Kudos
Message 6 of 6
(3,965 Views)