Discussion:
not reading/Writing simulated digital device
(too old to reply)
Ruzz
2008-05-13 10:10:09 UTC
Permalink
Hi to everyone, I have defined a simulated PCI-6503 card for testing examples in C#. As base of my example, im using the ReadDigPort.2005 and WriteDigPort.2005.The following code is what im trying to do for write in the port0 of my device the value 00000001                using (Task tareaWrite = new Task())                {                    //  Create an Digital Output channel and name it.                    tareaWrite.DOChannels.CreateChannel("Device1/port0", "port0",                        ChannelLineGrouping.OneChannelForAllLines);                    //  Write digital port data. WriteDigitalSingChanSingSampPort writes a single sample                    //  of digital data on demand, so no timeout is necessary.                    DigitalSingleChannelWriter writer = new DigitalSingleChannelWriter(tareaWrite.Stream);                    writer.WriteSingleSamplePort(true, (UInt32)1);                }After this, im doing the reading                using (Task tareaRead = new Task())                {                    tareaRead.DIChannels.CreateChannel("Device1/port0",                        "port0",                        ChannelLineGrouping.OneChannelForAllLines);                    DigitalSingleChannelReader reader = new DigitalSingleChannelReader(tareaRead.Stream);                    UInt32 data = reader.ReadSingleSamplePortUInt32();                    //Update the Data Read box                    hexData.Text = data.toString();                }But i alwais get 0's, so it seems im not writting on the desired port. I have tried writting only one line, and lot of combinations, but i have not succes. I dont know what im doing wrong, because i have just started.Any tip will help me a lot, Thanks to everyone in advance.
Ruzz
2008-05-13 15:10:09 UTC
Permalink
I have investigate a little more about my question. And i have noticed that, for a DOChannel, after write the value of the Line/s or port/s,i can perform a read using a Reader. The code should be like this, but still not working for me, and i cant reach the writted valueTask tarea = new Task();tarea.DOChannels.CreateChannel("Device1/port0" "port0",ChannelLineGrouping.OneChannelForAllLines);DigitalSingleChannelWriter writer = new DigitalSingleChannelWriter(tarea.Stream);writer.WriteSingleSamplePort(true, (uint32)1);//now its supposed we have writted the lines in that port//and we will read the writted valueDigitalSingleChannelReader reader = new DigitalSingleChannelReader(tarea.Stream);UInt32 data = reader.ReadSingleSamplePortUInt32();hexData.Text = data.ToString();Saddly, still not working. And i still lost about what im doing wrong.Again, Thanks a lot in advance for your answers.Mensaje editado por Ruzz
Loura
2008-05-14 08:10:07 UTC
Permalink
Hi Ruzz,
there is nothing wrong in your code, this is the expected behaviour of a simulated device. Since there is not a physical digital port you cannot read physical data from the port. Always when you read a simulated device you read simulated sets of data; no metter if you do or not a write before the read; in other words there's no memory for simulated device. In the case of digital chennels the simulation start always with 00000000, so it's correct that you read 00000000 even if you write something before.
As a test you can try to open Measurement and Automation Explorer, go to the simulated PCI 6503 and open the test Panel. If you test a digital port as input you'll see that the simulation always starts with 00000000 than 00000001, 00000010, 00000011 and so on...
Clara
Ruzz
2008-05-14 08:40:07 UTC
Permalink
Thanks a lot for your reply Clara. I was getting mad... So, if i want to know if im "really" sending data to a device, i need to use a real board on my computer? I though that with the simulated device i can simulate the behavior of the pci-6503 so i can play arround with the code before getting serious.Ruzz.
Loura
2008-05-14 09:10:09 UTC
Permalink
"If i want to know if im "really" sending data to a device, i need to use a real board on my computer?" yes!
The purpose of simulated device is to offer the possibility to start program without hardware; also with a simulated device you can check if the syntax of your program is correct and verify if he data you are writing meets specification for your board.
If you are interested in this there are some usefull information at this link:
<a href="http://zone.ni.com/devzone/cda/tut/p/id/3698#toc3" target="_blank">http://zone.ni.com/devzone/cda/tut/p/id/3698#toc3</a>
Bye
Clara
Ruzz
2008-05-14 09:10:09 UTC
Permalink
Thanks a lot Clara, you helped me a lot! Ruzz.

Continue reading on narkive:
Loading...