Commit 7e8d3d22 authored by reza's avatar reza

g

parent 8dc789f1
......@@ -89,6 +89,7 @@ namespace I8Devices
}
private int _gain = 250;
private int _Exgain = 250;
public int gain
{
get => _gain;
......@@ -104,7 +105,27 @@ namespace I8Devices
}
}
public bool[] channels_on = new bool[8] { true, true, true, true, true, true, true, true };
public int Exgain
{
get => _Exgain;
set
{
if (value <= 1) _gain = 1;
else if ((value > 1) && (value <= 2)) _gain = 2;
else if ((value > 2) && (value <= 4)) _gain = 4;
else if ((value > 4) && (value <= 6)) _gain = 6;
else if ((value > 6) && (value <= 8)) _gain = 8;
else if ((value > 8) && (value <= 12)) _gain = 12;
else if ((value > 12)) _gain = 24;
}
}
private const int _chanels_count = 24;
public bool[] channels_on = new bool[_chanels_count];
private const int _Exchanels_count = 3;
public bool[] Exchannels_on = new bool[_Exchanels_count];
public Settings()
{
......@@ -112,6 +133,8 @@ namespace I8Devices
leadoff_mode = false;
sampling_rate = 2000;
gain = 24;
for (int J = 0; J < _chanels_count; J++) channels_on[J] = true;
for (int J = 0; J < _Exchanels_count; J++) Exchannels_on[J] = false;
}
}
......@@ -150,8 +173,9 @@ namespace I8Devices
sendBuffer[3] = Convert.ToByte('S'); // for enter in setting mode
if (mysetting.test_signal) sendBuffer[4] = Convert.ToByte('T');
else sendBuffer[4] = Convert.ToByte('n');
// if (mysetting.test_signal) sendBuffer[4] = Convert.ToByte('T');
// else sendBuffer[4] = Convert.ToByte('n');
sendBuffer[4] = mysetting.test_signal ? Convert.ToByte('T') : Convert.ToByte('n');
sendBuffer[5] = Convert.ToByte(48+ (mysetting.sampling_rate/250)); // '1'=250, '2'=500, '4'=1000, '8'=2000
sendBuffer[6] = Convert.ToByte(' '); // disable lead-off (enable = 'L')
sendBuffer[6] = mysetting.leadoff_mode ? Convert.ToByte('L') : Convert.ToByte(' ');
......@@ -210,6 +234,72 @@ namespace I8Devices
return false;
};
}
public bool set(Settings mysetting)
{
if (debug_mode)
{
Console.WriteLine("DLL: Sampling rate= " + mysetting.sampling_rate);
Console.WriteLine("DLL: Test Mode= " + mysetting.test_signal);
Console.WriteLine("DLL: Lead off= " + mysetting.leadoff_mode);
Console.WriteLine("DLL: Gain= " + mysetting.gain);
foreach (var channels in mysetting.channels_on)
Console.Write(" " + channels);
Console.WriteLine("");
}
settingMode_flag = true;
sendBuffer[3] = Convert.ToByte('s'); // for enter in setting mode
sendBuffer[4] = mysetting.test_signal ? Convert.ToByte('T') : Convert.ToByte('n'); // test signal enable/disable
sendBuffer[5] = Convert.ToByte(48 + (mysetting.sampling_rate / 250)); // '1'=250, '2'=500, '4'=1000, '8'=2000
sendBuffer[6] = mysetting.leadoff_mode ? Convert.ToByte('L') : Convert.ToByte(' '); // lead-off enable/disable
sendBuffer[7] = Convert.ToByte('C'); // SRB1 connected to all Nchs
sendBuffer[8] = Convert.ToByte(mysetting.gain);
sendBuffer[9] = Convert.ToByte(mysetting.Exgain);
sendBuffer[10] = 0x00; //reserved
sendBuffer[11] = 0x00; //reserved
sendBuffer[12] = 0x00; //reserved
sendBuffer[13] = 0x00; //reserved
sendBuffer[14] = 0x00; //reserved
BitArray ch_arr = new BitArray(mysetting.channels_on);
byte[] ch_data = new byte[80];
ch_arr.CopyTo(ch_data, 0);
sendBuffer[15] = ch_data[0]; // channels 1 to 8 on/off status
sendBuffer[16] = ch_data[1]; // channels 9 to 16 on/off status
sendBuffer[17] = ch_data[2]; // channels 17 to 24 on/off status
if (debug_mode) Console.WriteLine("DLL: sendBuffer[10] " + sendBuffer[10]);
if (debug_mode) Console.WriteLine("DLL: sendBuffer[11] " + sendBuffer[11]);
if (debug_mode) Console.WriteLine("DLL: sendBuffer[12] " + sendBuffer[12]);
BitArray Exch_arr = new BitArray(mysetting.Exchannels_on);
byte[] Exch_data = new byte[80];
Exch_arr.CopyTo(Exch_data, 0);
sendBuffer[18] = Exch_data[0]; // channels 1 to 8 on/off status
Console.WriteLine("DLL: sendBuffer[18] " + sendBuffer[18]);
_serialPort.Open();
_serialPort.Write(sendBuffer, 0, sendBuffer.Length);
try
{
if (debug_mode) Console.WriteLine("DLL: Waiting for device to send back acknowledge about write setting ...");
while (settingMode_flag) ;
_serialPort.Close();
return true;
}
catch (Exception)
{
return false;
};
}
public bool connect() //string device_name
{
......
......@@ -17,24 +17,28 @@ def read_data():
if __name__ == "__main__":
myAwsomeHolyShitImDyingForThisDevice = Device()
myAwsomeHolyShitImDyingForThisDevice.debug_mode = True
# myAwsomeHolyShitImDyingForThisDevice.debug_mode = True
if myAwsomeHolyShitImDyingForThisDevice.connect():
print('connected success')
time.sleep(1)
mysetting = Settings()
mysetting.test_signal = 234
mysetting.sampling_rate = 885.5
mysetting.leadoff_mode = False
mysetting.channels_on[7] = False
mysetting.gain = 3
mysetting.channels_on[15] = False
mysetting.Exchannels_on[0] = False
mysetting.Exchannels_on[1] = True
mysetting.gain = 12
#
print(myAwsomeHolyShitImDyingForThisDevice.writeSetting(mysetting))
print(myAwsomeHolyShitImDyingForThisDevice.set(mysetting))
mysetting.gain = 5
#
print(myAwsomeHolyShitImDyingForThisDevice.writeSetting(mysetting))
# mysetting.gain = 5
# #
# print(myAwsomeHolyShitImDyingForThisDevice.writeSetting(mysetting))
# myAwsomeHolyShitImDyingForThisDevice.start()
# all_data = read_data()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment