Added a function to get the spectrum of the measures made

master
mDescape 3 years ago
parent 367b1834d8
commit ba1b0718e8
  1. BIN
      C7000 _SDK/Sample/.vs/C7000_SDK_Sample/v16/.suo
  2. BIN
      C7000 _SDK/Sample/.vs/C7000_SDK_Sample/v16/Server/sqlite3/storage.ide
  3. BIN
      C7000 _SDK/Sample/bin/Debug/C7000_SDK_Sample.exe
  4. BIN
      C7000 _SDK/Sample/bin/Debug/C7000_SDK_Sample.pdb
  5. 4
      C7000 _SDK/Sample/bin/Debug/SkCommIo.log
  6. BIN
      C7000 _SDK/Sample/obj/x86/Debug/C7000_SDK_Sample.exe
  7. BIN
      C7000 _SDK/Sample/obj/x86/Debug/C7000_SDK_Sample.pdb
  8. BIN
      C7000 _SDK/Sample/obj/x86/Debug/C7000_SDK_Sample.vbprojAssemblyReference.cache
  9. 3
      Code/C7000_Controller/netcoreapp3.1/SkCommIo.log
  10. 92
      Code/Matlab/A_TEST.m
  11. 12
      Code/Matlab/NEW_CalibrateVisualStim_Descalzo.m
  12. BIN
      Code/Visual_Basic/C7000_Main/.vs/C7000_Test/DesignTimeBuild/.dtbcache
  13. BIN
      Code/Visual_Basic/C7000_Main/.vs/C7000_Test/v16/.suo
  14. BIN
      Code/Visual_Basic/C7000_Main/.vs/C7000_Test/v16/Server/sqlite3/storage.ide
  15. 175
      Code/Visual_Basic/C7000_Main/C7000_Test/Program.vb
  16. BIN
      Code/Visual_Basic/C7000_Main/C7000_Test/bin/x86/Debug/netcoreapp3.1/C7000_Test.dll
  17. BIN
      Code/Visual_Basic/C7000_Main/C7000_Test/bin/x86/Debug/netcoreapp3.1/C7000_Test.pdb
  18. 21
      Code/Visual_Basic/C7000_Main/C7000_Test/bin/x86/Debug/netcoreapp3.1/SkCommIo.log
  19. BIN
      Code/Visual_Basic/C7000_Main/C7000_Test/obj/x86/Debug/netcoreapp3.1/C7000_Test.dll
  20. BIN
      Code/Visual_Basic/C7000_Main/C7000_Test/obj/x86/Debug/netcoreapp3.1/C7000_Test.pdb
  21. BIN
      Code/Visual_Basic/C7000_Main/C7000_Test/obj/x86/Debug/netcoreapp3.1/C7000_Test.vbprojAssemblyReference.cache

@ -66,3 +66,7 @@
[#2020/03/15 15:34:19.119]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000
[#2020/03/15 15:53:41.736]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000
[#2020/03/15 21:23:48.197]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000
[#2020/05/04 12:11:01.645]SkCommIo_CloseDevice :Status=0x20210003:GetLastError=0x00000000
[#2020/05/04 12:11:14.145]SkCommIo_SendData :Status=0x20210003:GetLastError=0x00000000
[#2020/05/04 12:11:14.335]SkCommIo_SendData :Status=0x20210003:GetLastError=0x00000000
[#2020/05/04 12:11:14.549]SkCommIo_CloseDevice :Status=0x20210003:GetLastError=0x00000578

@ -933,3 +933,6 @@
[#2020/04/28 17:35:25.612]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000
[#2020/04/28 18:20:29.792]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000
[#2020/04/28 23:29:57.552]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000
[#2020/05/04 13:27:57.405]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000
[#2020/05/04 13:28:50.320]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000
[#2020/05/04 13:29:59.082]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000

@ -0,0 +1,92 @@
X_1nm = [];
Y_1nm = [];
X_5nm = [];
Y_5nm = [];
interStimuliColor_sRGB = [0 0 0];
screenSizePix2 = zeros(1,2);
screenSizePix1 = zeros(1,2);
%Call the C7000 controller (TCP client)
%!..\C7000_Controller\netcoreapp3.1\C7000_Test &
%Start the TCP server
tcpObj = tcp_Server_Start(); %Wait here until the client connects
%Screen('Preference', 'ScreenToHead', 0, 1, 1);
Screen('Preference', 'SkipSyncTests', 1);
screenNumber = max(Screen('Screens')); %0: single display setting
[screenSizePix2(1) screenSizePix2(2)] = Screen('WindowSize', screenNumber);
[screenSizePix1(1) screenSizePix1(2)] = Screen('WindowSize', 1); %Principal monitor size
wPtr = Screen('OpenWindow', screenNumber, interStimuliColor_sRGB, [screenSizePix1(1) 1 screenSizePix1(1)+screenSizePix2(1) screenSizePix2(2)]);
Screen('FillRect', wPtr, interStimuliColor_sRGB);
[screenSizePix2(1) screenSizePix2(2)] = Screen('WindowSize', wPtr);
%Present new image
stimImg = GenerateNoisyImage([screenSizePix2(2) screenSizePix2(1)], 1, 0); %Create the visual stimuli
stimTextureId = Screen('MakeTexture', wPtr, uint8(stimImg.*255));
Screen('DrawTexture', wPtr, stimTextureId);
Screen('Flip', wPtr);
%Perform 1 measuresand returun the usefull values
[average_lx, max_lx, min_lx] = C7000_Read(1, tcpObj);
%Get the spectrum of the last measure
[X_1nm, Y_1nm, X_5nm, Y_5nm] = C7000_GetSpectrum(tcpObj);
%Program clossing
sca;
C7000_End_program(tcpObj); %Return the C-7000 to its manual control
fclose(tcpObj); %Close the server
%C-7000 controller Functions
%START HERE
function tcpObj = tcp_Server_Start()
%Opens a TCP/IP server and waits until a client connects to it
port = 30000;
tcpObj = tcpip('0.0.0.0', port, 'NetworkRole', 'Server') %Receive data from any ip
tcpObj.ByteOrder = 'littleEndian';
tcpObj.Timeout = 5; %change me to 9999
tcpObj.InputBufferSize = 99999;
fopen(tcpObj); %Wait until the client connects
end
function [average_lx, max_lx, min_lx] = C7000_Read(n, tcpObj)
%Ask the C-7000 to make n measures and returns average, max and min lux
%of all the measures
fwrite(tcpObj, int16(n), 'int16');
average_lx = fread(tcpObj, 1, 'double');
max_lx = fread(tcpObj, 1, 'double');
min_lx = fread(tcpObj, 1, 'double');
end
function [X_1nm, Y_1nm, X_5nm, Y_5nm] = C7000_GetSpectrum(tcpObj)
%Ask the C-7000 to send the spectrum of the last measure made
%This functuion does not take any new measures of the light, just sends
%more data to Matlab
fwrite(tcpObj, int16(-2), 'int16');
Y_1nm = fread(tcpObj, 400, 'single');
Y_1nm = transpose(Y_1nm);
Y_5nm = fread(tcpObj, 80, 'single');
Y_5nm = transpose(Y_5nm);
X_1nm = [380:1:779];
X_5nm = [380:5:775];
end
function C7000_End_program(tcpObj)
fwrite(tcpObj, int16(-1), 'int16'); %Ask the C-7000 to finish the program
end
%END HERE

@ -87,6 +87,18 @@ function [average_lx, max_lx, min_lx] = C7000_Read(n, tcpObj)
min_lx = fread(tcpObj, 1, 'double');
end
function [X_1nm, Y_1nm, X_5nm, Y_5nm] = C7000_GetSpectrum(tcpObj)
%Ask the C-7000 to send the spectrum of the last measure made
%This functuion does not take any new measures of the light, just sends
%more data to Matlab
fwrite(tcpObj, int16(-2), 'int16');
X_1nm = fread(tcpObj, 400, 'int32');
Y_1nm = fread(tcpObj, 400, 'single');
X_5nm = fread(tcpObj, 80, 'int32');
Y_5nm = fread(tcpObj, 80, 'single');
end
function C7000_End_program(tcpObj)
fwrite(tcpObj, int16(-1), 'int16'); %Ask the C-7000 to finish the program
end

@ -17,7 +17,8 @@ Public Module GlobalVariables
End Enum
Public Result_Illmi As String
Public Spectrum_1nm(C7000.SDK.SKF_WAVELENGTH_1NM_COUNT - 1) As Single
Public Spectrum_5nm(C7000.SDK.SKF_WAVELENGTH_5NM_COUNT - 1) As Single
End Module
Module Program
@ -27,7 +28,7 @@ Module Program
Dim Label_Ring As String
Dim server_ip As String
Dim Port As Integer = 30000 'Port where the server is
Dim Port As Integer = 30000 'Port where the server is allocated
Dim VBClient As Sockets.TcpClient
Dim VBClientStream As Sockets.NetworkStream
@ -71,66 +72,104 @@ Module Program
VBClientStream.Read(data_rx, 0, CInt(VBClient.ReceiveBufferSize))
num_measures = BitConverter.ToInt16(data_rx, 0)
If -1 = num_measures Then 'If -1 is sent from the server
Exit While 'Finish the program
End If
Dim Lux(num_measures - 1) As Double 'Array of illuminances mesuared
Console.WriteLine()
Console.WriteLine("Starting " + Convert.ToString(num_measures) + " measures...")
While num_measures > 0
While True
If True = Check_Status(C7000Device.SK_GetDeviceInfo(DeviceInfo)) Then ' If everything is OK
Label_Status = Get_DeveiceStats(DeviceInfo) ' Get Device Status
Label_Ring = Get_RingStatus(DeviceInfo) ' Get Light Selection Ring
Select Case Sequence
Case SequenceCtrKey.IDLE
Sequence = Start_Measurement()
Case SequenceCtrKey.MEASURING
If C7000.SDK.SKF_STATUS_DEVICE.BUSY_MEASURING <> DeviceInfo.Status Then 'If measurement is finished
Call Monitor_MeasuringResult() 'Take the results
Sequence = SequenceCtrKey.IDLE 'Indicate we are back to IDLE
Exit While 'Exit While loop
End If
End Select
If -1 = num_measures Then 'If -1 is received from the server
Exit While 'Finish the program
ElseIf -2 = num_measures Then 'If -2 is received from the server
'Send the spectrum of the last measure made
Console.WriteLine("Sending spectrum of the last measure...")
'Build the data of the packet
Dim temp_array As Byte()
ReDim temp_array(4)
Dim Y_1nm_byte As Byte()
ReDim Y_1nm_byte((C7000.SDK.SKF_WAVELENGTH_1NM_COUNT - 1) * 4)
For a_index As Integer = 0 To Spectrum_1nm.Length - 1
temp_array = BitConverter.GetBytes(Spectrum_1nm(a_index))
Y_1nm_byte(a_index * 4) = temp_array(0)
If 400 > a_index Then
Y_1nm_byte((a_index * 4) + 1) = temp_array(1)
Y_1nm_byte((a_index * 4) + 2) = temp_array(2)
Y_1nm_byte((a_index * 4) + 3) = temp_array(3)
End If
Next
Dim Y_5nm_byte As Byte()
ReDim Y_5nm_byte((C7000.SDK.SKF_WAVELENGTH_5NM_COUNT - 1) * 4)
For a_index As Integer = 0 To Spectrum_5nm.Length - 1
temp_array = BitConverter.GetBytes(Spectrum_5nm(a_index))
Y_5nm_byte(a_index * 4) = temp_array(0)
If 80 > a_index Then
Y_5nm_byte((a_index * 4) + 1) = temp_array(1)
Y_5nm_byte((a_index * 4) + 2) = temp_array(2)
Y_5nm_byte((a_index * 4) + 3) = temp_array(3)
End If
Next
Dim data_to_send As Byte() = Y_1nm_byte.Concat(Y_5nm_byte).ToArray 'Concatenate the 2 arrays
VBClient.Client.Send(data_to_send) 'Send the packet
ElseIf num_measures > 0 Then 'If a positive number of measures is requested, take thous measures
Dim Lux(num_measures - 1) As Double 'Array of illuminances mesuared
Console.WriteLine()
Console.WriteLine("Starting " + Convert.ToString(num_measures) + " measures...")
While num_measures > 0
While True
If True = Check_Status(C7000Device.SK_GetDeviceInfo(DeviceInfo)) Then ' If everything is OK
Label_Status = Get_DeveiceStats(DeviceInfo) ' Get Device Status
Label_Ring = Get_RingStatus(DeviceInfo) ' Get Light Selection Ring
Select Case Sequence
Case SequenceCtrKey.IDLE
Sequence = Start_Measurement()
Case SequenceCtrKey.MEASURING
If C7000.SDK.SKF_STATUS_DEVICE.BUSY_MEASURING <> DeviceInfo.Status Then 'If measurement is finished
Call Monitor_MeasuringResult() 'Take the results
Sequence = SequenceCtrKey.IDLE 'Indicate we are back to IDLE
Exit While 'Exit While loop
End If
End Select
End If
End While
If "Under" = Result_Illmi Then 'Translate the "too low for reading" to "0"
Result_Illmi = "0"
End If
Lux(index) = CDbl(Result_Illmi) 'Cast from string to Double
Console.WriteLine(" Measure " + Convert.ToString(index + 1) + ": " + Result_Illmi + " lx")
index += 1
num_measures -= 1
End While
If "Under" = Result_Illmi Then 'Translate the "too low for reading" to "0"
Result_Illmi = "0"
End If
Lux(index) = CDbl(Result_Illmi) 'Cast from string to Double
Console.WriteLine(" Measure " + Convert.ToString(index + 1) + ": " + Result_Illmi + " lx")
index += 1
num_measures -= 1
End While
Console.WriteLine("Measures completed")
Console.WriteLine("")
average_lx = 0
For i As Int16 = 0 To (index - 1)
average_lx += Lux(i)
Next i
average_lx = average_lx / index
max_lx = Lux.Max()
min_lx = Lux.Min()
Console.Write("Mean Value: ")
Console.WriteLine(average_lx)
Console.Write("Max Value: ")
Console.WriteLine(max_lx)
Console.Write("Min Value: ")
Console.WriteLine(min_lx)
index = 0
'Creation of the packet to be send to the server
Dim mean_byte As Byte() = BitConverter.GetBytes(average_lx)
Dim max_byte As Byte() = BitConverter.GetBytes(max_lx)
Dim min_byte As Byte() = BitConverter.GetBytes(min_lx)
Dim data_tx() As Byte = mean_byte.Concat(max_byte.Concat(min_byte).ToArray).ToArray 'Concatenate the 3 values
VBClient.Client.Send(data_tx) 'Send it
Console.WriteLine("Measures completed")
Console.WriteLine("")
average_lx = 0
For i As Int16 = 0 To (index - 1)
average_lx += Lux(i)
Next i
average_lx = average_lx / index
max_lx = Lux.Max()
min_lx = Lux.Min()
Console.Write("Mean Value: ")
Console.WriteLine(average_lx)
Console.Write("Max Value: ")
Console.WriteLine(max_lx)
Console.Write("Min Value: ")
Console.WriteLine(min_lx)
index = 0
'Creation of the packet to be send to the server
Dim mean_byte As Byte() = BitConverter.GetBytes(average_lx)
Dim max_byte As Byte() = BitConverter.GetBytes(max_lx)
Dim min_byte As Byte() = BitConverter.GetBytes(min_lx)
Dim data_tx() As Byte = mean_byte.Concat(max_byte.Concat(min_byte).ToArray).ToArray 'Concatenate the 3 values
VBClient.Client.Send(data_tx) 'Send it
End If
End While
@ -286,10 +325,28 @@ Module Program
Monitor_MeasuringResult = Check_Status(SDKResult)
With MeasResult
Dim pt As Integer = 0
If True = Monitor_MeasuringResult And C7000.SDK.SKF_RESULT_VALUE.VALUE_ON = .ResultFlag Then ' If measurment is finished
Result_Illmi = .Illuminance.LUX
'Set Spectrum 1nm
For wl As Integer = 380 To 780
'Add XY to 1nm arrat(wl, p)
Spectrum_1nm(pt) = .SpectralData_1nm(pt)
pt += 1
Next
'Set Spectrum 5nm
pt = 0
For wl As Integer = 380 To 780 Step 5
'Add XY to 1nm arrat(wl, p)
Spectrum_5nm(pt) = .SpectralData_5nm(pt)
pt += 1
Next
Else
Result_Illmi = ""
'Add dummy data to the spectrum arrays
Spectrum_1nm(0) = 0
Spectrum_5nm(0) = 0.8
End If
End With
End Function

@ -838,3 +838,24 @@
[#2020/04/09 11:26:53.892]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000
[#2020/04/09 12:10:46.498]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000
[#2020/04/09 12:12:25.810]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000
[#2020/05/04 13:40:44.111]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000
[#2020/05/04 13:43:29.518]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000
[#2020/05/04 13:46:10.481]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000
[#2020/05/04 13:47:34.027]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000
[#2020/05/04 13:48:57.655]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000
[#2020/05/04 15:13:38.628]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000
[#2020/05/04 15:16:27.690]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000
[#2020/05/04 15:17:50.306]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000
[#2020/05/04 15:21:03.074]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000
[#2020/05/04 15:22:24.583]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000
[#2020/05/04 15:29:15.585]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000
[#2020/05/04 15:31:14.448]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000
[#2020/05/04 15:34:13.755]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000
[#2020/05/04 15:37:22.575]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000
[#2020/05/04 15:41:36.829]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000
[#2020/05/04 15:53:13.477]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000
[#2020/05/04 15:54:30.418]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000
[#2020/05/04 15:55:07.221]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000
[#2020/05/04 15:57:03.021]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000
[#2020/05/04 15:59:38.610]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000
[#2020/05/04 16:00:13.397]SkCommIo_RecvData :Status=0x2021000f:GetLastError=0x00000000

Loading…
Cancel
Save