-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from tmytek/Update-TLKCore
Update tlk core
- Loading branch information
Showing
180 changed files
with
25,376 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,15 @@ | ||
## Issue | ||
(Please attach GitHub Issue url.) | ||
# Pull Request templates | ||
|
||
## Description | ||
## Release Note | ||
|
||
## Root Cause | ||
(If root cause is not attached in linked GitHub Issue, please add root cause analysis here.) | ||
|
||
## Solution | ||
(If solution is not attached in linked GitHub Issue, please add solution here.) | ||
1. Solved xxx | ||
|
||
## Verification | ||
|
||
- [ ] Build Pass | ||
- [ ] LabView Sample Code Run on LabView 2019 | ||
- [ ] LabView Sample Code Run on LabView 2015 | ||
- [ ] IT with BBox One 4x4, SN: ____ | ||
- [ ] IT with BBox One 8x8, SN: ____ | ||
- [ ] IT with BBox One FW version: (Attach release tag here) | ||
- [ ] IT with BBox Suite version: (Attach release tag here) | ||
- [ ] Beam steering performance | ||
- [ ] Python example code | ||
- [ ] LabVIEW example code | ||
- [ ] MATLAB example code | ||
- [ ] C/C++ example code | ||
- [ ] CSharp example code | ||
- [ ] WEB-TLK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Getting Started with C# Sample Code | ||
|
||
## Prerequisites | ||
|
||
* Python 3 | ||
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. | ||
* 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/)) | ||
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/ | ||
![](../../images/CS_Lib_copy.png) | ||
3. Make sure your Python related path already exist in environment variable: `Path` | ||
* Visual Studio - Example runs on Visual Studio 2019 with .NET Framework 4.7.2 | ||
1. Install **pythonnet** | ||
* 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 | ||
![](../../images/CS_Install_Python_Runtime.png) | ||
|
||
2. Setup Python version/path in ExampleMain.cs, and '.' is your output folder | ||
![](../../images/CS_Python_Path_Setup.png) | ||
|
||
## C# sample build steps | ||
|
||
1. Launch TLKCoreExample\TLKCoreExample.sln | ||
2. Build project | ||
|
||
## C# sample execution steps | ||
|
||
1. [BBoxOne/Lite] Copy your calibration & antenna tables into **files/** under the built folder likes *bin/Debug/* | ||
* BBox calibration tables -> **{SN}_{Freq}GHz.csv** | ||
* BBox antenna table -> **AAKIT_{AAKitName}.csv** | ||
2. Launch TLKCoreExample.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,251 @@ | ||
using Python.Runtime; | ||
using System; | ||
using System.IO; | ||
using System.Reflection; | ||
|
||
namespace TLKCoreExample | ||
{ | ||
class ExampleMain | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
// Getting Python execute environment from environment: "Path" | ||
string env = Environment.GetEnvironmentVariable("Path"); | ||
string[] array = env.Split(new[] { ";" }, StringSplitOptions.None); | ||
string pathToVirtualEnv = ""; | ||
// Asign your Python version | ||
string PyVer = "38"; | ||
foreach (var path in array) | ||
{ | ||
if (path.Contains("Python"+ PyVer+"\\") && !path.Contains("Script")) { | ||
pathToVirtualEnv = path; | ||
break; | ||
} | ||
} | ||
Console.WriteLine($"Python installed path: {pathToVirtualEnv}\n"); | ||
|
||
// Setting relative environment for execute Python, please update parameters from your real Python version | ||
Runtime.PythonDLL = Path.Combine(pathToVirtualEnv, "python"+ PyVer + ".dll"); | ||
PythonEngine.PythonHome = Path.Combine(pathToVirtualEnv, "python.exe"); | ||
|
||
// Set default Python lib path and path to import TLKCore | ||
PythonEngine.PythonPath = $".;lib;{pathToVirtualEnv}\\Lib\\site-packages;{pathToVirtualEnv}\\Lib;{pathToVirtualEnv}\\DLLs"; | ||
|
||
PythonEngine.Initialize(); | ||
using (Py.GIL()) | ||
{ | ||
// Import modules which we need | ||
dynamic tlkcoreIns = Py.Import("TLKCoreService"); | ||
dynamic tmy_public = Py.Import("TMYPublic"); | ||
|
||
// Please keep this instance | ||
dynamic service = tlkcoreIns.TLKCoreService(); | ||
Console.WriteLine("TLKCore version: v" + service.queryTLKCoreVer()); | ||
|
||
dynamic dev_interface = tmy_public.DevInterface.ALL; | ||
dynamic ret = service.scanDevices(dev_interface.value); | ||
dynamic scanlist = ret.RetData; | ||
Console.WriteLine("Scanned device list: " + scanlist); | ||
|
||
ExampleMain example = new ExampleMain(); | ||
foreach (string sn_addr_type in scanlist) | ||
{ | ||
dynamic element = sn_addr_type.Split(','); | ||
string sn = element[0]; | ||
string addr = element[1]; | ||
string dev_type = element[2]; | ||
ret = service.initDev(sn); | ||
if (ret.RetCode.value != tmy_public.RetCode.OK.value) | ||
{ | ||
Console.WriteLine("Init failed, skip it"); | ||
continue; | ||
} | ||
|
||
string dev_name = service.getDevTypeName(sn); | ||
if (dev_name.Contains("BBox")) { | ||
dev_name = "BBox"; | ||
} | ||
// Invoke example methods | ||
Object[] param = { sn, service }; | ||
Console.WriteLine("Going to test " + dev_name); | ||
example.GetType().InvokeMember("Test"+dev_name, BindingFlags.InvokeMethod, Type.DefaultBinder, example, param); | ||
} | ||
|
||
Console.WriteLine("Presss any key to exit ..."); | ||
Console.ReadKey(); | ||
} | ||
} | ||
public void TestBBox(string sn, dynamic service) | ||
{ | ||
dynamic tmy_public = Py.Import("TMYPublic"); | ||
|
||
dynamic mode = tmy_public.RFMode.TX; | ||
dynamic ret = service.setRFMode(sn, mode); | ||
Console.WriteLine("Set RF mode: {0}", ret.RetCode); | ||
ret = service.getRFMode(sn); | ||
Console.WriteLine("Get RF mode: {0}", ret); | ||
|
||
// Convert Python: list to C# array [] | ||
dynamic freqList = service.getFrequencyList(sn).RetData; | ||
Console.WriteLine("Freq list: " + freqList); | ||
|
||
// Please edit your target freq | ||
Double targetFreq = 28.0; | ||
bool found = false; | ||
foreach (dynamic f in freqList) | ||
{ | ||
if (f == targetFreq) | ||
{ | ||
found = true; | ||
break; | ||
} | ||
} | ||
if (!found) | ||
{ | ||
Console.WriteLine("Not support your target freq:{0} in freq list!", targetFreq); | ||
return; | ||
} | ||
|
||
ret = service.setOperatingFreq(sn, targetFreq); | ||
if (ret.RetCode.value != tmy_public.RetCode.OK.value) | ||
{ | ||
Console.WriteLine("Set freq failed: " + ret); | ||
return; | ||
} | ||
Console.WriteLine("Set freq: {0}", ret); | ||
|
||
// Gain setting for BBoxOne/Lite | ||
dynamic rng = service.getDR(sn, mode).RetData; | ||
Console.WriteLine("DR range: " + rng); | ||
|
||
// Select AAKit, please call getAAKitList() to fetch all AAKit list in files/ | ||
bool aakit_selected = false; | ||
string[] aakitList = (string[])service.getAAKitList(sn).RetData; | ||
foreach (string aakit in aakitList) | ||
{ | ||
if (aakit.Contains("4x4")) | ||
{ | ||
Console.WriteLine("Select AAKit: {0}: {1}", aakit, service.selectAAKit(sn, aakit).name); | ||
aakit_selected = true; | ||
break; | ||
} | ||
} | ||
if (!aakit_selected) | ||
Console.WriteLine("PhiA mode"); | ||
|
||
// ------- Get basic informations ------- | ||
Double gain_max = rng[1]; | ||
|
||
// Set IC channel gain, we use board 1 (its index in com_dr is 0) as example | ||
dynamic board_count = service.getBoardCount(sn).RetData; | ||
int board = 1; | ||
Console.WriteLine("Selected board: {0}/{1}", board, board_count); | ||
|
||
dynamic com_dr = service.getCOMDR(sn).RetData; | ||
dynamic common_gain_rng = com_dr[mode.value][board - 1]; | ||
// Here we takes the maximum common gain as example | ||
dynamic common_gain_max = common_gain_rng[1]; | ||
dynamic ele_dr_limit = service.getELEDR(sn).RetData[mode.value][board - 1]; | ||
Console.WriteLine("Board:{0} common gain range: {1}, and element gain limit: {2}", board, common_gain_rng, ele_dr_limit); | ||
|
||
// ------- Beam control example ------- | ||
if (aakit_selected) | ||
{ | ||
//Passing: gain, theta, phi | ||
Console.WriteLine("SetBeamAngle: " + service.setBeamAngle(sn, gain_max, 0, 0)); | ||
} | ||
else | ||
{ | ||
Console.WriteLine("PhiA mode cannot process beam steering"); | ||
} | ||
} | ||
|
||
public void TestUDBox(string sn, dynamic service) | ||
{ | ||
dynamic tmy_public = Py.Import("TMYPublic"); | ||
dynamic UDState = tmy_public.UDState; | ||
|
||
Console.WriteLine("PLO state: " + service.getUDState(sn, UDState.PLO_LOCK).RetData); | ||
Console.WriteLine("All state: " + service.getUDState(sn).RetData); | ||
|
||
Console.WriteLine(service.setUDState(sn, 0, UDState.CH1)); | ||
Console.WriteLine("Wait for CH1 OFF"); | ||
Console.ReadKey(); | ||
Console.WriteLine(service.setUDState(sn, 1, UDState.CH1)); | ||
Console.WriteLine("Check CH1 is ON"); | ||
Console.ReadKey(); | ||
// Other setate options | ||
Console.WriteLine(service.setUDState(sn, 1, UDState.CH2)); | ||
Console.WriteLine(service.setUDState(sn, 1, UDState.OUT_10M)); | ||
Console.WriteLine(service.setUDState(sn, 1, UDState.OUT_100M)); | ||
Console.WriteLine(service.setUDState(sn, 1, UDState.PWR_5V)); | ||
Console.WriteLine(service.setUDState(sn, 1, UDState.PWR_9V)); | ||
|
||
// Passing: LO, RF, IF, Bandwidth with kHz | ||
Double LO = 24e6; | ||
Double RF = 28e6; | ||
Double IF = 4e6; | ||
Double BW = 1e5; | ||
// A check function, should be false -> not harmonic | ||
Console.WriteLine("Check harmonic: " + service.getHarmonic(sn, LO, RF, IF, BW).RetData); | ||
// SetUDFreq also includes check function | ||
dynamic ret = service.setUDFreq(sn, LO, RF, IF, BW); | ||
Console.WriteLine("Freq config: " + ret); | ||
} | ||
public void TestUDM(string sn, dynamic service) | ||
{ | ||
dynamic tmy_public = Py.Import("TMYPublic"); | ||
|
||
dynamic ret = service.getUDState(sn); | ||
if (ret.RetCode.value != tmy_public.RetCode.OK.value) | ||
{ | ||
Console.WriteLine("Error to get UDM state:" + ret); | ||
return; | ||
} | ||
Console.WriteLine("UDM state: " + ret); | ||
|
||
// Passing: LO, RF, IF, Bandwidth with kHz | ||
Double LO = 7e6; | ||
Double RF = 10e6; | ||
Double IF = 3e6; | ||
Double BW = 1e5; | ||
ret = service.setUDFreq(sn, LO, RF, IF, BW); | ||
Console.WriteLine("Set UDM freq to {0}: {1}", LO, ret.RetCode); | ||
|
||
ret = service.getUDFreq(sn); | ||
Console.WriteLine("UDM current freq: " + ret); | ||
|
||
dynamic source = tmy_public.UDM_REF.INTERNAL; | ||
|
||
// A case to set internal source to output | ||
dynamic supported = service.getRefFrequencyList(sn, source).RetData; | ||
Console.WriteLine("Supported internal reference clock(KHz): {0}", supported); | ||
dynamic output_freq = supported[0]; | ||
Console.WriteLine("Enable UDM ref output({0}KHz): {1}", output_freq, service.setOutputReference(sn, true, output_freq)); | ||
Console.WriteLine("Get UDM ref ouput: {0}", service.getOutputReference(sn)); | ||
|
||
Console.WriteLine("Press ENTER to disable output"); | ||
Console.ReadKey(); | ||
|
||
Console.WriteLine("Disable UDM ref output({0}KHz): {1}", output_freq, service.setOutputReference(sn, true, output_freq)); | ||
Console.WriteLine("Get UDM ref ouput: {0}", service.getOutputReference(sn)); | ||
|
||
// A case to change reference source to EXTERNAL | ||
source = tmy_public.UDM_REF.EXTERNAL; | ||
// Get external reference source supported list | ||
supported = service.getRefFrequencyList(sn, source).RetData; | ||
Console.WriteLine("Supported external reference clock(KHz): {0}", supported); | ||
// Try to change reference source to external: 10M | ||
ret = service.setRefSource(sn, source, supported[0]); | ||
Console.WriteLine("Change UDM ref source to {0} -> {1} with freq: {2}", source, ret, supported[0]); | ||
|
||
Console.WriteLine("\r\nWaiting for external reference clock input...\n"); | ||
Console.ReadKey(); | ||
|
||
// Check last state | ||
dynamic refer = tmy_public.UDMState.REF_LOCK; | ||
dynamic lock_state = service.getUDState(sn, refer.value); | ||
Console.WriteLine("UDM current reference status: {0}", lock_state); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
example_Linux/CSharp/TLKCoreExample/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// 組件的一般資訊是由下列的屬性集控制。 | ||
// 變更這些屬性的值即可修改組件的相關 | ||
// 資訊。 | ||
[assembly: AssemblyTitle("TLKCoreExample")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("TMYTEK")] | ||
[assembly: AssemblyProduct("TLKCoreExample")] | ||
[assembly: AssemblyCopyright("Copyright © 2023")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// 將 ComVisible 設為 false 可對 COM 元件隱藏 | ||
// 組件中的類型。若必須從 COM 存取此組件中的類型, | ||
// 的類型,請在該類型上將 ComVisible 屬性設定為 true。 | ||
[assembly: ComVisible(false)] | ||
|
||
// 下列 GUID 為專案公開 (Expose) 至 COM 時所要使用的 typelib ID | ||
[assembly: Guid("2c9097f5-6010-4837-9f14-b2912a5748ce")] | ||
|
||
// 組件的版本資訊由下列四個值所組成: | ||
// | ||
// 主要版本 | ||
// 次要版本 | ||
// 組建編號 | ||
// 修訂 | ||
// | ||
// 您可以指定所有的值,也可以使用 '*' 將組建和修訂編號 | ||
// 設為預設,如下所示: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
Oops, something went wrong.