Skip to content

Commit ca333ec

Browse files
authored
Merge pull request #32 from tmytek/Update-TLKCore
Update tlk core
2 parents 8b2fde5 + 702aabc commit ca333ec

File tree

180 files changed

+25376
-272
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

180 files changed

+25376
-272
lines changed

.github/pull_request_template.md

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
1-
## Issue
2-
(Please attach GitHub Issue url.)
1+
# Pull Request templates
32

4-
## Description
3+
## Release Note
54

6-
## Root Cause
7-
(If root cause is not attached in linked GitHub Issue, please add root cause analysis here.)
8-
9-
## Solution
10-
(If solution is not attached in linked GitHub Issue, please add solution here.)
5+
1. Solved xxx
116

127
## Verification
8+
139
- [ ] Build Pass
14-
- [ ] LabView Sample Code Run on LabView 2019
15-
- [ ] LabView Sample Code Run on LabView 2015
16-
- [ ] IT with BBox One 4x4, SN: ____
17-
- [ ] IT with BBox One 8x8, SN: ____
18-
- [ ] IT with BBox One FW version: (Attach release tag here)
19-
- [ ] IT with BBox Suite version: (Attach release tag here)
20-
- [ ] Beam steering performance
10+
- [ ] Python example code
11+
- [ ] LabVIEW example code
12+
- [ ] MATLAB example code
13+
- [ ] C/C++ example code
14+
- [ ] CSharp example code
15+
- [ ] WEB-TLK

example_Linux/CSharp/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Getting Started with C# Sample Code
2+
3+
## Prerequisites
4+
5+
* Python 3
6+
1. Install Python *3.6 or 3.8 or 3.10* which mapping with [TLKCore_release](https://github.com/tmytek/bbox-api/tree/master/example_Linux/TLKCore_release), and follow reference user guide of [Getting Started with Python Sample Code](https://github.com/tmytek/bbox-api/tree/master/example_Linux/Python/README.md) to make sure your Python environment first.
7+
* Example gives a default libraries for Python 3.8 ([python-3.8.0 64-bit download Link](https://www.python.org/downloads/release/python-380/))
8+
2. Extract zip file under the [TLKCore_release](https://github.com/tmytek/bbox-api/tree/master/example_Linux/TLKCore_release) then copy the whole `lib/` & `logging.conf` to TLKCoreExample/
9+
![](../../images/CS_Lib_copy.png)
10+
3. Make sure your Python related path already exist in environment variable: `Path`
11+
* Visual Studio - Example runs on Visual Studio 2019 with .NET Framework 4.7.2
12+
1. Install **pythonnet**
13+
* Please follow [the reference link](https://learn.microsoft.com/en-us/nuget/consume-packages/install-use-packages-visual-studio) to install pythonnet 3.x.x
14+
![](../../images/CS_Install_Python_Runtime.png)
15+
16+
2. Setup Python version/path in ExampleMain.cs, and '.' is your output folder
17+
![](../../images/CS_Python_Path_Setup.png)
18+
19+
## C# sample build steps
20+
21+
1. Launch TLKCoreExample\TLKCoreExample.sln
22+
2. Build project
23+
24+
## C# sample execution steps
25+
26+
1. [BBoxOne/Lite] Copy your calibration & antenna tables into **files/** under the built folder likes *bin/Debug/*
27+
* BBox calibration tables -> **{SN}_{Freq}GHz.csv**
28+
* BBox antenna table -> **AAKIT_{AAKitName}.csv**
29+
2. Launch TLKCoreExample.exe
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
5+
</startup>
6+
</configuration>
Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
using Python.Runtime;
2+
using System;
3+
using System.IO;
4+
using System.Reflection;
5+
6+
namespace TLKCoreExample
7+
{
8+
class ExampleMain
9+
{
10+
static void Main(string[] args)
11+
{
12+
// Getting Python execute environment from environment: "Path"
13+
string env = Environment.GetEnvironmentVariable("Path");
14+
string[] array = env.Split(new[] { ";" }, StringSplitOptions.None);
15+
string pathToVirtualEnv = "";
16+
// Asign your Python version
17+
string PyVer = "38";
18+
foreach (var path in array)
19+
{
20+
if (path.Contains("Python"+ PyVer+"\\") && !path.Contains("Script")) {
21+
pathToVirtualEnv = path;
22+
break;
23+
}
24+
}
25+
Console.WriteLine($"Python installed path: {pathToVirtualEnv}\n");
26+
27+
// Setting relative environment for execute Python, please update parameters from your real Python version
28+
Runtime.PythonDLL = Path.Combine(pathToVirtualEnv, "python"+ PyVer + ".dll");
29+
PythonEngine.PythonHome = Path.Combine(pathToVirtualEnv, "python.exe");
30+
31+
// Set default Python lib path and path to import TLKCore
32+
PythonEngine.PythonPath = $".;lib;{pathToVirtualEnv}\\Lib\\site-packages;{pathToVirtualEnv}\\Lib;{pathToVirtualEnv}\\DLLs";
33+
34+
PythonEngine.Initialize();
35+
using (Py.GIL())
36+
{
37+
// Import modules which we need
38+
dynamic tlkcoreIns = Py.Import("TLKCoreService");
39+
dynamic tmy_public = Py.Import("TMYPublic");
40+
41+
// Please keep this instance
42+
dynamic service = tlkcoreIns.TLKCoreService();
43+
Console.WriteLine("TLKCore version: v" + service.queryTLKCoreVer());
44+
45+
dynamic dev_interface = tmy_public.DevInterface.ALL;
46+
dynamic ret = service.scanDevices(dev_interface.value);
47+
dynamic scanlist = ret.RetData;
48+
Console.WriteLine("Scanned device list: " + scanlist);
49+
50+
ExampleMain example = new ExampleMain();
51+
foreach (string sn_addr_type in scanlist)
52+
{
53+
dynamic element = sn_addr_type.Split(',');
54+
string sn = element[0];
55+
string addr = element[1];
56+
string dev_type = element[2];
57+
ret = service.initDev(sn);
58+
if (ret.RetCode.value != tmy_public.RetCode.OK.value)
59+
{
60+
Console.WriteLine("Init failed, skip it");
61+
continue;
62+
}
63+
64+
string dev_name = service.getDevTypeName(sn);
65+
if (dev_name.Contains("BBox")) {
66+
dev_name = "BBox";
67+
}
68+
// Invoke example methods
69+
Object[] param = { sn, service };
70+
Console.WriteLine("Going to test " + dev_name);
71+
example.GetType().InvokeMember("Test"+dev_name, BindingFlags.InvokeMethod, Type.DefaultBinder, example, param);
72+
}
73+
74+
Console.WriteLine("Presss any key to exit ...");
75+
Console.ReadKey();
76+
}
77+
}
78+
public void TestBBox(string sn, dynamic service)
79+
{
80+
dynamic tmy_public = Py.Import("TMYPublic");
81+
82+
dynamic mode = tmy_public.RFMode.TX;
83+
dynamic ret = service.setRFMode(sn, mode);
84+
Console.WriteLine("Set RF mode: {0}", ret.RetCode);
85+
ret = service.getRFMode(sn);
86+
Console.WriteLine("Get RF mode: {0}", ret);
87+
88+
// Convert Python: list to C# array []
89+
dynamic freqList = service.getFrequencyList(sn).RetData;
90+
Console.WriteLine("Freq list: " + freqList);
91+
92+
// Please edit your target freq
93+
Double targetFreq = 28.0;
94+
bool found = false;
95+
foreach (dynamic f in freqList)
96+
{
97+
if (f == targetFreq)
98+
{
99+
found = true;
100+
break;
101+
}
102+
}
103+
if (!found)
104+
{
105+
Console.WriteLine("Not support your target freq:{0} in freq list!", targetFreq);
106+
return;
107+
}
108+
109+
ret = service.setOperatingFreq(sn, targetFreq);
110+
if (ret.RetCode.value != tmy_public.RetCode.OK.value)
111+
{
112+
Console.WriteLine("Set freq failed: " + ret);
113+
return;
114+
}
115+
Console.WriteLine("Set freq: {0}", ret);
116+
117+
// Gain setting for BBoxOne/Lite
118+
dynamic rng = service.getDR(sn, mode).RetData;
119+
Console.WriteLine("DR range: " + rng);
120+
121+
// Select AAKit, please call getAAKitList() to fetch all AAKit list in files/
122+
bool aakit_selected = false;
123+
string[] aakitList = (string[])service.getAAKitList(sn).RetData;
124+
foreach (string aakit in aakitList)
125+
{
126+
if (aakit.Contains("4x4"))
127+
{
128+
Console.WriteLine("Select AAKit: {0}: {1}", aakit, service.selectAAKit(sn, aakit).name);
129+
aakit_selected = true;
130+
break;
131+
}
132+
}
133+
if (!aakit_selected)
134+
Console.WriteLine("PhiA mode");
135+
136+
// ------- Get basic informations -------
137+
Double gain_max = rng[1];
138+
139+
// Set IC channel gain, we use board 1 (its index in com_dr is 0) as example
140+
dynamic board_count = service.getBoardCount(sn).RetData;
141+
int board = 1;
142+
Console.WriteLine("Selected board: {0}/{1}", board, board_count);
143+
144+
dynamic com_dr = service.getCOMDR(sn).RetData;
145+
dynamic common_gain_rng = com_dr[mode.value][board - 1];
146+
// Here we takes the maximum common gain as example
147+
dynamic common_gain_max = common_gain_rng[1];
148+
dynamic ele_dr_limit = service.getELEDR(sn).RetData[mode.value][board - 1];
149+
Console.WriteLine("Board:{0} common gain range: {1}, and element gain limit: {2}", board, common_gain_rng, ele_dr_limit);
150+
151+
// ------- Beam control example -------
152+
if (aakit_selected)
153+
{
154+
//Passing: gain, theta, phi
155+
Console.WriteLine("SetBeamAngle: " + service.setBeamAngle(sn, gain_max, 0, 0));
156+
}
157+
else
158+
{
159+
Console.WriteLine("PhiA mode cannot process beam steering");
160+
}
161+
}
162+
163+
public void TestUDBox(string sn, dynamic service)
164+
{
165+
dynamic tmy_public = Py.Import("TMYPublic");
166+
dynamic UDState = tmy_public.UDState;
167+
168+
Console.WriteLine("PLO state: " + service.getUDState(sn, UDState.PLO_LOCK).RetData);
169+
Console.WriteLine("All state: " + service.getUDState(sn).RetData);
170+
171+
Console.WriteLine(service.setUDState(sn, 0, UDState.CH1));
172+
Console.WriteLine("Wait for CH1 OFF");
173+
Console.ReadKey();
174+
Console.WriteLine(service.setUDState(sn, 1, UDState.CH1));
175+
Console.WriteLine("Check CH1 is ON");
176+
Console.ReadKey();
177+
// Other setate options
178+
Console.WriteLine(service.setUDState(sn, 1, UDState.CH2));
179+
Console.WriteLine(service.setUDState(sn, 1, UDState.OUT_10M));
180+
Console.WriteLine(service.setUDState(sn, 1, UDState.OUT_100M));
181+
Console.WriteLine(service.setUDState(sn, 1, UDState.PWR_5V));
182+
Console.WriteLine(service.setUDState(sn, 1, UDState.PWR_9V));
183+
184+
// Passing: LO, RF, IF, Bandwidth with kHz
185+
Double LO = 24e6;
186+
Double RF = 28e6;
187+
Double IF = 4e6;
188+
Double BW = 1e5;
189+
// A check function, should be false -> not harmonic
190+
Console.WriteLine("Check harmonic: " + service.getHarmonic(sn, LO, RF, IF, BW).RetData);
191+
// SetUDFreq also includes check function
192+
dynamic ret = service.setUDFreq(sn, LO, RF, IF, BW);
193+
Console.WriteLine("Freq config: " + ret);
194+
}
195+
public void TestUDM(string sn, dynamic service)
196+
{
197+
dynamic tmy_public = Py.Import("TMYPublic");
198+
199+
dynamic ret = service.getUDState(sn);
200+
if (ret.RetCode.value != tmy_public.RetCode.OK.value)
201+
{
202+
Console.WriteLine("Error to get UDM state:" + ret);
203+
return;
204+
}
205+
Console.WriteLine("UDM state: " + ret);
206+
207+
// Passing: LO, RF, IF, Bandwidth with kHz
208+
Double LO = 7e6;
209+
Double RF = 10e6;
210+
Double IF = 3e6;
211+
Double BW = 1e5;
212+
ret = service.setUDFreq(sn, LO, RF, IF, BW);
213+
Console.WriteLine("Set UDM freq to {0}: {1}", LO, ret.RetCode);
214+
215+
ret = service.getUDFreq(sn);
216+
Console.WriteLine("UDM current freq: " + ret);
217+
218+
dynamic source = tmy_public.UDM_REF.INTERNAL;
219+
220+
// A case to set internal source to output
221+
dynamic supported = service.getRefFrequencyList(sn, source).RetData;
222+
Console.WriteLine("Supported internal reference clock(KHz): {0}", supported);
223+
dynamic output_freq = supported[0];
224+
Console.WriteLine("Enable UDM ref output({0}KHz): {1}", output_freq, service.setOutputReference(sn, true, output_freq));
225+
Console.WriteLine("Get UDM ref ouput: {0}", service.getOutputReference(sn));
226+
227+
Console.WriteLine("Press ENTER to disable output");
228+
Console.ReadKey();
229+
230+
Console.WriteLine("Disable UDM ref output({0}KHz): {1}", output_freq, service.setOutputReference(sn, true, output_freq));
231+
Console.WriteLine("Get UDM ref ouput: {0}", service.getOutputReference(sn));
232+
233+
// A case to change reference source to EXTERNAL
234+
source = tmy_public.UDM_REF.EXTERNAL;
235+
// Get external reference source supported list
236+
supported = service.getRefFrequencyList(sn, source).RetData;
237+
Console.WriteLine("Supported external reference clock(KHz): {0}", supported);
238+
// Try to change reference source to external: 10M
239+
ret = service.setRefSource(sn, source, supported[0]);
240+
Console.WriteLine("Change UDM ref source to {0} -> {1} with freq: {2}", source, ret, supported[0]);
241+
242+
Console.WriteLine("\r\nWaiting for external reference clock input...\n");
243+
Console.ReadKey();
244+
245+
// Check last state
246+
dynamic refer = tmy_public.UDMState.REF_LOCK;
247+
dynamic lock_state = service.getUDState(sn, refer.value);
248+
Console.WriteLine("UDM current reference status: {0}", lock_state);
249+
}
250+
}
251+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// 組件的一般資訊是由下列的屬性集控制。
6+
// 變更這些屬性的值即可修改組件的相關
7+
// 資訊。
8+
[assembly: AssemblyTitle("TLKCoreExample")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("TMYTEK")]
12+
[assembly: AssemblyProduct("TLKCoreExample")]
13+
[assembly: AssemblyCopyright("Copyright © 2023")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// 將 ComVisible 設為 false 可對 COM 元件隱藏
18+
// 組件中的類型。若必須從 COM 存取此組件中的類型,
19+
// 的類型,請在該類型上將 ComVisible 屬性設定為 true。
20+
[assembly: ComVisible(false)]
21+
22+
// 下列 GUID 為專案公開 (Expose) 至 COM 時所要使用的 typelib ID
23+
[assembly: Guid("2c9097f5-6010-4837-9f14-b2912a5748ce")]
24+
25+
// 組件的版本資訊由下列四個值所組成:
26+
//
27+
// 主要版本
28+
// 次要版本
29+
// 組建編號
30+
// 修訂
31+
//
32+
// 您可以指定所有的值,也可以使用 '*' 將組建和修訂編號
33+
// 設為預設,如下所示:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)