Commit c20edde7 authored by reza's avatar reza

v3.1

add error handling
parent fd11ed25
...@@ -587,7 +587,13 @@ namespace I8Devices ...@@ -587,7 +587,13 @@ namespace I8Devices
} }
else else
{ {
if (device_name == "Fascin8" && _serialPort.IsOpen && _serialPort.BytesToRead > 73) //if (!_serialPort.IsOpen)
//{
// Console.WriteLine(_serialPort.IsOpen);
//}
try
{
if (device_name == "Fascin8" && _serialPort.IsOpen && _serialPort.BytesToRead > 73)
{ {
/* /*
byte[] last_data_recieve = new byte[74]; byte[] last_data_recieve = new byte[74];
...@@ -615,29 +621,32 @@ namespace I8Devices ...@@ -615,29 +621,32 @@ namespace I8Devices
newData_count ++; newData_count ++;
// if (debug_mode) Console.WriteLine("DLL: Sample number " + sample_count + " has been received :)"); // if (debug_mode) Console.WriteLine("DLL: Sample number " + sample_count + " has been received :)");
*/ */
byte[] last_data_recieve = new byte[80];
_serialPort.Read(last_data_recieve, 0, 80); byte[] last_data_recieve = new byte[80];
_serialPort.Read(last_data_recieve, 0, 80);
double[] data_converted = new double[30]; double[] data_converted = new double[30];
data_converted[0] = sample_count; // dll sample count data_converted[0] = sample_count; // dll sample count
data_converted[1] = (65536 * last_data_recieve[0]) + (256 * last_data_recieve[1]) + last_data_recieve[2]; // firmware sample count data_converted[1] = (65536 * last_data_recieve[0]) + (256 * last_data_recieve[1]) + last_data_recieve[2]; // firmware sample count
data_converted[2] = 0; //reserverd data_converted[2] = 0; //reserverd
data_converted[3] = last_data_recieve[3]; // Device ID data_converted[3] = last_data_recieve[3]; // Device ID
data_converted[4] = last_data_recieve[4]; // user input keys data_converted[4] = last_data_recieve[4]; // user input keys
data_converted[5] = 0; //reserverd data_converted[5] = 0; //reserverd
int i = 6, p = 8; // i = data_convewrted position, p = input data position int i = 6, p = 8; // i = data_convewrted position, p = input data position
for (int k = i; k < 24 + i; k++) for (int k = i; k < 24 + i; k++)
{ {
data_converted[k] = (65536 * last_data_recieve[3 * (k - i) + p + 0]) + (256 * last_data_recieve[3 * (k - i) + p + 1]) + data_converted[k] = (65536 * last_data_recieve[3 * (k - i) + p + 0]) + (256 * last_data_recieve[3 * (k - i) + p + 1]) +
last_data_recieve[3 * (k - i) + p + 2]; // adding 3 byte as one data last_data_recieve[3 * (k - i) + p + 2]; // adding 3 byte as one data
if (data_converted[k] > 8388607) data_converted[k] = data_converted[k] - 16777216; //two's compliment if (data_converted[k] > 8388607) data_converted[k] = data_converted[k] - 16777216; //two's compliment
data_converted[k] = data_converted[k] * 0.536; //convert to uV data_converted[k] = data_converted[k] * 0.536; //convert to uV
} }
receiveBuffer.Add(data_converted); receiveBuffer.Add(data_converted);
sample_count++; sample_count++;
newData_count++; newData_count++;
} }
else if (device_name == "Ultim8" && _serialPort.IsOpen && _serialPort.BytesToRead > 25) else if (device_name == "Ultim8" && _serialPort.IsOpen && _serialPort.BytesToRead > 25)
{ {
byte[] last_data_recieve = new byte[26]; byte[] last_data_recieve = new byte[26];
...@@ -669,7 +678,14 @@ namespace I8Devices ...@@ -669,7 +678,14 @@ namespace I8Devices
// if (debug_mode) Console.WriteLine("DLL: Somthing is wrong!"); // if (debug_mode) Console.WriteLine("DLL: Somthing is wrong!");
if (debug_mode) Console.WriteLine("DLL: Somthing is wrong!"); if (debug_mode) Console.WriteLine("DLL: Somthing is wrong!");
} }
}
catch (Exception)
{
if (debug_mode)
Console.WriteLine("Port is not open?");
}
} }
} }
public object getData(int val=0) public object getData(int val=0)
{ {
......
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