03-20-2024 01:37 PM
Hi, I have cDaq-9174 and two NI9205 and two NI9213. For the server side I use ni grpc server. My client app is working fine if it is only 1 client, however, if the second client app tries to access the same NI device I get a 50103 error and never go inside the while loop(await responseStream.MoveNext()).
Here is part of my code:
for (int i = 0; i < selectedChannelsForPressure.Length; i++)
{
if (selectedChannelsForPressure[i] != string.Empty && selectedChannelsForPressure[i] != "N/A")
{
string chan = GetChannelName(int.Parse(new string(selectedChannelsForPressure[i].Where(char.IsDigit).ToArray())) - 1);
if (chan != "Invalid channel index") {
await client.CreateAIVoltageChanAsync(new CreateAIVoltageChanRequest
{
Task = task,
PhysicalChannel = chan, //"cDAQ1Mod1/ai7",
MinVal = 1,
MaxVal = 5,
TerminalConfig = InputTermCfgWithDefault.CfgDefault, //try to use diffrential method to see how it would reduce noize, but it is actually require to wire up two cables per channel, which is not possible
Units = VoltageUnits2.Volts,
});
pickedChannels.Add("pressure" + selectedChannelsForPressure[i], smth);
smth++;
}
}
}
for (int i = 0; i < selectedChannelsForForce.Length; i++)
{
if (selectedChannelsForForce[i] != string.Empty && selectedChannelsForForce[i] != "N/A")
{
//string chan = GetChannelName(int.Parse(new string(selectedChannelsForForce[i].Where(char.IsDigit).ToArray())) + 11);
string chan = "cDAQ1Mod1/ai12";
if (chan != "Invalid channel index")
{
await client.CreateAIVoltageChanAsync(new CreateAIVoltageChanRequest
{
Task = task,
PhysicalChannel = chan,
MinVal = 1,
MaxVal = 5,
TerminalConfig = InputTermCfgWithDefault.CfgDefault,
Units = VoltageUnits2.Volts,
});
pickedChannels.Add("force" + selectedChannelsForForce[i], smth);
smth++;
}
}
}
for (int i = 0; i < selectedChannelsForTemperature.Length; i++)
{
if (selectedChannelsForTemperature[i] != string.Empty && selectedChannelsForTemperature[i] != "N/A")
{
string chan = GetChannelName(int.Parse(new string(selectedChannelsForTemperature[i].Where(char.IsDigit).ToArray())) + 12);
if(chan != "Invalid channel index")
{
await client.CreateAIThrmcplChanAsync(new CreateAIThrmcplChanRequest //CreateAIThrmcplChan
{
Task = task,
PhysicalChannel = chan,
ThermocoupleType = ThermocoupleType1.JTypeTc,
MinVal = 0,
MaxVal = 100,
Units = TemperatureUnits.DegC,
CjcSource = CJCSource1.BuiltIn
});
pickedChannels.Add("temperature" + selectedChannelsForTemperature[i], smth);
smth++;
}
}
}
await client.CfgSampClkTimingAsync(new CfgSampClkTimingRequest
{
Task = task,
SampleMode = AcquisitionType.ContSamps,
SampsPerChan = 1000,
ActiveEdge = Edge1.Rising,
Rate = (double)numericUpDown1.Value
});
var everyNSamplesStream = client.RegisterEveryNSamplesEvent(new RegisterEveryNSamplesEventRequest
{
Task = task,
NSamples = (uint)numericUpDown2.Value,
EveryNSamplesEventType = EveryNSamplesEventType.AcquiredIntoBuffer,
});
var startTaskResponse = await client.StartTaskAsync(new StartTaskRequest { Task = task });
var getNumChansResponse = await client.GetTaskAttributeUInt32Async(new GetTaskAttributeUInt32Request
{
Task = task,
Attribute = TaskUInt32Attribute.TaskAttributeNumChans
});
int numberOfChannels = (int)getNumChansResponse.Value;
var responseStream = everyNSamplesStream.ResponseStream;
startTime = DateTime.Now;
async Task ReadData()
{
while (await responseStream.MoveNext())
{
try
{
//MessageBox.Show("INside");
var readResponse = await client.ReadAnalogF64Async(new ReadAnalogF64Request
{
Task = task,
NumSampsPerChan = (int)numericUpDown2.Value,
FillMode = GroupBy.GroupByChannel,
ArraySizeInSamps = (uint)(numberOfChannels * (int)numericUpDown2.Value),
//Timeout
});
double[] data = readResponse.ReadArray.ToArray();
grpcServerData = data;
if (data.Length > 0)
{
msg();
}
}
catch (Exception ex)
{
Console.WriteLine("Error" + ex.Message);
break;
}
}
}
var readDataTask = ReadData();
await Task.WhenAll(readDataTask);
await client.StopTaskAsync(new StopTaskRequest
{
Task = task
});