找回密码
 注册
查看: 4354|回复: 1

Basic guide to making a C# program to read from CT3 meter (Linux and Windows)

[复制链接]

1

主题

0

回帖

20

积分

Member

积分
20
发表于: 27-08-2021 15:43:14
| 显示全部楼层 |阅读模式
Edited by Danny5678 at 27-08-2021 15:49

Hello everybody, I needed to get this to run on a Raspberry Pi, but in doing so I created a 'universal' program that should be able to work on any Linux and Windows system. I couldn't find any information elsewhere on how to do this easily, so I thought I'd try to save everybody some time (Especially those who don't code often, like me) by outlining the basic principles and steps to creating a program using their C# API.
(I'm only an EE intern so go easy on me)


If you haven't already, download their libraries from:
https://forum.avhzy.com/forum.php?mod=viewthread&tid=190

If you want to, you can look at what they say to do. I found this helpful in implementing my solution, but there were a lot of holes in their explanations:

The process I describe will allow for running a program on Linux, but VisualStudio is the prefered IDE, which I think is Windows only.

This next part I just describe what I did. You can skip it if you're only looking to make a Windows.
If you downloaded csharplib.zip, there are 4 libraries. Unfortunately, there is a windows-only module imported into their ShizukuProtocol library, so I had to deal with it. I used dotPeek to copy and paste all the libraries in ShizukuProtocol into C#. Then, I went into the library "ShizukuDeviceScanHelper" and commented out 'using System.Management;' and every function that used System.Management.

To make this program run on Linux, you need to do something similar to what I did.
I'm not going to include my dll, since it is in bad practice to download dlls you're going to use in an executable from unverified strangers, so don't download it from me.

Now its time to make the project:
I used .NET 5.0, since the other framework wasn't working on my RPi for some reason. Add references to the libraries and do whatever other stupid stuff VisualStudio needs you to do. You might have to install some of the references I made.
My code might not be that efficient, since I don't really know what I'm doing, but it works. In the zip folder I attach, the code is called "Program.cs".
Just copy and paste the code from within to whatever you want. My code basically takes the dirty example that the creators provide and make it work for what I want. You can do the same with my code, to make something more usable for you.

Hopefully this guide and my code aren't too complicated. If there is enough demand, I will make the guide more understandable and useful. For now, I just wanted to hopefully save someone a few hours of headache and describe what I had to do to get it working on an RPi.






回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archive|手机版|小黑屋|AVHzY Forum

GMT-8, 24-04-2024 12:14 , Processed in 0.093014 sec., 19 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

Release 20231001, © 2001-2024, Tencent Cloud.

MultiLingual version, Rev. 4300, © 2009-2024 codersclub.org

快速回复 返回顶部 返回列表