////////////////波形成性 //現在のシーケンスから波形を生成 public void compile() { MainWindow.WriteMessage("シーケンスから信号を作成..."); taskAsm.Clear(); //デバイスごとにTaskAssembleを作成 List <string> deviceList = getEnabledDeviceList(); int divisionCount = divisions.Count; for (int i = 0; i < deviceList.Count(); i++) { TaskAssemble ta = new TaskAssemble(); long sampleCount = this.getSequenceSampleCount(); ta.deviceName = deviceList[i]; // すべてのチャンネルから特定デバイスに属するAO/DO/AI/DIをフィルター List <Channel> analogOutputChannels = channels.FindAll((ch) => ch.deviceName == ta.deviceName && ch.isAnalog && ch.isOutput); List <Channel> analogInputChannels = channels.FindAll((ch) => ch.deviceName == ta.deviceName && ch.isAnalog && !ch.isOutput); List <Channel> digitalOutputChannels = channels.FindAll((ch) => ch.deviceName == ta.deviceName && !ch.isAnalog && ch.isOutput); int analogOutputChannelCount = analogOutputChannels.Count(); int analogInputChannelCount = analogInputChannels.Count(); int digitalOutputChannelCount = digitalOutputChannels.Count(); ta.analogOutputChannelNames = new string[analogOutputChannelCount]; ta.outputMaxVoltage = new double[analogOutputChannelCount]; ta.outputMinVoltage = new double[analogOutputChannelCount]; ta.outputWaves = new double[analogOutputChannelCount, sampleCount]; ta.digitalOutputChannelNames = new string[digitalOutputChannelCount]; ta.outputDigis = new uint[digitalOutputChannelCount, sampleCount]; ta.analogInputChannelNames = new string[analogInputChannelCount]; ta.inputMaxVoltage = new double[analogInputChannelCount]; ta.inputMinVoltage = new double[analogInputChannelCount]; // AOを整理 for (int ci = 0; ci < analogOutputChannelCount; ci++) { ta.analogOutputChannelNames[ci] = analogOutputChannels[ci].channelName; ta.outputMinVoltage[ci] = analogOutputChannels[ci].minVoltage; ta.outputMaxVoltage[ci] = analogOutputChannels[ci].maxVoltage; long offset = 0; // division ごとに波形をサンプルに変換 for (int di = 0; di + 1 < divisionCount; di++) { long divisionSample = getDivisionSampleCount(di); NodeType type = analogOutputChannels[ci].nodes[di].type; double current = analogOutputChannels[ci].nodes[di].value; double next = analogOutputChannels[ci].nodes[di + 1].value; if (type == NodeType.Hold) { for (int si = 0; si < divisionSample; si++) { ta.outputWaves[ci, offset + si] = current; ta.outputWaves[ci, offset + si] = Math.Max(ta.outputWaves[ci, offset + si], ta.outputMinVoltage[ci]); ta.outputWaves[ci, offset + si] = Math.Min(ta.outputWaves[ci, offset + si], ta.outputMaxVoltage[ci]); } } else if (type == NodeType.Linear) { double val = current; double step = (next - current) / divisionSample; for (int si = 0; si < divisionSample; si++) { ta.outputWaves[ci, offset + si] = val; ta.outputWaves[ci, offset + si] = Math.Max(ta.outputWaves[ci, offset + si], ta.outputMinVoltage[ci]); ta.outputWaves[ci, offset + si] = Math.Min(ta.outputWaves[ci, offset + si], ta.outputMaxVoltage[ci]); val += step; } } offset += divisionSample; } } // DOの情報を整理 for (int ci = 0; ci < digitalOutputChannelCount; ci++) { ta.digitalOutputChannelNames[ci] = digitalOutputChannels[ci].channelName; long offset = 0; for (int di = 0; di + 1 < divisionCount; di++) { long divisionSample = getDivisionSampleCount(di); double value = digitalOutputChannels[ci].nodes[di].value; string[] namespl = digitalOutputChannels[ci].channelName.Split("line".ToCharArray()); int linenum = int.Parse(namespl[namespl.Count() - 1]); for (int si = 0; si < divisionSample; si++) { ta.outputDigis[ci, offset + si] = (uint)(value > 0?1 << linenum:0); } offset += divisionSample; } } // AIの情報を整理 for (int ci = 0; ci < analogInputChannelCount; ci++) { ta.analogInputChannelNames[ci] = analogInputChannels[ci].channelName; ta.inputMinVoltage[ci] = analogInputChannels[ci].minVoltage; ta.inputMaxVoltage[ci] = analogInputChannels[ci].maxVoltage; } taskAsm.Add(ta); } // MainWindow.WriteMessage("OK\n"); MainWindow.WriteMessage(" サンプルレート:" + sampleRate + " / "); MainWindow.WriteMessage(" 使用デバイス数:" + deviceList.Count() + " / "); MainWindow.WriteMessage(" シーケンス時間:" + getSequenceTime() + " / "); MainWindow.WriteMessage(" サンプル数:" + getSequenceSampleCount() + " / "); MainWindow.WriteMessage(" 通信量:" + getSequenceSampleCount() * sizeof(double) * getEnabledChannelCount() * 1e-6 + "MByte\n"); }
////////////////波形成性 //現在のシーケンスから波形を生成 public void compile() { MainWindow.WriteMessage("シーケンスから信号を作成..."); taskAsm.Clear(); //デバイスごとにTaskAssembleを作成 List<string> deviceList = getEnabledDeviceList(); int divisionCount = divisions.Count; for (int i = 0; i < deviceList.Count(); i++) { TaskAssemble ta = new TaskAssemble(); long sampleCount = this.getSequenceSampleCount(); ta.deviceName = deviceList[i]; // すべてのチャンネルから特定デバイスに属するAO/DO/AI/DIをフィルター List<Channel> analogOutputChannels = channels.FindAll((ch) => ch.deviceName == ta.deviceName && ch.isAnalog && ch.isOutput); List<Channel> analogInputChannels = channels.FindAll((ch) => ch.deviceName == ta.deviceName && ch.isAnalog && !ch.isOutput); List<Channel> digitalOutputChannels = channels.FindAll((ch) => ch.deviceName == ta.deviceName && !ch.isAnalog && ch.isOutput); int analogOutputChannelCount = analogOutputChannels.Count(); int analogInputChannelCount = analogInputChannels.Count(); int digitalOutputChannelCount = digitalOutputChannels.Count(); ta.analogOutputChannelNames = new string[analogOutputChannelCount]; ta.outputMaxVoltage = new double[analogOutputChannelCount]; ta.outputMinVoltage = new double[analogOutputChannelCount]; ta.outputWaves = new double[analogOutputChannelCount, sampleCount]; ta.digitalOutputChannelNames = new string[digitalOutputChannelCount]; ta.outputDigis = new uint[digitalOutputChannelCount, sampleCount]; ta.analogInputChannelNames = new string[analogInputChannelCount]; ta.inputMaxVoltage = new double[analogInputChannelCount]; ta.inputMinVoltage = new double[analogInputChannelCount]; // AOを整理 for (int ci = 0; ci < analogOutputChannelCount; ci++) { ta.analogOutputChannelNames[ci] = analogOutputChannels[ci].channelName; ta.outputMinVoltage[ci] = analogOutputChannels[ci].minVoltage; ta.outputMaxVoltage[ci] = analogOutputChannels[ci].maxVoltage; long offset = 0; // division ごとに波形をサンプルに変換 for (int di = 0; di+1 < divisionCount; di++) { long divisionSample = getDivisionSampleCount(di); NodeType type = analogOutputChannels[ci].nodes[di].type; double current = analogOutputChannels[ci].nodes[di].value; double next = analogOutputChannels[ci].nodes[di + 1].value; if (type == NodeType.Hold) { for (int si = 0; si < divisionSample; si++) { ta.outputWaves[ci, offset + si] = current; ta.outputWaves[ci, offset + si] = Math.Max(ta.outputWaves[ci, offset + si], ta.outputMinVoltage[ci]); ta.outputWaves[ci, offset + si] = Math.Min(ta.outputWaves[ci, offset + si], ta.outputMaxVoltage[ci]); } } else if (type == NodeType.Linear) { double val = current; double step = (next - current) / divisionSample; for (int si = 0; si < divisionSample; si++) { ta.outputWaves[ci, offset + si] = val; ta.outputWaves[ci, offset + si] = Math.Max(ta.outputWaves[ci, offset + si], ta.outputMinVoltage[ci]); ta.outputWaves[ci, offset + si] = Math.Min(ta.outputWaves[ci, offset + si], ta.outputMaxVoltage[ci]); val += step; } } offset += divisionSample; } } // DOの情報を整理 for (int ci = 0; ci < digitalOutputChannelCount; ci++) { ta.digitalOutputChannelNames[ci] = digitalOutputChannels[ci].channelName; long offset=0; for(int di=0;di+1<divisionCount;di++){ long divisionSample = getDivisionSampleCount(di); double value = digitalOutputChannels[ci].nodes[di].value; string[] namespl = digitalOutputChannels[ci].channelName.Split("line".ToCharArray()); int linenum = int.Parse(namespl[namespl.Count()-1]); for (int si = 0; si < divisionSample; si++) { ta.outputDigis[ci, offset + si] = (uint)(value>0?1<<linenum:0); } offset += divisionSample; } } // AIの情報を整理 for (int ci = 0; ci < analogInputChannelCount; ci++) { ta.analogInputChannelNames[ci] = analogInputChannels[ci].channelName; ta.inputMinVoltage[ci] = analogInputChannels[ci].minVoltage; ta.inputMaxVoltage[ci] = analogInputChannels[ci].maxVoltage; } taskAsm.Add(ta); } // MainWindow.WriteMessage("OK\n"); MainWindow.WriteMessage(" サンプルレート:" + sampleRate+" / "); MainWindow.WriteMessage(" 使用デバイス数:" + deviceList.Count()+" / "); MainWindow.WriteMessage(" シーケンス時間:" + getSequenceTime() + " / "); MainWindow.WriteMessage(" サンプル数:" + getSequenceSampleCount() + " / "); MainWindow.WriteMessage(" 通信量:" + getSequenceSampleCount()*sizeof(double)*getEnabledChannelCount()*1e-6+"MByte\n"); }